简体   繁体   English

使用AKKA actor在Java中使用RabbitMQ消耗多个消息

[英]Consuming multiple messages from RabbitMQ in java with AKKA actors

I am pretty new to RabbitMQ, I want to to consume multiple messages from RabbitMQ so that work can be done parallely also sending acknowledgement only when any of the actor has finished it's task so as not to loose messages. 我是RabbitMQ的新手,我想使用RabbitMQ的多个消息,以便可以并行完成工作,并且仅在任何参与者完​​成任务后才发送确认,以免丢失消息。 How should I proceed, I want to use spring support for AKKA. 我要如何使用AKKA的弹簧支架。

Can I use an actor as a consumer or it should be a plain consumer that can consume multiple messages without sending acknowledgement for any of the message or it should be that I have multiple classes/threads working as consumer instantiated to listen a single message at a time than calling actor (but that would be as if it had no actor or parallelism via AKKA model). 我可以将actor用作使用者,还是应该是普通使用者,可以使用多条消息而不发送任何消息的确认,或者应该有多个类/线程作为使用者实例化,以便在某个实例上侦听一条消息。时间比调用演员要多(但通过AKKA模型就好像没有演员或并行性一样)。

I haven't worked with RabbitMQ per se, but I would probably designate one actor as a dispatcher, that would: 我还没有使用RabbitMQ本身,但是我可能会指定一个演员作为调度员,这将:

  1. Handle RabbitMQ connection. 处理RabbitMQ连接。
  2. Receive messages (doesn't matter if one-by-one or in a batch for efficiency). 接收消息(以一对一或成批的效率无关紧要)。
  3. Distribute work between worker actors, either by creating a new worker for each message, or by sending messages to a pre-created pool of workers. 通过为每条消息创建一个新的工作人员,或通过将消息发送到预先创建的工作人员池,在工作人员角色之间分配工作。
  4. Receive confirmation from worker once task is completed and results are committed, and send acknowledgement back to RabbitMQ. 任务完成并提交结果后,接收工作人员的确认,并将确认发送回RabbitMQ。 Acknowledgment token may be included as a part of worker's task, so no need to track the mappings inside the dispatcher. 确认令牌可以作为工作人员任务的一部分包括在内,因此无需跟踪调度程序内部的映射。

Some additional things to consider are: 需要考虑的其他一些事项是:

  • Supervision strategy: who supervises the dispatcher? 监督策略:谁监督调度员? Who supervises the workers? 谁监督工人? What happens if they crash? 如果它们崩溃了怎么办?
  • Message re-sends when running in a distributed environment. 在分布式环境中运行时,消息会重新发送。

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

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