简体   繁体   English

Kafka Producer(具有多个实例)写入同一主题

[英]Kafka Producer (with multiple instance) writing to same topic

I have a use case where messages are coming from a channel, which we want to push into a Kafka topic(multiple partitions) . 我有一个用例,其中消息来自某个渠道,我们希望将其推送到一个Kafka主题(多个分区)中。 In our case message order is important so we have to push the messages to topic in the order they are received which looks very straight forward if we have only one producer and single partition. 在我们的情况下,消息顺序很重要,因此我们必须按接收消息的顺序将消息推送到主题,如果我们只有一个producer和单个分区,这看起来非常简单。 In our case, for load balancing and scalability we want to run multiple instances for same producer but the problem is how to maintain order of messages . 在我们的案例中,为了实现负载平衡和可伸缩性,我们希望为同一producer运行多个实例,但是问题是如何维护消息的顺序

Any thought or solution would be great helpful. 任何想法或解决方案将大有帮助。

Even if I think to have single partition can it replicated to multiple brokers for availability and fault tolerance? 即使我认为只有一个分区,也可以将其复制到多个代理以提高可用性和容错能力吗?

we have to push the messages to topic in the order they are received which looks very straight forward if we have only one producer and single partition 我们必须按收到消息的顺序将消息推送到主题,如果我们只有一个生产者和单个分区,这看起来非常简单

You can have multiple partitions in the topic with one producer and still have the order maintained if you provide key for your messages. 您可以在一个生产者的主题中具有多个分区,并且如果您为消息提供密钥,则仍然可以保持顺序。 All messages with the same key produced by a single producer are always in order. 由单个生产者产生的具有相同密钥的所有消息总是井井有条。


When you say multiple producers , I assume that you are having multiple instances of your application running and that you are not creating multiple producers in the same JVM instance. 当您说多个生产者时 ,我假设您正在运行应用程序的多个实例,并且没有在同一个JVM实例中创建多个生产者。

Since you said channel , I suppose that it is a network channel like Datagram channel, for example. 既然您说过channel ,我想它是一个网络通道,例如Datagram通道。 In that case, I suppose that you are listening on some port and sending the received data to Kafka. 在这种情况下,我想您正在某个端口上侦听并将接收到的数据发送到Kafka。

I do not see a point in having multiple producers in the same instance producing to the same topic, so it is better to have a single producer send all the messages and for performance you can tune the producer properties like batch.size , linger.ms etc. 我看不到在同一实例中有多个生产者针对同一个主题进行生产的意义,因此最好由一个生产者发送所有消息,并且为了提高性能,您可以调整生产者属性,例如batch.sizelinger.ms等等

To achieve fault tolerance, have another instance running in HA mode (fail-over mode), so that if this instance dies the other automatically picks up. 为了实现容错能力,请让另一个实例在HA模式(故障转移模式)下运行,以便该实例死亡后,另一个实例将自动启动。

If it is a network channel, you can run multiple instances and open the socket with the option SO_REUSEADDR in StandardSocketOptions and this way you only one producer will be active at any point and new producer will become active once the active one dies. 如果是网络通道,则可以运行多个实例,并在StandardSocketOptions中使用选项SO_REUSEADDR打开套接字,这样,在任何时候您只有一个生产者将处于活动状态,并且一旦活动的生产者死亡,新的生产者将变为活动状态。

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

相关问题 卡夫卡多个制片人写同一主题? - Kafka multiple producer writing to same topic? Kafka多个制作人写同一主题 - 消息和数据突发的排序 - Kafka multiple producer writing to same topic - Ordering of message and data burst 在kafka上写相同的话题 - Writing to same topic on kafka Kafka Producer、Broker 和 Topic 中的相同配置 - Same configuration in Kafka Producer, Broker and Topic Kafka - 编写同一主题和消息顺序的多个制作人很重要 - Kafka - Multiple producers writing to same topic and order of message is important 多个 Kafka 生产者写入同一主题 - 如何负载平衡消费 - Multiple Kafka Producers writing to the same topic - how to load balance consumption Kafka-从多个服务器收集日志。 每个运行的生产者都应该写相同的主题吗? - Kafka - collect logs from multiple servers. Should each producer running on write to the same topic? 幂等的 Kafka Producer 写入多分区主题 - Idempotent Kafka Producer writing to multi-partitioned topic 每个生产者的 Kafka 主题 - Kafka topic per producer 如果我有多个生产者向 Kafka 生产相同的数据,为每个生产者配置一个主题或为所有生产者配置一个主题是否有效 - If I have multiple producers producing same data to Kafka,Is it efficient to configure one topic for each producer or one topic for all producers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM