简体   繁体   English

多个消费者和生产者连接到消息队列,这在AMQP中是否可能?

[英]Multiple consumers & producers connected to a message queue, Is that possible in AMQP?

I'd like to create a farm of processes that are able to OCR text. 我想创建一个能够OCR文本的进程场。 I've thought about using a single queue of messages which is read by multiple OCR processes. 我曾考虑使用由多个OCR进程读取的单个消息队列。

I would like to ensure that: 我想确保:

  • each message in queue is eventually processed 队列中的每条消息最终都会被处理
  • the work is more or less equally distributed 工作或多或少地平均分配
  • an image will be parsed only by one OCR process 图像将仅由一个OCR进程解析
  • An OCR process won't get multiple messages at once (so that any other free OCR process can handle the message). OCR进程不会立即获得多条消息(因此任何其他免费的OCR进程都可以处理该消息)。

Is that possible to do using AMQP? 使用AMQP可以吗?

I'm planning to use python and rabbitmq 我打算用python和rabbitmq

Yes, as @nailxx points out. 是的,正如@nailxx指出的那样。 The AMQP programming model is slightly different from JMS in that you only have queues , which can be shared between workers, or used privately by a single worker. AMQP编程模型与JMS略有不同,因为您只有队列 ,可以在工作人员之间共享,也可以由单个工作人员私下使用。 You can also easily set up RabbitMQ to do PubSub use cases or what in JMS are called topics . 您还可以轻松设置RabbitMQ以执行PubSub用例或JMS中的内容称为主题 Please go to our Getting Started page on the RabbitMQ web site to find a ton of helpful info about this. 请访问RabbitMQ网站上的“ 入门”页面,查找大量有用的信息。

Now, for your use case in particular, there are already plenty of tools available. 现在,特别是对于您的用例,已经有很多工具可用。 One that people are using a lot, and that is well supported, is Celery . 人们正在大量使用并得到很好支持的是Celery Here is a blog post about it, that I think will help you get started: 这是一篇关于它的博客文章 ,我认为这将有助于您入门:

If you have any questions please email us or post to the rabbitmq-discuss mailing list. 如果您有任何疑问,请给我们发电子邮件或发送到rabbitmq-discuss邮件列表。

Yes, that's possible. 是的,这是可能的。 Server cluster for a real-time MMO game I'm working on operate this way. 用于我正在进行的实时MMO游戏的服务器集群以这种方式运行。 We use ActiveMQ, but I think all this possible with RabbitMQ as well. 我们使用ActiveMQ,但我认为RabbitMQ也可以实现这一切。

All items that you mentioned you get out of the box, except last one. 您提到的所有项目都是开箱即用的,除了最后一项。

  • each message in queue is eventually processed - this is one of main responsibilities of message brokers 队列中的每条消息最终都会被处理 - 这是消息代理的主要职责之一
  • the work is more or less equally distributed - this is another one :) 工作或多或少均匀分布 - 这是另一个:)
  • an image will be parsed only by one OCR process - the distinction of /topic and /queue exists for this. 图像将仅由一个OCR进程解析 - 为此存在/ topic和/ queue的区别。 Topics are like broadcast signals, queues are tasks. 主题就像广播信号,队列是任务。 You need a /queue in your scenario 您的方案中需要/ queue

To make last one work in desired way, consumers send AMQ-specific argument when subscribing to the queue: 为了使最后一个以期望的方式工作,消费者在订阅队列时发送特定于AMQ的参数:

activemq.prefetchSize: 1

This setting guarantees that consumer will not take any more messages after it took one and until it send an ack to AMQ. 此设置可确保消费者在收到消息后不再接收任何消息,直到它向AMQ发送ack消息。 I believe something similar exists in RabbitMQ. 我相信RabbitMQ中存在类似的东西。

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

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