Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.blah.ktable;
- import java.util.Properties;
- import org.apache.kafka.common.serialization.Serdes;
- import org.apache.kafka.streams.KafkaStreams;
- import org.apache.kafka.streams.StreamsBuilder;
- import org.apache.kafka.streams.StreamsConfig;
- import org.apache.kafka.streams.kstream.ForeachAction;
- import org.apache.kafka.streams.kstream.KTable;
- public class KTableReader {
- public static void main(final String[] args) throws Exception {
- Properties config = new Properties();
- config.put(StreamsConfig.APPLICATION_ID_CONFIG, "test_ktable1");
- config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka-dev01.socialgist.local:9092");
- config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
- config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
- config.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, "10000");
- StreamsBuilder builder = new StreamsBuilder();
- KTable<String, String> source = builder.table("test_ktable1");
- source.toStream().foreach(new ForeachAction<String, String>() {
- public void apply(String key, String value) {
- System.out.println(key + ": " + value);
- }
- });
- KafkaStreams streams = new KafkaStreams(builder.build(), config);
- streams.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment