Getting Started with Hazelcast Jet

Create your first Jet job

  1. Download the latest Hazelcast Jet
  2. Unzip it and add the lib/hazelcast-0.x.jar to your class path.
  3. Create a Java class and import Jet libraries.
  4. The following code will start Jet cluster with two nodes. Aggregation application (word count) will be processed in distributed way:
  5. import com.hazelcast.core.IMap;
    import com.hazelcast.jet.Jet;
    import com.hazelcast.jet.JetInstance;
    import com.hazelcast.jet.stream.IStreamMap;
    
    import java.util.Arrays;
    import java.util.Map.Entry;
    import java.util.regex.Pattern;
    
    import static com.hazelcast.jet.stream.DistributedCollectors.toIMap;
    
    public class WordCount {
    
        private static final Pattern PATTERN = Pattern.compile("\\W+");
    
        public static void main(String[] args) {
            JetInstance jet = Jet.newJetInstance();
            // Create an additional instance; it will automatically
            // discover the first one and form a cluster
            Jet.newJetInstance();
    
            IStreamMap<Integer, String> source = jet.getMap("source");
    
            source.put(0, "It was the best of times, " +
                    "it was the worst of times ");
            source.put(1, "There were a king with a large jaw and a " +
                    "queen with a plain face, on the that things in " +
                    "general were settled for ever.");
            source.put(2, "It was the year of Our Lord one thousand " +
                    "seven hundred and seventy-five. Spiritual " +
                    "revelations were conceded to England at that " +
                    "favoured period");
    
            IMap<String, Integer> counts = source
                    .stream()
                    .map(e -> e.getValue().toLowerCase())
                    .flatMap(line -> Arrays.stream(PATTERN.split(line)))
                    .collect(toIMap(m -> m, m -> 1,
                            (left, right) -> left + right));
    
            System.out.println("Counts=" + counts.entrySet());
            Jet.shutdownAll();
        }
    }
    
  6. See more code samples and explore more Jet features.

What’s Next

Get Hands-on Training

Sign up for hands-on training from Hazelcast experts, online or in the classroom.

Learn more at Hazelcast University

Hazelcast 3.6 Deployment and Operations Guide

Read It Online Now

jet.jet.hazelcast.org

Main Menu