本文整理汇总了Java中org.apache.kafka.streams.kstream.KStream.print方法的典型用法代码示例。如果您正苦于以下问题:Java KStream.print方法的具体用法?Java KStream.print怎么用?Java KStream.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.kafka.streams.kstream.KStream
的用法示例。
在下文中一共展示了KStream.print方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.kafka.streams.kstream.KStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Welcome to Aletheia 201 - Kafka Streams consumption.");
final Properties properties = new Properties();
properties.setProperty(AletheiaConfig.ROUTING_CONFIG_PATH,
"com/outbrain/aletheia/configuration/routing.withStreams.json");
properties.setProperty(AletheiaConfig.SERDES_CONFIG_PATH,
"com/outbrain/aletheia/configuration/serdes.json");
properties.setProperty(AletheiaConfig.ENDPOINTS_CONFIG_PATH,
"com/outbrain/aletheia/configuration/endpoints.json");
properties.setProperty(AletheiaConfig.ENDPOINT_GROUPS_CONFIG_PATH,
"com/outbrain/aletheia/configuration/endpoint.groups.json");
properties.setProperty("aletheia.producer.incarnation", "1");
properties.setProperty("aletheia.consumer.incarnation", "1");
properties.setProperty("aletheia.consumer.source", "myHostName");
properties.setProperty("aletheia.producer.source", "myHostName");
// Streams App Configuration
Map<String, Object> appConfig = new HashMap<>();
appConfig.put(StreamsConfig.APPLICATION_ID_CONFIG, "aletheia-streams-example");
// For this example we use the wall-clock timestamp extractor (Processing-time semantics)
appConfig.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, WallclockTimestampExtractor.class);
// Create the AletheiaStreams helper
final AletheiaStreams aletheiaStreams = new AletheiaStreams(appConfig);
// Configure Aletheia
final AletheiaConfig aletheiaConfig = new AletheiaConfig(properties);
// Build a source stream that consumes MyDatum
final KStream<String, MyDatum> myDatumStream = aletheiaStreams.stream(
aletheiaConfig,
MyDatum.class,
"kafka_endpoint",
"json");
// Define your processing topology
myDatumStream.print();
// Build the KafkaStreams instance
final KafkaStreams streams = aletheiaStreams.constructStreamsInstance();
// Start processing
System.out.println("Starting KafkaStreams processing");
streams.start();
// For this example we stop processing after some time,
// Usually a streams application would be running indefinitely
Thread.sleep(10000L);
streams.close();
System.out.println("Done.");
}
示例2: main
import org.apache.kafka.streams.kstream.KStream; //导入方法依赖的package包/类
public static void main(String[] args) {
StreamsConfig streamingConfig = new StreamsConfig(getProperties());
KStreamBuilder kStreamBuilder = new KStreamBuilder();
KStream<String, String> patternStreamI = kStreamBuilder.stream(Serdes.String(), Serdes.String(), Pattern.compile("topic-\\d"));
KStream<String, String> namedTopicKStream = kStreamBuilder.stream(Serdes.String(), Serdes.String(), "topic-Z");
KStream<String, String> patternStreamII = kStreamBuilder.stream(Serdes.String(), Serdes.String(), Pattern.compile("topic-[A-Y]+"));
patternStreamI.print("pattern-\\d");
namedTopicKStream.print("topic-Z");
patternStreamII.print("topic-[A-Y]+");
System.out.println("Starting stream regex consumer Example");
KafkaStreams kafkaStreams = new KafkaStreams(kStreamBuilder, streamingConfig);
kafkaStreams.start();
}