PDA

View Full Version : High Priority Messages



PMBell
Jan 31st, 2012, 07:35 AM
Hello again,

Quick question: does Spring AMQP support the notion of message priority? The AMQP spec says that an implementation *may* provide such support. By this notion I understand that a (relatively) high priority message would move from the exchange to the head (or close to the head) of the appropriate message queues. Perhaps this is really a RabbitMQ question...

Also, when I view what I think is the current documentation for the Spring AMQP classes (see below for lengthy URL), I find hyperlinks to a Message class. But clicking on this link gives a 404. Is there no such class, is this a broken link, or am I looking at the wrong docs?

Thanks for your help.

-Paul

http://www.jarvana.com/jarvana/view/org/springframework/amqp/spring-rabbit/1.0.0.RELEASE/spring-rabbit-1.0.0.RELEASE-javadoc.jar!/allclasses-noframe.html

Gary Russell
Jan 31st, 2012, 09:12 AM
First, we don't by default map the SI header MessageHeaders.PRIORITY (priority) to the AMQP priority header. However, even when configuring the adapter to do so...



<int-amqp:outbound-channel-adapter channel="toRabbit"
amqp-template="amqpTemplate" exchange-name="si.test.exchange"
mapped-request-headers="priority"
routing-key="si.test.binding"/>


...my experimentation does not indicate it is used by Rabbit. Messages sent to the queue arrive serially, regardless of the priority header.

Therefore, I don't believe Rabbit supports priority but, since a listener can bind to multiple queues, you can come close by sending low-volume high priority messages to a different queue.



<int:channel id="toRabbit" />

<int-amqp:outbound-channel-adapter channel="toRabbit"
amqp-template="amqpTemplate" exchange-name="si.test.exchange"
routing-key="si.test.binding"/>

<int:channel id="toRabbitHigh" />

<int-amqp:outbound-channel-adapter channel="toRabbitHigh"
amqp-template="amqpTemplate" exchange-name="si.test.exchange"
routing-key="si.test.binding2"/>


And on the receiving side...



<int-amqp:inbound-channel-adapter channel="fromRabbit" mapped-request-headers="priority"
queue-names="si.test.queue, si.test.queue2"
connection-factory="connectionFactory" />


This worked fine for me; messages sent to the second queue jump ahead of any messages still in the first queue.

Re: JavaDoc; use our official docs - http://static.springsource.org/spring-amqp/docs/1.0.x/apidocs/

Linked from here http://www.springsource.org/spring-amqp

It looks like the problem is that provider you are using is just showing the spring-rabbit javadocs (from the jar), with no links to the spring-amqp jar.

PMBell
Jan 31st, 2012, 09:15 AM
Beautiful, Gary - thank you very much.

I had already considered the user of a second queue, but wanted to see if this could be avoided.

-Paul