消息驱动Bean和消息消费顺序

发布于 2024-10-23 15:46:29 字数 199 浏览 4 评论 0原文

我有一个 MDB,它订阅了一个主题,该主题发送消息,其内容最终保存到数据库。

我知道 MDB 是池化的,因此容器能够并行处理多个传入消息。就我而言,这些消息的消费(然后持久化)顺序很重要。我不希望 MDB 实例池在消息在 JMS 主题中发布时使用并以不同的顺序保留消息。

这会是一个问题吗?如果是这样,是否有办法告诉容器在消费消息时遵循严格的传入顺序?

I have an MDB that gets subscribed to a topic which sends messages whose content is eventually persisted to a DB.

I know MDBs are pooled, and therefore the container is able to handle more than one incoming message in parallel. In my case, the order in which those messages are consumed (and then persisted) is important. I don't want an MDB instance pool to consume and then persist messages in a different order as they get published in the JMS topic.

Can this be an issue? If so, is there a way of telling the container to follow strict incoming order when consuming messages?

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

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

发布评论

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

评论(2

逆光下的微笑 2024-10-30 15:46:29

那里复制:

以确保接收顺序与客户端发送消息的顺序相匹配,您必须执行以下操作:

  • 将 MDB 的 max-beans-in-free-pool 设置为 1。这可确保 MDB 是消息的唯一使用者。

  • 如果您的 MDB 部署在集群上,请将它们部署到集群中的单个节点,[...]。

  • 为了确保事务回滚和恢复时的消息排序,请配置自定义连接工厂,并将 MessagesMaximum 设置为 1,并确保未配置重新传递延迟。欲了解更多信息,请参阅[...]。

Copied from there:

To ensure that receipt order matches the order in which the client sent the message, you must do the following:

  • Set max-beans-in-free-pool to 1 for the MDB. This ensures that the MDB is the sole consumer of the message.

  • If your MDBs are deployed on a cluster, deploy them to a single node in the cluster, [...].

  • To ensure message ordering in the event of transaction rollback and recovery, configure a custom connection factory with MessagesMaximum set to 1, and ensure that no redelivery delay is configured. For more information see [...].
蓝礼 2024-10-30 15:46:29

您应该能够将 MDB 池的大小限制为 1,从而确保按照正确的顺序处理消息。

当然,如果您仍然想要一些并行性,那么您有几个选择,但这实际上取决于数据。

如果某些消息有一些共同点,并且处理顺序仅在共享共同值的消息组中起作用,那么您可能需要有多个主题,或者使用队列和线程池。

另一方面,如果与消息到达相关的逻辑的某些部分可以并行发生,而其他部分则不能,那么您需要将逻辑分为并行确定和并行不正常部分,并相应地处理这些位。

You should be able to limit the size of the MDB pool to 1, thus ensuring that the messages are processed in the correct order.

Of course, if you still want some parallelism in there, then you have a couple of options, but that really depends on the data.

If certain messages have something in common and the order of processing only matters within that group of messages that share a common value, then you may need to have multiple topics, or use Queues and a threadpool.

If on the other hand certain parts of the logic associated with the arrival of a message can take place in parallel, while other bits cannot, then you will need to split the logic up into the parallel-ok and parallel-not-ok parts, and process those bits accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文