Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force order of messages with HornetQ

Tags:

java

jms

hornetq

I've setup a jms server with HornetQ as a JMS provider (Queue).

I have an application which acts as a producer and another one (different computer) as a consumer.

I understand that the JMS specification doesn't guarantee the order of delivery, but I'm looking for a way to do just that: receive the messages exactly in the order they have been sent, even if it's provider specific.

Any ideas?

like image 514
Bogdan Avatar asked Nov 03 '10 08:11

Bogdan


2 Answers

Apparently this can be achieved by disabling the consumer cache. This is done by changing the hornetq-jms.xml:

   <connection-factory name="ConnectionFactory">
      <connectors>
         <connector-ref connector-name="netty-connector"/>
      </connectors>
      <entries>
         <entry name="ConnectionFactory"/>
      </entries>

      <consumer-window-size>0</consumer-window-size> <!-- add this line -->
   </connection-factory>
like image 181
Bogdan Avatar answered Oct 03 '22 02:10

Bogdan


Actually section 4.4.10.2 (Order of Message Sends) of the JMS specification is pretty clear about ordering.

If you have a single producer, and single consumer to a queue or topic subscription, message ordering is always guaranteed even in the presence of redeliveries.

If you have multiple consumers, the client buffering may be redelivered in case of rollbacks or closing your consumer, and the client buffer may be delivered out of ordering.

On HornetQ you also have the message group which entitles extra ordering constraints to the produced messages.

like image 30
Clebert Suconic Avatar answered Oct 03 '22 02:10

Clebert Suconic