<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
This comes up once in a while on the spring-amqp (
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<a href="http://forum.springsource.org/forumdisplay.php?74-AMQP">http://forum.springsource.org/forumdisplay.php?74-AMQP</a>)
and spring-integration (
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<a
href="http://forum.springsource.org/forumdisplay.php?42-Integration">http://forum.springsource.org/forumdisplay.php?42-Integration</a>)
forums; especially from folks migrating from JMS.<br>
<br>
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.<br>
<br>
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).<br>
<br>
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.<br>
<br>
Even when not using Spring Integration, it's simple to do the same.<br>
<br>
Hope that helps.<br>
<br>
Gary<br>
Spring Integration Team<br>
VMware, Inc.<br>
<br>
<br>
<div class="moz-cite-prefix">On 07/27/2012 05:31 AM, Ernest Staszuk
wrote:<br>
</div>
<blockquote cite="mid:50126009.7070001@comarch.pl" type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<div class="moz-cite-prefix">I didn't use spring amqp api, so I
can not provide you working example. <br>
<br>
I use consuming with small timeout (and there is a cost of time
- small delay,<br>
not an issue in my case, cpu usage and network fingerprints
stays very small). <br>
I was also taking advantage of rabbit's java client prefetching
(I am not sure <br>
if spring implements that). These two combined gave me
acceptable approximation of priorities. <br>
<br>
You could also add to messages own argument (for example
myPriority) and consume all messages<br>
as they are available (or let's say up to 200 messages or sth),
then put them in a priority <br>
queue on your application side. And then process them from the
head of this container (using <br>
dedicated thread). That also may give you acceptable results. <br>
<br>
Note that the state of art is as follows: RabbitMQ is a FIFO
queue, and does not make <br>
use of message priorities today. It could be changed in one of
the future releases, I don't <br>
know when it may be. As consequence of that you should apply
some reasonable workaround <br>
which will be acceptable for you or reconsider your needs (maybe
you don't really need <br>
priorities?) or use something else than RabbitMQ or implement it
by yourself. By the way <br>
AMQP itself says that "Messages with higher priorities MAY be
delivered before those with <br>
lower priorities". Following that messages priority in any
implementation of AMQP may <br>
be not consistent.<br>
<br>
Best regards, <br>
Ernest Staszuk<br>
<br>
<br>
<br>
<br>
<br>
W dniu 2012-07-27 10:50, andy pisze:<br>
</div>
<blockquote cite="mid:033c01cd6bd4$e76f6b10$b64e4130$@gmail.com"
type="cite"><span style="color:#1F497D" lang="EN-US">at as you
say ,if we are processing 2st queue message as soon as the 1<sup>st</sup>
queue gets a new message needed to process,how can we switch
to process 1</span><sup><span
style="font-family:宋体;color:#1F497D" lang="EN-US">st</span></sup><span
style="color:#1F497D" lang="EN-US">? 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</span></blockquote>
<br>
</blockquote>
<br>
</body>
</html>