简体   繁体   English

使用Akka持久邮箱进行事务性消息处理

[英]Transactional message processing with an Akka durable mailbox

I have a Java/Akka application that is integrated with a persistent JMS ( ActiveMQ ) queue. 我有一个与持久性JMSActiveMQ )队列集成的Java / Akka应用程序。

The PersistentQueue wraps a JMS/ActiveMQ queue containing batch jobs. PersistentQueue包装包含批处理作业的JMS / ActiveMQ队列。 Messages are received in a transaction so that if the server goes down in the middle of job execution then the job will be preserved on restart. 在事务中接收到消息,因此,如果服务器在作业执行过程中停机,则该作业将在重新启动时保留。 If the job completes successfully or is cancelled by the user then this transaction is committed to permanently remove the message, and if the job fails then the transaction is rolled back (putting the message on the front of the queue) if the job has executed fewer than MAX_RETRY times. 如果作业成功完成或被用户取消,则该事务将致力于永久删除消息;如果作业失败,则如果作业执行较少,则回滚事务(将消息放在队列的最前面)。超过MAX_RETRY次。

The BatchManager is the interface with the REST controller. BatchManager是与REST控制器的接口。 It is only able to execute one batch job at a time due to limitations imposed by the stored procedures called during job execution. 由于作业执行期间调用的存储过程所施加的限制,它一次只能执行一个批处理作业。 The BatchManager receives jobs from the controller and sends them to the PersistentQueue to be put in the JMS queue, and then polls the PersistentQueue for a new job when a job is enqueued (unless another job is executing) or when a job completes. BatchManager从控制器接收作业,并将其发送到PersistentQueue以放入JMS队列中,然后在一个作业入队(除非正在执行另一个作业)或作业完成时,轮询PersistentQueue以寻找新作业。

I would like to remove the JMS queue and all of the complication of dealing with its JMSExceptions and replace it with a durable mailbox for the BatchManager . 我想删除JMS队列以及处理其JMSExceptions所有麻烦,然后将其替换为BatchManager的持久邮箱。 The problem is that I don't know how I can replicate JMS transactions with a durable mailbox - my understanding is that if the server goes down during job execution then that message is lost forever (as opposed to being put back on the queue for the JMS queue). 问题是我不知道如何使用持久邮箱复制JMS事务-我的理解是,如果服务器在作业执行过程中停机,则该消息将永远丢失(而不是被放回到队列中等待)。 JMS队列)。

Is there a way to effect transactional message processing with an Akka durable mailbox, so that a message won't be lost if the server goes down while it is being executed? 有没有一种方法可以使用Akka持久邮箱进行事务性消息处理,以使如果服务器在执行过程中关闭,消息也不会丢失?

Akka documentation says: Akka文档说:

A durable mailbox is like any other mailbox not likely to be transactional. 持久邮箱就像其他不太可能具有事务性的邮箱一样。 It's possible if the actor crashes after receiving a message, but before completing processing of it, that the message could be lost. 如果actor在收到消息后崩溃,但是在完成对其进行处理之前崩溃,则可能会丢失消息。

But there is also another type of mailbox - Mailbox with Explicit Acknowledgement (aka PeekMailbox). 但是,还有另一种类型的邮箱-带有显式确认的邮箱(又名PeekMailbox)。 Here you can find usage example. 在这里您可以找到用法示例。 And here is the implementation source code. 是实现源代码。

I think you can achieve your goal by implementing custom durable mailbox which extends some of the existing implementations and augments it with the PeekMailbox capabilities. 我认为您可以通过实现自定义的持久邮箱来实现您的目标,该邮箱扩展了一些现有的实现并使用PeekMailbox功能进行了增强。

You could achieve this using a PersistentActor to keep track of posted and completed jobs. 您可以使用PersistentActor跟踪已发布和已完成的作业来实现此目的。

The "distributed workers" activator template contains such a work unit managing actor. “分布式工人”激活器模板包含这样的工作单元管理角色。 (As well as dynamic worker registration and clustering but it might still be worth looking at even if those aren't of interest to you). (以及动态的工作人员注册和聚类,但即使您不感兴趣,仍然值得一看)。

Scala version of the template and Java version of the template Scala版本的模板Java版本的模板

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

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