Kafka发送流

时间:2018-08-20 18:45:35

标签: java apache-kafka-streams confluent

您好,我想从生产者那里发送消息,并以大写形式在消费者中收到。将CONFLUENT和KAFKA与build.gradle文件和包含以下代码的StreamingApp.java一起使用:

ProcessingApp.java:

package kafka_stream;


import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.Topology;

import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsConfig;

import org.apache.kafka.streams.kstream.KStream;

import java.util.Properties;


public class StreamingApp { 
    public static void main(String[] args) throws Exception {

Properties props = new Properties();
props.put(StreamsConfig.APPLICATION_ID_CONFIG,"streaming_app_id");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG,"localhost:9092");

StreamsConfig config = new StreamsConfig(props);
StreamsBuilder builder = new StreamsBuilder();

Topology topology = builder.build();

KafkaStreams streams = new KafkaStreams(topology,config);

KStream<String, String> simpleFirstStream = builder.stream("src-topic");
KStream<String, String> upperCasedStream = simpleFirstStream.mapValues(String::toUpperCase);

upperCasedStream.to("out-topic");

System.out.println("Streaming App Started");
streams.start();
Thread.sleep(30000);
System.out.println("shutting downl the streaming app");
streams.close();

}
}

这么好解决这个问题吗?

0 个答案:

没有答案