好好爱自己!

【转】SENDING KEY VALUE MESSAGES WITH THE KAFKA CONSOLE PRODUCER

SENDING KEY VALUE MESSAGES WITH THE KAFKA CONSOLE PRODUCER

When working with Kafka you might find yourself using the kafka-console-producer (kafka-console-producer.sh). The kafka-console-producer is a program included with Kafka that creates messages from command line input (STDIN).

However, simply sending lines of text will result in messages with null keys. In order to send messages with both keys and values you must set the parse.key and key.separator properties on the command line when running the producer.

The below example sets the parse.key property to true, and specifies the key.separator as “:“. The keys in the sample messages below are “key1”, “key2”, “key3”, with the values being “value1”, “value2”, “value3”.

 

 

If you haven’t installed Kafka yet, see our Kafka Quickstart Tutorial to get up and running quickly.

posted @ 2019-09-12 09:37  立志做一个好的程序员  阅读(453)  评论(0编辑  收藏  举报

不断学习创作,与自己快乐相处