[rabbitmq-discuss] 答复: something about message priority

Gary Russell grussell at vmware.com
Fri Jul 27 12:58:54 BST 2012


This comes up once in a while on the spring-amqp ( http://forum.springsource.org/forumdisplay.php?74-AMQP) and spring-integration ( http://forum.springsource.org/forumdisplay.php?42-Integration) forums; especially from folks migrating from JMS.

The general solution is to simulate priority, by having the listener container listen on multiple queues (e.g. 'low, normal, high') and have the client use a different routing key, based on the priority.

This generally works fine, as long as most messages are 'normal' and only a few are high. If you have a priority distribution that has many high priority messages (in relation to normal), you might be better off configuring a different listener container for each queue, so you can configure the consumer count appropriately for each queue (e.g. more consumers for the high priority queue).

On the client side, when using Spring Integration, it's easy to configure a routing-key-expression on the <outbound-channel-adapter/> to generate the appropriate routing key.

Even when not using Spring Integration, it's simple to do the same.

Hope that helps.

Gary
Spring Integration Team
VMware, Inc.


On 07/27/2012 05:31 AM, Ernest Staszuk wrote:
I didn't use spring amqp api, so I can not provide you working example.

I use consuming with small timeout (and there is a cost of time - small delay,
 not an issue in my case, cpu usage and network fingerprints stays very small).
I was also taking advantage of rabbit's java client prefetching (I am not sure
if spring implements that). These two combined gave me acceptable approximation of priorities.

You could also add to messages own argument (for example myPriority) and consume all messages
as they are available (or let's say up to 200 messages or sth), then put them in a priority
queue on your application side. And then process them from the head of this container (using
dedicated thread). That also may give you acceptable results.

Note that the state of art is as follows: RabbitMQ is a FIFO queue, and does not make
use of message priorities today. It could be changed in one of the future releases, I don't
know when it may be. As consequence of that you should apply some reasonable workaround
which will be acceptable for you or reconsider your needs (maybe you don't really need
priorities?) or use something else than RabbitMQ or implement it by yourself. By the way
AMQP itself says that "Messages with higher priorities MAY be delivered before those with
lower priorities". Following that messages priority in any implementation of AMQP may
be not consistent.

Best regards,
Ernest Staszuk





W dniu 2012-07-27 10:50, andy pisze:
at as you say ,if we are processing 2st queue message as soon as the 1st queue gets a new message needed to process,how can we switch to process 1st? It also means that we should check the amount of  messages in the queue  in order ,I think it will cost much time and machine resource.and could you tell me  how I could  use spring amqp a


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120727/333c9986/attachment.htm>


More information about the rabbitmq-discuss mailing list