Spring-boot Integration RABBITMQ start error no queue ' Dev_pms2invoi_queue ' in vhost '/'

Source: Internet
Author: User
Tags bind manual rabbitmq

The

consolidates RABBITMQ in spring-boot using pure annotations, as follows

@Configuration public class Rabbitmqconfig {@Bean (value = "pmsmqconnectionfactory") public connectionfactory PmsM
        Qconnectionfactory () {cachingconnectionfactory connectionfactory=new cachingconnectionfactory ();
        Connectionfactory.setaddresses (pmsmqserveraddress);
        Connectionfactory.setvirtualhost (Pmsmqservervirtualhost);
        Connectionfactory.setusername (Pmsmqserverusername);
        Connectionfactory.setpassword (Pmsmqserverpassword);
    return connectionfactory; } @Bean (value = "Pmsconsumerqueue") public Queue Pmsconsumerqueue () {queue consumerqueue=new queue (Pmsmqco

        Nsumerqueue,pmsmqqueuepersist);
    return consumerqueue; } @Bean (value = "Pmsconsumerexchange") Public Exchange Pmsconsumerexchange () {Exchange Consumerexchange=ne
        W Directexchange (Pmsmqconsumerexchangename,pmsmqqueuepersist,false);
    return consumerexchange; } @Bean (value = "pmsconsumermessagebinding") public Binding PmscOnsumermessagebinding (@Qualifier ("Pmsconsumerqueue") queue queue, @Quali
    Fier ("Pmsconsumerexchange") Exchange Exchange {return Bindingbuilder.bind (queue). to (Exchange). With (""). Noargs (); } @Bean (value = "Pmsmessagelistenercontainer") public Simplemessagelistenercontainer Pmsmessagelistenercontain
                                                                      ER (@Qualifier ("Pmsmqconnectionfactory") ConnectionFactory ConnectionFactory, @Qualifier ("Pmsmqconsumer") Pmsmqconsumer Pmsmqconsumer, @Qualifier ("Pmsconsumerqueue") queue queue
        ) {Simplemessagelistenercontainer container=new simplemessagelistenercontainer ();
        Container.setconnectionfactory (ConnectionFactory);
        Container.setmessagelistener (Pmsmqconsumer);
        Container.setqueues (queue);
        Container.setacknowledgemode (acknowledgemode.manual);
    return container; }
}

Results start Error:

2018-02-28 19:50:26.560 [WARN] [org.springframework.amqp.rabbit.listener.blockingqueueconsumer:544] Queue Declaration failed; Retries Left=3 org.springframework.amqp.rabbit.listener.blockingqueueconsumer$declarationexception:failed to Declare queue (s): [Dev_pms2invoi_queue] at Org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations ( blockingqueueconsumer.java:636) at Org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start ( blockingqueueconsumer.java:535) at org.springframework.amqp.rabbit.listener.simplemessagelistenercontainer$ Asyncmessageprocessingconsumer.run (simplemessagelistenercontainer.java:1389) at Java.lang.Thread.run (Thread.java : 745) caused by:java.io.IOException:null at Com.rabbitmq.client.impl.AMQChannel.wrap (amqchannel.java:105) at COM . Rabbitmq.client.impl.AMQChannel.wrap (amqchannel.java:101) at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc (amqchannel.java:123) at COM.RABBITMQ.CLIENT.IMPL.CHanneln.queuedeclarepassive (channeln.java:992) at Com.rabbitmq.client.impl.ChannelN.queueDeclarePassive ( CHANNELN.JAVA:50) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccess Orimpl.invoke (nativemethodaccessorimpl.java:62) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:498) at org.springframework.a Mqp.rabbit.connection.cachingconnectionfactory$cachedchannelinvocationhandler.invoke ( cachingconnectionfactory.java:955) at Com.sun.proxy. $Proxy 155.queueDeclarePassive (Unknown Source) at Org.springfra
    Mework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations (blockingqueueconsumer.java:615) ... 3 common frames omitted caused by:com.rabbitmq.client.ShutdownSignalException:channel error; Protocol method: #method <channel.close> (reply-code=404, reply-text=not_found-no queue ' dev_pms2invoi_queue ' in Vhost '/', class-id=50, method-id=10) at Com.rabbitmq.utility.ValueOrException.getValue (valueorexception.java:66) at COM. Rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue (blockingvalueorexception.java:32) at Com.rabbitmq.client.impl.amqchannel$blockingrpccontinuation.getreply (amqchannel.java:366) at COM.RABBITMQ.CLIENT.IMPL.AMQCHANNEL.PRIVATERPC (amqchannel.java:229) at COM.RABBITMQ.CLIENT.IMPL.AMQCHANNEL.EXNWRAPPINGRPC (amqchannel.java:117) ... Common frames omitted caused by:com.rabbitmq.client.ShutdownSignalException:channel error; Protocol method: #method <channel.close> (reply-code=404, reply-text=not_found-no queue ' dev_pms2invoi_queue ' in Vhost '/', class-id=50, method-id=10) at Com.rabbitmq.client.impl.ChannelN.asyncShutdown (channeln.java:505) at COM . Rabbitmq.client.impl.ChannelN.processAsync (channeln.java:336) at Com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand (amqchannel.java:143) at com.rabbitmq.client. Impl. Amqchannel.handleframe (amqchannel.java:90) at Com.rabbitmq.client.impl.AMQConnection.readFrame ( amqconnection.java:634) at com.rabbitmq.client.impl.amqconnection.access$300 (amqconnection.java:47) at COM.RABBITM Q.client.impl.amqconnection$mainloop.run (amqconnection.java:572) ... 1 Common frames omitted

