start zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
start kafka server:
bin/kafka-server-start.sh config/server.properties
run the demo:
a. For unlimited sync-producer-consumer run, `run bin/java-producer-consumer-demo.sh sync` b. For unlimited async-producer-consumer run, `run bin/java-producer-consumer-demo.sh`adf
Let's take a look the source code java-producer-consumer-demo.sh,.
the code created 2 topics(queues) for produce and consumer.
the time to dig into code step by step.
Firstly, take a look at source code of Producer
on line 53, KafkaProducer send the message with callback : ProducerRecord
Per each message, the topic, messgeNo and messager body are defined.
DemoCallBack provide asynchronous handling of request completion.
here, DemoCallBack just print the message when completing send the message.
The Consumer class will poll the data every one second and print the message.
all producerRecord and Consume inherited from Bean.
Comments
Post a Comment