简体   繁体   English

分布式环境中的消息排序

[英]Message sequencing in Distributed Env

I need some guidance on the solutioning of a problem which I am facing at the moment.我需要一些指导来解决我目前面临的问题。 I have a microservice which is deployed in 8 pods and it has a JMS listener which is enabled in all the pods to increase parallelism.我有一个部署在 8 个 pod 中的微服务,它有一个 JMS 侦听器,在所有 pod 中启用以增加并行度。

Now the event is getting processed in different order and not able to maintain the order of event processing.现在事件正在以不同的顺序进行处理,并且无法维持事件处理的顺序。 The business required the events to be processed in a specific order (Event contains a sequence no, which guarantees the order).业务要求事件按特定顺序处理(事件包含序号,保证顺序)。 But we need the parallelism in place to run the listeners in multiple pods.但是我们需要适当的并行性来在多个 pod 中运行侦听器。

If anyone have any suggestions of how to design it, please can you share?如果有人对如何设计它有任何建议,请您分享一下吗? using DB or redis or any other component?使用 DB 或 redis 或任何其他组件?

Thanks Sandeep谢谢桑迪普

Let me take different example, for instance- Kafka, where sequencing is maintain using partition, and all message having same context(ex: user id) will go to same partition.让我举个不同的例子,例如 - Kafka,其中使用分区维护排序,并且所有具有相同上下文(例如:用户 ID)的消息将 go 到同一个分区。 parallelism can be achieve with number of partitions available.并行性可以通过可用的分区数来实现。

To achieve similar features, parallelism and sequencing of message in JMS is quite tricky.为了实现类似的功能,JMS 中消息的并行性和排序是相当棘手的。 With just one Queue, you can't achieve parallelism and sequencing together.仅使用一个队列,您无法同时实现并行和排序。 This can be achieve in following ways这可以通过以下方式实现

  • Introduce more queue for same purpose, difference will be just some suffix.为同一目的引入更多队列,区别只是一些后缀。 Ex: event_consumer_1, event_consumer_2...etc.例如:event_consumer_1、event_consumer_2...等。 Queue will be created when consumer initialise if queue already not present.如果队列已经不存在,则将在消费者初始化时创建队列。

  • Load balance the event message at producer, producer should have all the information about available Queues[we are using in house service discovery mechanism], probably you can explore service discovery framework to share the list of queue available.在生产者处对事件消息进行负载均衡,生产者应该拥有可用队列的所有信息[我们正在使用内部服务发现机制],也许您可以探索服务发现框架以共享可用队列列表。

  • Route the message at producer, using common context/group( user Id, event type, ..depend on your message structure), This will make sure that message of specific type will be sequenced.在生产者处路由消息,使用公共上下文/组(用户 ID、事件类型、..取决于您的消息结构),这将确保特定类型的消息将被排序。 Like hashing of userId, it will always route the message of specific user Id at same Queue.就像 userId 的散列一样,它总是将特定用户 ID 的消息路由到同一个 Queue 中。

  • Since all consumer have own queue, this help you to achieve parallelism too由于所有消费者都有自己的队列,这也可以帮助您实现并行性

let me know if any specific information require.让我知道是否需要任何具体信息。

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

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