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 pr开发者_JAVA技巧ovider specific.
Any ideas?
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>
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.
精彩评论