关于 JMS receive()/MessageListener 优先级的问题
如果我为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将得到一个异常,因为会话必须处于异步或同步模式。来自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
我很难想象这样做有意义的情况。
假设您的 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.