【问题标题】:JMS queue message receive orderJMS队列消息接收顺序
【发布时间】:2011-06-14 07:43:45
【问题描述】:

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

我正在添加到目的地:

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

Msg1Msg2 在所有情况下都会按顺序添加(如网络故障和延迟等)?

【问题讨论】:

    标签: java jms ejb-3.0 ejb openjms


    【解决方案1】:

    不保证消息顺序(规范也没有强制要求),Total JMS Message ordering 详细解释了原因。另请参阅 Stack 溢出帖子 How to handle order of messages in JMS?

    【讨论】:

      【解决方案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.
      

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

      【讨论】:

        猜你喜欢
        • 2012-01-19
        • 2012-05-06
        • 2013-08-01
        • 2021-03-29
        • 2018-01-28
        • 1970-01-01
        • 2014-07-08
        • 2019-10-08
        • 2010-09-19
        相关资源
        最近更新 更多