This problem occurs because I have defined the connectionfactory of MQ myself, so I need to define a rabbitadmin to manage this connectionfactory, see: https:// stackoverflow.com/questions/49028289/no-queue-dev-pms2invoi-queue-in-vhost-when-using-rabbitmq-in-spring-boot/ 49035026#49035026. So the changes are as follows:

@Configuration public class Rabbitmqconfig {@Bean (value = "pmsmqconnectionfactory") public connectionfactory PmsM
        Qconnectionfactory () {cachingconnectionfactory connectionfactory=new cachingconnectionfactory ();
        Connectionfactory.setaddresses (pmsmqserveraddress);
        Connectionfactory.setvirtualhost (Pmsmqservervirtualhost);
        Connectionfactory.setusername (Pmsmqserverusername);
        Connectionfactory.setpassword (Pmsmqserverpassword);
    return connectionfactory; }/** * Because a custom connectionfactory is used, you need to define Rabbitadmin */@Bean (value = "pmsrabbitadmin") public Rab
        Bitadmin pmsrabbitadmin () {rabbitadmin rabbitadmin=new rabbitadmin (Pmsmqconnectionfactory ());
    return rabbitadmin; } @Bean (value = "Pmsconsumerqueue") public Queue Pmsconsumerqueue () {queue consumerqueue=new queue (Pmsmqco
        Nsumerqueue,pmsmqqueuepersist);
        Consumerqueue.setadminsthatshoulddeclare (Pmsrabbitadmin ()); RetUrn Consumerqueue; } @Bean (value = "Pmsconsumerexchange") public Exchange Pmsconsumerexchange () {Directexchange Consumerexcha
        Nge=new Directexchange (Pmsmqconsumerexchangename,pmsmqqueuepersist,false);
        Consumerexchange.setadminsthatshoulddeclare (Pmsrabbitadmin ());
    return consumerexchange; } @Bean (value = "pmsconsumermessagebinding") public Binding pmsconsumermessagebinding (@Qualifier ("Pmsconsumerqueue
        ") Queue queue, @Qualifier (" Pmsconsumerexchange ") Exchange Exchange) {
        Binding binding= bindingbuilder.bind (queue). to (Exchange). With (""). Noargs ();
        Binding.setadminsthatshoulddeclare (Pmsrabbitadmin ());
    return binding; } @Bean (value = "Pmsmessagelistenercontainer") Public Simplemessagelistenercontainer Pmsmessagelistenercontainer (
                                                            @Qualifier ("Pmsmqconnectionfactory") ConnectionFactory ConnectionFactory,          @Qualifier ("Pmsmqconsumer") Pmsmqconsumer Pmsmqconsumer, @Qualifier ("Pmsconsumerqueue") queue queue) {Simp
        Lemessagelistenercontainer container=new Simplemessagelistenercontainer ();
        Container.setconnectionfactory (ConnectionFactory);
        Container.setmessagelistener (Pmsmqconsumer);
        Container.setqueues (queue);
        Container.setrabbitadmin (Pmsrabbitadmin ());
        Set the man-Sent Ack Container.setacknowledgemode (acknowledgemode.manual);
    return container; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.