spring boot - RabbitTemplate to connect to RabbitMQ : getting - NOT_FOUND - no queue -


i new spring , working on cloud based application , trying use rabbittemplate , rabbitmq.

i able store data queue using.

rabbittemplate.convertandsend(queue_name, msg); 

but when receiving data same queue using

rabbittemplate.receiveandconvert(queue_name) 

i getting exception as:

err caused by: java.io.ioexception 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.wrap(amqchannel.java:106) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.wrap(amqchannel.java:102) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.exnwrappingrpc(amqchannel.java:124) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.channeln.basicget(channeln.java:985) 2016-09-13t11:15:21.38+0530 [app/0] err @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) 2016-09-13t11:15:21.38+0530 [app/0] err @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) 2016-09-13t11:15:21.38+0530 [app/0] err @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) 2016-09-13t11:15:21.38+0530 [app/0] err @ java.lang.reflect.method.invoke(method.java:498) 2016-09-13t11:15:21.38+0530 [app/0] err @ org.springframework.amqp.rabbit.connection.cachingconnectionfactory$cachedchannelinvocationhandler.invoke(cachingconnectionfactory.java:625) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.sun.proxy.$proxy55.basicget(unknown source) 2016-09-13t11:15:21.38+0530 [app/0] err @ org.springframework.amqp.rabbit.core.rabbittemplate$4.doinrabbit(rabbittemplate.java:650) 2016-09-13t11:15:21.38+0530 [app/0] err @ org.springframework.amqp.rabbit.core.rabbittemplate$4.doinrabbit(rabbittemplate.java:646) 2016-09-13t11:15:21.38+0530 [app/0] err @ org.springframework.amqp.rabbit.core.rabbittemplate.doexecute(rabbittemplate.java:1045) 2016-09-13t11:15:21.38+0530 [app/0] err ... 50 more 2016-09-13t11:15:21.38+0530 [app/0] err caused by: com.rabbitmq.client.shutdownsignalexception: channel error; protocol method: #method(reply-code=404, reply-text=not_found - no queue 'testqueue' in vhost '9cc1b4db-636e-4251-bb68-c7ed7f3be1d3', class-id=60, method-id=70) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.utility.valueorexception.getvalue(valueorexception.java:67) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.utility.blockingvalueorexception.uninterruptiblegetvalue(blockingvalueorexception.java:33) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel$blockingrpccontinuation.getreply(amqchannel.java:343) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.privaterpc(amqchannel.java:216) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.exnwrappingrpc(amqchannel.java:118) 2016-09-13t11:15:21.38+0530 [app/0] err ... 60 more 2016-09-13t11:15:21.38+0530 [app/0] err caused by: com.rabbitmq.client.shutdownsignalexception: channel error; protocol method: #method(reply-code=404, reply-text=not_found - no queue 'testqueue' in vhost '9cc1b4db-636e-4251-bb68-c7ed7f3be1d3', class-id=60, method-id=70) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.channeln.asyncshutdown(channeln.java:478) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.channeln.processasync(channeln.java:315) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.handlecompleteinboundcommand(amqchannel.java:144) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqchannel.handleframe(amqchannel.java:91) 2016-09-13t11:15:21.38+0530 [app/0] err @ com.rabbitmq.client.impl.amqconnection$mainloop.run(amqconnection.java:552)

my code:

@configuration @profile("cloud") public class rabbitconfig extends abstractcloudconfig {  @bean public rabbittemplate rabbittemplate(){     cachingconnectionfactory cachingconnectionfactory = (cachingconnectionfactory)connectionfactory().rabbitconnectionfactory();      cachingconnectionfactory.setcachemode(cachingconnectionfactory.cachemode.channel);      rabbittemplate rabbittemplate = new rabbittemplate(cachingconnectionfactory);      return rabbittemplate;     } } 

my controller:

@restcontroller @requestmapping("mq") public class maincontroller {  @autowired private rabbittemplate rabbittemplate;  private static final string queue_name = "testqueue";  @requestmapping(value = "/putinq/{msg}",method = requestmethod.put) public string storemessage(@pathvariable("msg") string msg){     string result = "";      rabbittemplate.setqueue(queue_name);     try {         rabbittemplate.convertandsend(queue_name, msg); // no exception         thread.sleep(3000);         object object = rabbittemplate.receiveandconvert(queue_name); // getting exception here           system.out.println("received: "+object);         result = "success";     }catch(exception ex){         ex.printstacktrace();     }      return result; } } 

updated rabbitconfig.java

@configuration @profile("cloud") public class rabbitconfig extends abstractcloudconfig {  private static final string queue_name = "testqueue";  @bean public rabbittemplate rabbittemplate(){     cachingconnectionfactory cachingconnectionfactory = (cachingconnectionfactory)(connectionfactory().rabbitconnectionfactory());     system.out.println("------------------------ rabbit mq template: " + cachingconnectionfactory.getcachemode());     system.out.println("------------------------ cachingconnectionfactory.tostring(): " + cachingconnectionfactory.tostring());     cachingconnectionfactory.setcachemode(cachingconnectionfactory.cachemode.channel);     cachingconnectionfactory.setchannelcachesize(25);     system.out.println("----------after set-------------- rabbit mq template: " + cachingconnectionfactory.getcachemode());     system.out.println("------------------------ cachingconnectionfactory.tostring(): " + cachingconnectionfactory.getchannelcachesize());     rabbittemplate rabbittemplate = new rabbittemplate(cachingconnectionfactory);      system.out.println("------------------------ rabbit mq template: " + rabbittemplate);     return rabbittemplate; }  @bean public queue myqueue() {     system.out.println("--------------@@---------- creating queue: ");     final boolean isdurable = true;     final boolean isexclusive = false;     final boolean autodelete = false;     return new queue(queue_name, isdurable, isexclusive, autodelete); }   } 

i tried searching on internet still not able resolve issue, struggling exception long, appreciated.

got solution!

cachingconnectionfactory cachingconnectionfactory = new cachingconnectionfactory();     cachingconnectionfactory.setusername("");     cachingconnectionfactory.setpassword("");     cachingconnectionfactory.setvirtualhost("");     cachingconnectionfactory.sethost("");     cachingconnectionfactory.setport(1);     cachingconnectionfactory.setrequestedheartbeat(30);     cachingconnectionfactory.setconnectiontimeout(30000);      rabbitadmin admin = new rabbitadmin(cachingconnectionfactory());     queue queue = new queue(queue_name);     admin.declarequeue(queue);     topicexchange exchange = new topicexchange(exchange_name);     admin.declareexchange(exchange);   admin.declarebinding(bindingbuilder.bind(queue).to(exchange).with(queue_name)); rabbittemplate template = new rabbittemplate(cachingconnectionfactory()); 

you need define queue in configuration.

@bean public org.springframework.amqp.core.queue myqueue() {     final boolean isdurable = true;     final boolean isexclusive = false;     final boolean autodelete = false;     return new org.springframework.amqp.core.queue(queue_name, isdurable, isexclusive, autodelete); } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -