3

我按顺序在同一目标中添加两条 JMS 消息。这两条消息的接收顺序是否与我添加它们的顺序相同,或者是否有机会进行反向排序,也就是说,在目标中首先接收到的消息将首先被检索。

我添加到目的地为:

producer.send(Msg1);
producer.send(Msg2);

Msg1并且Msg2将在所有情况下按顺序添加(如网络故障和延迟等)?

4

2 回答 2

6

不保证消息排序(规范也没有强制要求),Total JMS Message ordering解释了原因的详细信息。另请参阅 Stack Overflow 帖子 如何处理 JMS 中的消息顺序?.

于 2011-01-24T05:54:58.360 回答
3

根据 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.

因此,要回答您的问题,消息将按照与上述信息一起发送的顺序收到。然而,消息传递到服务器的顺序将受到消息优先级、持久性/非持久性等限制的约束。

于 2014-02-12T12:01:35.497 回答