关联 JMS 消息的计划重试

发布于 2024-09-25 07:42:07 字数 490 浏览 0 评论 0原文

我有一个单线程消息侦听器,用于侦听传入消息。接收到的消息在收到时保留在数据库中。

有一条消息 A,关联的消息 B 跟随它并引用它。在某些奇怪的情况下,B 在 A 之前到达。现在在这种情况下,在一些“x”相等的间隔之后必须有 3 次重试,以查看 A 是否已到达并且然后保持关联。

由于消息监听器是单线程的,如果我们让线程休眠,整个系统都会受到影响。所以必须有一个单独的线程重试。

我们是否可以使用 Quartz Job Scheduler 来实现此目的,以避免处理多线程问题,并通过以下 2 种方式中的任何一种来持久存储,

  1. 在 Quartz 中调度作业 3 次,并跟踪 JobDataMap 中的标志以检查是否之前的重试成功,然后返回而不执行任何操作

,或者

2.安排一个作业重试一次,然后如果重试失败,则在几秒钟后安排相同的作业。

石英是否只能用于重复性工作,并且没有跨工作的一些状态信息,或者是否有其他更好的方法来做到这一点。

I have a single threaded message listener that listens for the incoming messages.The received messages are persisted in a database as they are recieved.

There is a message A and associated message B follows it with a reference it.In Some Odd occurences, B arrives before A. Now in this case, There has to be 3retries after some 'x' equal intervals to see if A has arrived and then persists the association.

As the message listener is single threaded if we put the thread to sleep the whole system would be affected. So there has to be a separate thread retrying.

Can we use Quartz Job Scheduler for this purpose to avoid handling multiThreading issues and to have a PERSISTENT STORE of the in any of the following 2 ways,

  1. Schedule a Job in Quartz for 3 times and keep track of a flag in the JobDataMap to check if previous retries succeeds then return without doing anything

OR

2.Schedule a Job to retry once and then if the retry fails schedule the same job after a few seconds.

Can quartz be used only for repetitive jobs and not have some state information span across job or Is there any other better way to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-10-02 07:42:07

您应该配置 JMS 提供程序以设置消息队列上的重新传递延迟。在您的代码中,您可以调用 context.setRollbackOnly 来中止未通过先决条件检查的消息。

这样的话,代码执行场景就变成:

  • 消费“B”,检查先决条件并检测A是否缺少
  • ,回滚事务,消息返回队列,在配置的延迟消费后重新投递
  • 并处理下一条消息“A”
  • 延迟后,MDB再次消费并处理“B”成功

You should configure your JMS provider to set the redelivery delay on your message queue. In your code, you call context.setRollbackOnly to abort a message that does not pass prerequisites check.

In that case, the code execution scenario becomes:

  • consume "B", check for prerequisite and detect A is lacking
  • roll back the transaction and the message returns to the queue, it will be re-delivered after the configured delay
  • consume and process next message "A"
  • after the delay, the MDB consumes and processes again "B" with success
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文