Search in sources :

Example 6 with Topology

use of org.apache.kafka.streams.Topology in project apache-kafka-on-k8s by banzaicloud.

the class WordCountProcessorDemo method main.

public static void main(String[] args) throws Exception {
    Properties props = new Properties();
    props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-wordcount-processor");
    props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    props.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
    // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    Topology builder = new Topology();
    builder.addSource("Source", "streams-plaintext-input");
    builder.addProcessor("Process", new MyProcessorSupplier(), "Source");
    builder.addStateStore(Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore("Counts"), Serdes.String(), Serdes.Integer()), "Process");
    builder.addSink("Sink", "streams-wordcount-processor-output", "Process");
    final KafkaStreams streams = new KafkaStreams(builder, props);
    final CountDownLatch latch = new CountDownLatch(1);
    // attach shutdown handler to catch control-c
    Runtime.getRuntime().addShutdownHook(new Thread("streams-wordcount-shutdown-hook") {

        @Override
        public void run() {
            streams.close();
            latch.countDown();
        }
    });
    try {
        streams.start();
        latch.await();
    } catch (Throwable e) {
        System.exit(1);
    }
    System.exit(0);
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) Topology(org.apache.kafka.streams.Topology) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Topology (org.apache.kafka.streams.Topology)6 KafkaStreams (org.apache.kafka.streams.KafkaStreams)4 List (java.util.List)2 Properties (java.util.Properties)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Collectors (java.util.stream.Collectors)2 TopologyDescription (org.apache.kafka.streams.TopologyDescription)2 Test (org.junit.Test)2 CEPStream (com.github.fhuss.kafka.streams.cep.CEPStream)1 ComplexStreamsBuilder (com.github.fhuss.kafka.streams.cep.ComplexStreamsBuilder)1 Sequence (com.github.fhuss.kafka.streams.cep.Sequence)1 Pattern (com.github.fhuss.kafka.streams.cep.pattern.Pattern)1 QueryBuilder (com.github.fhuss.kafka.streams.cep.pattern.QueryBuilder)1 KsqlStream (io.confluent.ksql.metastore.KsqlStream)1 KsqlTable (io.confluent.ksql.metastore.KsqlTable)1 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)1 QueryId (io.confluent.ksql.query.QueryId)1 SchemaKTable (io.confluent.ksql.structured.SchemaKTable)1 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)1 IOException (java.io.IOException)1