关于 JMS receive()/MessageListener 优先级的问题

发布于 2024-11-27 20:55:23 字数 199 浏览 1 评论 0原文

如果我为 MessageConsumer 设置一个 MessageListener 对象,然后对该消费者调用 receive() ,会发生什么?提供者会将消息提供给 receive(),还是会在 MessageListener 对象处理消息时继续被阻止?

If I set a MessageListener object for a MessageConsumer, and then call receive() on that consumer, what will happen? Will the provider give the message to receive(), or will it continue to be blocked while the message is processed by the MessageListener object?

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

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

发布评论

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

评论(2

半衬遮猫 2024-12-04 20:55:23

您将得到一个异常,因为会话必须处于异步或同步模式。来自JMS规范的4.4.6

会话的单线程控制限制的一个后果是
带有消息监听器的会话也不能用于同步接收
消息。会话专用于用于控制的线程
传递给消息监听器或者专用于发起的控制线程
通过客户端代码。尝试在同一会话中组合两者是错误的。

You will get an exception, as a Session must be in either asynchronous or synchronous modes. From 4.4.6 of the JMS specification

One consequence of the session’s single-thread-of-control restriction is that a
session with message listeners cannot also be used to synchronously receive
messages. Either the session is dedicated to the thread of control used for
delivery to message listeners or it is dedicated to a thread of control initiated
by client code. It is erroneous to attempt to combine both in the same session.

∞梦里开花 2024-12-04 20:55:23

我很难想象这样做有意义的情况。

假设您的 receive() 没有优先权。那么估计就没有什么效果了。

假设您的 receive() 确实具有优先级。当您的接收者收到消息后,您希望发生什么?大概直到您再次调用 receive 消息消费者才会接收消息?在这种情况下,您的系统的行为实际上是一种巨大的竞争条件,消息的确切到达时间会导致不同的行为。

你一定能够做得比这更好。拥有一个“自适应”MessageConsumer,您也许可以控制其行为。

I'm having a hard time imagining a situation where doing this makes sense.

Suppose that your receive() did not have precedence. Then presumably there's no effect.

Suppose that your receive() did have precedence. What would you expect to happen after your receive gets a message? Presumably until you call receive again the Message Consumer would be taking the messages? In that case your system's behaviour is effectively one huge race condition, the exact arrival times of messages causes different behaviours.

You must be able to do better than this. Have an "adaptive" MessageConsumer whose behaviour you can control perhaps.

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