简体   繁体   English

使用amqp从队列中解复用消息以并行流处理?

[英]Demultiplexing messages from a queue to process in parallel streams using amqp?

I am trying to figure out if I can switch from a blocking scenario to a more reactive pattern. 我试图找出是否可以从阻塞场景切换到更具反应性的模式。

I have incoming update commands arriving in a queue, and I need to handle them in order, but only those regarding the same entity. 我有传入的更新命令到达队列,我需要按顺序处理它们,但只需要处理相同实体的那些命令。 In essence, I can create as many parallel streams of update events as I wish, as long as no two streams contain events regarding the same entity. 本质上,我可以创建任意数量的并行更新事件流,只要没有两个流包含有关同一实体的事件。

I was thinking that the consumer of the primary queue would possibly be able to leverage amqp's routing mechanisms, and temporary queues, by creating temporary queues for each entity id, and hooking a consumer to them. 我在想主要队列的消费者可能能够利用amqp的路由机制和临时队列,为每个实体id创建临时队列,并将消费者挂钩。 Once the subscriber is finished and no other events regarding the entity in question are currently in the queue, the queue could be disposed of. 一旦订户完成并且当前没有关于所讨论的实体的其他事件在队列中,则可以丢弃该队列。

Is this scenario something that is used regularly? 这种情况是经常使用的吗? Is there a better way to achieve this? 有没有更好的方法来实现这一目标? In our current system we use a named lock based on the id to prevent concurrent updates. 在我们当前的系统中,我们使用基于id的命名锁来防止并发更新。

There are at least 2 Options: 至少有2个选项:

A single queue for each entity And n Consumers on one Entity-Queue. 每个实体的单个队列和一个Entity-Queue上的n个消费者。

One queue with messages of all entities . 一个队列,包含所有实体的消息 Where the message contains data what it is for an entity. 消息包含数据对于实体的含义。 You could than split this up into several queues (One AMQP-Queue for one type of entity) or by using a BlockingQueue implementation. 您可以将其拆分为多个队列(一种类型的实体的一个AMQP-Queue)或使用BlockingQueue实现。

Benefits of splitting up the Entities in qmqp-queues 在qmqp队列中拆分实体的好处

  • You could create an ha-setup with rabbitmq 你可以用rabbitmq创建一个ha-setup
  • You could route messages 您可以路由邮件
  • You could maybe have more than one consumer of an entity queue if it is necessary someday (scalability) 如果某天有必要(可扩展性),你可能有一个以上的实体队列消费者
  • Messages could be persistent and therefore recoverable on an application-crash 消息可以是持久的,因此可以在应用程序崩溃时恢复

Benefits of using an internal BlockingQueue implementation 使用内部BlockingQueue实现的好处

  • It is faster (no net-io obviously) 它更快(显然没有net-io)
  • Everything has to happen in one JVM 一切都必须在一个JVM中发生

Anyway it does depend on what you want since both ways could have their benefits. 无论如何,它确实取决于你想要什么,因为这两种方式都可以带来好处。

UPDATE: I am not sure if I got you now, but let me give you some resources to try some things out. 更新:我不确定我现在能不能找到你,但是让我给你一些资源来尝试一些事情。 There are special rabbitmq extensions maybe some of them can give you an idea. 有一些特殊的rabbitmq 扩展可能其中一些可以给你一个想法。 Take a look at a lternate exchanges and exchange to exchange bindings. 看看交换交换交换绑定。

Also for basic testing, I am not sure if it covers all rabbitmq features or at all all amqp features but this can sometimes be usefull. 也为基本测试,我不知道,如果它涵盖了所有RabbitMQ的功能或根本AMQP的所有功能,但这样有时是有用的。 Keep in mind the routing key in this visualization is the producer name, you can also find there some examples. 请记住,此可视化中的路由键是生产者名称,您还可以找到一些示例。 Import and Export your configuration. 导入和导出配置。

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

相关问题 一旦使用 Spring AMQP 从队列中自动删除消息 - Auto Delete Messages from Queue Once consumed using Spring AMQP rabbitmq(AMQP):删除队列中的所有消息 - rabbitmq (AMQP): delete all messages from a queue 如何使用Spring Integration处理来自AWS SQS FiFo队列的10多个并发消息 - How to process more than 10 concurrent messages from an AWS SQS FiFo queue using Spring Integration 如何使用Java中的多个服务器按顺序从队列中处理消息 - How to process messages in the same order from queue using multiple servers in java 在Java中异步处理队列中的Amazon SQS消息 - Process Amazon SQS messages from queue asynchronously in Java 如何异步发送消息以排队它们而不等待使用java中的rabbitmq在spring amqp中回复每条消息? - How to send messages asynchronously to queue them up without waiting for reply of each message in spring amqp using rabbitmq in java? 使用spring amqp模板清除rabbitmq队列? - purge rabbitmq queue using spring amqp template? 使用Java 8并行流更新从Map原子检索的元素 - Updating elements atomically retrieving from Map using Java 8 parallel streams 使用带有并行流的forEachOrdered的好处 - Benefit of using forEachOrdered with Parallel streams 使用Streams并行排序数组 - Sorting an array in parallel using Streams
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM