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”.

 
 
 
 
 
 

Shell

 
1
2
3
4
5
6
7
8
$KAFKA_HOME/bin/kafka-console-producer.sh \
  --broker-list localhost:9092 \
  --topic my-topic \
  --property "parse.key=true" \
  --property "key.separator=:"
key1:value1
key2:value2
key3:value3

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

【转】SENDING KEY VALUE MESSAGES WITH THE KAFKA CONSOLE PRODUCER的更多相关文章

  1. Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)

    windows下使用kafka遇到这个问题: Error when sending message to topic test with key: null, value: 2 bytes with ...

  2. 【转】 详解Kafka生产者Producer配置

    粘贴一下这个配置,与我自己的程序做对比,看看能不能完善我的异步带代码:   -----------------------------------------    详解Kafka生产者Produce ...

  3. Kafka: Producer (0.10.0.0)

    转自:http://www.cnblogs.com/f1194361820/p/6048429.html 通过前面的架构简述,知道了Producer是用来产生消息记录,并将消息以异步的方式发送给指定的 ...

  4. [Kafka] - Kafka Java Producer代码实现

    根据业务需要可以使用Kafka提供的Java Producer API进行产生数据,并将产生的数据发送到Kafka对应Topic的对应分区中,入口类为:Producer Kafka的Producer ...

  5. 【原创】Kafka console consumer源代码分析(一)

    上一篇中分析了Scala版的console producer代码,这篇文章为读者带来一篇console consumer工作原理分析的随笔.其实不论是哪个consumer,大部分的工作原理都是类似的. ...

  6. Kafka的Producer和Consumer源码学习

    先解释下两个概念: high watermark (HW) 它表示已经被commited的最后一个message offset(所谓commited, 应该是ISR中所有replica都已写入),HW ...

  7. Kafka学习-Producer和Customer

    在上一篇kafka入门的基础之上,本篇主要介绍Kafka的生产者和消费者. Kafka 生产者 kafka Producer发布消息记录到Kakfa集群.生产者是线程安全的,可以在多个线程之间共享生产 ...

  8. kafka 客户端 producer 配置参数

    属性 描述 类型 默认值 bootstrap.servers 用于建立与kafka集群的连接,这个list仅仅影响用于初始化的hosts,来发现全部的servers.格式:host1:port1,ho ...

  9. 057 Java中kafka的Producer程序实现

    1.需要启动的服务 这里启动的端口是9092. bin/kafka-console-consumer.sh --topic beifeng --zookeeper linux-hadoop01.ibe ...

随机推荐

  1. Java程序内存分析

    1. Runtime.getRuntime().freeMemory() 和 jvisualvm.exe http://blog.csdn.net/u011004037/article/details ...

  2. python 线程队列LifoQueue-LIFO(36)

    在 python线程队列Queue-FIFO  文章中已经介绍了 先进先出队列Queue,而今天给大家介绍的是第二种:线程队列LifoQueue-LIFO,数据先进后出类型,两者有什么区别呢? 一.队 ...

  3. 生命不息,奔跑不止,持之以恒,勇攀高峰——JasonCeng的跑步打卡

    生命不息,奔跑不止,持之以恒,勇攀高峰!JasonCeng的跑步打卡博文,持续更新,培养好习惯,一起变成更优秀的自己! 2019-12-20-5.05km Avg-speed(均速): 5'56'' ...

  4. WCF-方法重载

    一.服务端重载 一般写法直接重载,但是会报错,如下. [ServiceContract] public interface IService1 { [OperationContract] string ...

  5. Python之reduce函数使用示例

    #!/usr/bin/env python # -*- coding:utf8 -*- '''reduce:处理一个序列,然后把序列进行合并操作''' ###在python中没有reduce函数,所以 ...

  6. c#序列化基类(包含派生类继承DynamicObject和 IXmlSerializable)对象

    直接上代码 using System.Diagnostics; using System.Text; using System.Xml; using System.Xml.Schema; using ...

  7. Python06之分支和循环1(三目运算符)

    Python 为了使得程序更加简洁而新引入过来的一个三目操作符,顾名思义就是有三个参数. 格式: x if 条件表达式 else y 先判断条件表达式真假,真则取 x 的值,否则取 y 的值. 例如: ...

  8. Red Hat操作系统的安装

    1.双击打开VMware虚拟机 2.以下是打开后的界面,点击“创建新的虚拟机” 3.出现新建虚拟机的导向,选择“自定义” 3.选择虚拟机硬件兼容性,使用默认Workstation 12.0就可以 4. ...

  9. Practice

    一.简介 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 )所设计的 ...

  10. 【C#】课堂知识点#3

    1.讲解了实验1中,利用Char.is***来进行判断字符类型. using System; using System.Collections.Generic; using System.Linq; ...