[英]How copy some message from one kafka topic to another from bash?
pls help请帮助
We have 2 kafka topic.我们有 2 个 kafka 主题。 I want copy 10 message from beginning from topic1 to topic2.
我想从 topic1 开始复制 10 条消息到 topic2。
I`m try do it with kafka-console-consumer and kafka-console-producer我正在尝试使用kafka-console-consumer和kafka-console-producer
First i save 10 message from topic1 to some directory:首先,我将 10 条消息从 topic1 保存到某个目录:
for (( i=1; i<=10; i++ )); do bin/kafka-console-consumer.sh --bootstrap-server 1.1.2.3:9092 --group CONSUMER1 --topic TOPIC1 --max-messages 1 > /tmp/_topic/$i.msg; done;
then i try with kafka-console-producer send it to topic2:然后我尝试使用 kafka-console-producer 将它发送到 topic2:
for (( i=1; i<=10; i++ )); do bin/kafka-console-producer.sh --broker-list 1.1.2.4:9092 --topic TOPIC2 < /tmp/_topic/$i.msg; done;
And i got error - my service Can't deserialize data.我收到错误消息 - 我的服务无法反序列化数据。 My question is:
我的问题是:
UPD: How i`m solve this problem (thanks: Robin Moffatt): I using kafka-mirror and this jar: https://github.com/opencore/mirrormaker_topic_rename with this i can copy message from one topic kafka to another on one cluster UPD:我如何解决这个问题(感谢:Robin Moffatt):我使用 kafka-mirror 和这个 jar: https ://github.com/opencore/mirrormaker_topic_rename 有了这个我可以将消息从一个主题 kafka 复制到另一个主题簇
You can do this with kafkacat
:你可以用
kafkacat
做到这kafkacat
:
kafkacat -b localhost:9092 -C -t source-topic -K: -e -o beginning -c10 | \
kafkacat -b localhost:9092 -P -t target-topic -K:
|
redirects the output of the first kafkacat (which is a -C
consumer) into the input of the second kafkacat (which is a -P
producer)-C
消费者)的输出重定向到第二个 kafkacat(它是-P
生产者)的输入-c10
means just consume 10 messages -c10
表示只消耗 10 条消息-o beginning
means start at the beginning of the topic. -o beginning
表示从主题的开头开始。 Note that this won't work if you've got binary data (eg Avro).请注意,如果您有二进制数据(例如 Avro),这将不起作用。 To properly do this use something like Replicator or MirrorMaker2 and a ByteArrayConverter.
要正确执行此操作,请使用 Replicator 或 MirrorMaker2 和 ByteArrayConverter 之类的东西。
Ref: https://rmoff.net/2019/09/29/copying-data-between-kafka-clusters-with-kafkacat/参考: https : //rmoff.net/2019/09/29/copying-data-between-kafka-clusters-with-kafkacat/
For anyone interested in doing this for binary kafka messages, I wrote a simple tool ( kpipe
) to do that.对于任何有兴趣对二进制kafka 消息执行此操作的人,我编写了一个简单的工具 (
kpipe
)来执行此操作。 Hope it helps someone希望它能帮助别人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.