我按顺序在同一目的地添加两条JMS消息。这些消息是否会按照我添加它们的顺序接收,或者是否有可能进行反向排序,也就是说,首先在目的地中首先接收到的消息将首先被检索。
我将目标添加到目的地:
producer.send(Msg1);
producer.send(Msg2);
在所有情况下(如网络故障和延迟等),将按顺序添加 Msg1
和Msg2
?
答案 0 :(得分:5)
不保证消息排序(并且不是规范要求), Total JMS Message ordering 解释了原因的详细信息。另请参阅Stack Overflow帖子 How to handle order of messages in JMS? 。
答案 1 :(得分:2)
根据JMS2规范
JMS defines that messages sent by a session to a destination must be received
in the order in which they were sent. This defines a partial ordering
constraint on a session’s input message stream.
JMS does not define order of message receipt across destinations or across
a destination’s messages sent from multiple sessions. This aspect of a
session’s input message stream order is timing-dependent. It is not under
application control.
另外
Although clients loosely view the messages they produce within a session
as forming a serial stream of sent messages, the total ordering of this stream
is not significant. The only ordering that is visible to receiving clients is
the order of messages a session sends to a particular destination.
Several things can affect this order like message priority,
persistent/non persistent etc.
因此,为了回答您的问题,将按照与上述信息一起发送的订单接收消息。但是,消息传递到服务器的顺序将受到消息优先级,持久性/非持久性等限制的约束。