简体   繁体   English

如何使用Java修改一个kafka主题的消息并发送到另一个kafka主题?

[英]how to modify message of one kafka topic and send to another kafka topic using java?

I have created producer which produces MSG to one topic A and My need is I want to do change in that MSG and want to send it to another topic B, I'm trying to do this by Kafka streams,but not sure is it a right way or not. 我已经创建了一个生产器,可以将MSG生成到一个主题A,我需要在该MSG中进行更改并将其发送到另一个主题B,我正在尝试通过Kafka流进行此操作,但不确定是否是正确与否。 if it requires Kafka streams for that then please share what should be the code to write? 如果它需要Kafka流,那么请分享应该编写的代码?

There are many options how you can to this. 有很多方法可以做到这一点。

Kafka's Streams API is one possibility with the advantage that you don't add a new dependency to your project. Kafka的Streams API是一种可能,其优点是您无需向项目添加新的依赖项。 As simple stream.map(...).to(...) as program should do this. 像程序一样简单的stream.map(...).to(...)应该做到这一点。 Check out the docs and examples for more details: 查看文档和示例以获取更多详细信息:

You could even just use plain KafkaConsumer and KafkaProducer to get this done (but using Kafka's Streams API seem to be more natural than this). 您甚至可以只使用简单的KafkaConsumerKafkaProducer来完成此操作(但使用Kafka的Streams API似乎比这更自然)。

Of course, you can also use a stream processing framework like Apache Flink, Apache Storm, Apache Apex, Heron (or maybe Apache Spark) -- for sure, there are others too. 当然,您还可以使用诸如Apache Flink,Apache Storm,Apache Apex,Heron(或也许是Apache Spark)之类的流处理框架-当然,还可以使用其他框架。 The program would be similarly simple to write as sketched above. 如上所示,该程序编写起来同样简单。 But you need to setup a processing cluster to deploy you job for those stream processing framework. 但是您需要设置一个处理集群以为这些流处理框架部署作业。

You should look into using Apache storm , it will be very suitable for your needs. 您应该考虑使用Apache storm ,它将非常适合您的需求。

I have used it and it does very well and gels like water in milk with kafka. 我用过它,效果非常好,卡夫卡牛奶中的水像凝胶一样凝结。 It is also very easy to implement. 它也很容易实现。

Best of luck 祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM