java - Configuring priority in rabbitmq -
i have following configuration attempting change support priority queues. based on done research says should have 2 queues 1 each priority. adjusted configuration following:
@configuration public class fixedreplyqueueconfig { @bean public connectionfactory rabbitconnectionfactory() { cachingconnectionfactory connectionfactory = new cachingconnectionfactory(); connectionfactory.sethost("localhost"); connectionfactory.setusername("urbanbuz"); connectionfactory.setpassword("ub"); connectionfactory.setvirtualhost("urbanbuzvhost"); return connectionfactory; } /** * @return rabbit template fixed reply queue. */ @bean public rabbittemplate fixedreplyqrabbittemplate() { rabbittemplate template = new rabbittemplate(rabbitconnectionfactory()); template.setexchange(ex().getname()); template.setroutingkey("test"); template.setreplyqueue(replyqueue()); return template; } /** * @return reply listener container - rabbit template listener. */ @bean public simplemessagelistenercontainer replylistenercontainer() { simplemessagelistenercontainer container = new simplemessagelistenercontainer(); container.setconnectionfactory(rabbitconnectionfactory()); container.setqueues(replyqueue()); container.setmessagelistener(fixedreplyqrabbittemplate()); return container; } /** * @return listener container handles request , returns reply. */ @bean public simplemessagelistenercontainer servicelistenercontainer() { simplemessagelistenercontainer container = new simplemessagelistenercontainer(); container.setconnectionfactory(rabbitconnectionfactory()); container.setqueues(requestqueue()); container.setmessagelistener(new messagelisteneradapter(new pojolistener())); return container; } @bean public directexchange ex() { return new directexchange("ub.exchange", false, true); } @bean public binding binding() { return bindingbuilder.bind(requestqueue()).to(ex()).with("test"); } @bean public queue requestqueue() { return new queue("ub.request"); } @bean public queue replyqueue() { return new queue("ub.reply"); } /** * @return admin handle declarations. */ @bean public rabbitadmin admin() { return new rabbitadmin(rabbitconnectionfactory()); } }
to following:
@configuration public class fixedreplyqueueconfig { @bean public connectionfactory rabbitconnectionfactory() { cachingconnectionfactory connectionfactory = new cachingconnectionfactory(); connectionfactory.sethost("localhost"); connectionfactory.setusername("urbanbuz"); connectionfactory.setpassword("ub"); connectionfactory.setvirtualhost("urbanbuzvhost"); return connectionfactory; } /** * @return rabbit template fixed reply queue. */ @bean public rabbittemplate fixedreplyqrabbittemplate() { rabbittemplate template = new rabbittemplate(rabbitconnectionfactory()); template.setexchange(ex().getname()); template.setroutingkey("high"); template.setroutingkey("normal"); template.setreplyqueue(replyqueue()); return template; } /** * @return reply listener container - rabbit template listener. */ @bean public simplemessagelistenercontainer replylistenercontainer() { simplemessagelistenercontainer container = new simplemessagelistenercontainer(); container.setconnectionfactory(rabbitconnectionfactory()); container.setqueues(replyqueue()); container.setmessagelistener(fixedreplyqrabbittemplate()); return container; } /** * @return listener container handles request , returns reply. */ @bean public simplemessagelistenercontainer servicelistenercontainer() { simplemessagelistenercontainer container = new simplemessagelistenercontainer(); container.setconnectionfactory(rabbitconnectionfactory()); container.setqueues(requestqueuehigh(), requestqueue()); container.setmessagelistener(new messagelisteneradapter(new pojolistener())); return container; } @bean public directexchange ex() { return new directexchange("ub.exchange", false, true); } @bean public binding binding() { return bindingbuilder.bind(requestqueue()).to(ex()).with("normal"); } @bean public binding bindinghigh() { return bindingbuilder.bind(requestqueuehigh()).to(ex()).with("high"); } @bean public queue requestqueue() { return new queue("ub.request"); } @bean public queue requestqueuehigh() { return new queue("ub.request.high"); } @bean public queue replyqueue() { return new queue("ub.reply"); } /** * @return admin handle declarations. */ @bean public rabbitadmin admin() { return new rabbitadmin(rabbitconnectionfactory()); } }
am going around correct way? how should proceed make consumer consume 1 on other?
this how call test:
public class app { public static void main(string[] args) { applicationcontext context = new annotationconfigapplicationcontext(fixedreplyqueueconfig.class); rabbittemplate rabbittemplate = context.getbean(rabbittemplate.class); rabbittemplate.convertsendandreceive("ub.exchange", "normal" , "yalla"); rabbittemplate.convertsendandreceive("ub.exchange", "high" , "hello"); } }
and pojo class:
public class pojolistener { public string handlemessage(string foo) { system.out.println("in message receiver"); return "it's weekend!!!!!!!!!!!!"; } }
both messages sent through not sure how priority implemented implemented configuration , classes.
note i'm trying avoid plugins support priority.
the code spring amqp (blockingqueueconsumer
) looks like:
for (string queuename : queues) { if (!this.missingqueues.contains(queuename)) { consumefromqueue(queuename); } }
os, if config is:
container.setqueues(requestqueuehigh(), requestqueue());
you going receive messages requestqueuehigh()
on requestqueue()
. , independently of concurrency
on listenercontainer
.
you can test several messages, stopped
listener start of application. , start()
listener container after sending messages.
Comments
Post a Comment