当前位置: 首页 > 知识库问答 >
问题:

RabbitMQ无法声明队列,侦听器无法获取服务器上的队列

隗和裕
2023-03-14

我有一个spring boot rabbitmq应用程序,其中我必须将一个Employee对象发送到队列中。那么我已经设置了一个侦听器应用程序。对employee对象进行一些处理,并将此对象放入回调队列中。

为此,我在应用程序中创建了以下对象。

    null

我的应用程序文件如下所示。

应用程序.属性

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.virtual-host=foo
emp.rabbitmq.directexchange=EMP_EXCHANGE1
emp.rabbitmq.requestqueue=EMP_QUEUE1
emp.rabbitmq.routingkey=EMP_ROUTING_KEY1

MainClass.java

package com.employee;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MainClass {

    public static void main(String[] args) {
        SpringApplication.run(
                MainClass.class, args);
    }
}
package com.employee.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;

public class ApplicationContextProvider implements ApplicationContextAware {
    private static ApplicationContext context;

    public ApplicationContext getApplicationContext(){
        return context;
    }

    @Override
    public void setApplicationContext(ApplicationContext arg0) throws BeansException {
        context = arg0;

    }

    public Object getBean(String name){
        return context.getBean(name, Object.class);
    }

    public void addBean(String beanName, Object beanObject){
        ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext)context).getBeanFactory();
        beanFactory.registerSingleton(beanName, beanObject);
    }

    public void removeBean(String beanName){
        BeanDefinitionRegistry reg = (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory();
        reg.removeBeanDefinition(beanName);
    }
}
package com.employee.constant;

public class Constants {

    public static final String CALLBACKQUEUE = "_CBQ";

}
package com.employee.model;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id", scope = Employee.class)
public class Employee {

    private String empName;
    private String empId;
    private String changedValue;
    public String getEmpName() {
        return empName;
    }
    public void setEmpName(String empName) {
        this.empName = empName;
    }
    public String getEmpId() {
        return empId;
    }
    public void setEmpId(String empId) {
        this.empId = empId;
    }
    public String getChangedValue() {
        return changedValue;
    }
    public void setChangedValue(String changedValue) {
        this.changedValue = changedValue;
    }


}
package com.employee.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.employee.constant.Constants;
import com.employee.service.EmployeeResponseReceiver;

@Configuration
@EnableAutoConfiguration
@ComponentScan(value="com.en.*")
public class EmployeeProducerInitializer {

    @Value("${emp.rabbitmq.requestqueue}")
    String requestQueueName;

    @Value("${emp.rabbitmq.directexchange}")
    String directExchange;

    @Value("${emp.rabbitmq.routingkey}")
    private String requestRoutingKey;

    @Autowired
    private ConnectionFactory rabbitConnectionFactory;

    @Bean
    ApplicationContextProvider applicationContextProvider(){
        System.out.println("inside app ctx provider");
        return new ApplicationContextProvider();
    };

    @Bean
    RabbitAdmin rabbitAdmin(){
        System.out.println("inside rabbit admin");
        return new RabbitAdmin(rabbitConnectionFactory);
    };

    @Bean
    Queue empRequestQueue() {
        System.out.println("inside request queue");
        return new Queue(requestQueueName, true);
    }

    @Bean
    Queue empCallBackQueue() {
        System.out.println("inside call back queue");
        return new Queue(requestQueueName + Constants.CALLBACKQUEUE, true);
    }

    @Bean
    DirectExchange empDirectExchange() {
        System.out.println("inside exchange");
        return new DirectExchange(directExchange);
    }

    @Bean
    Binding empRequestBinding() {
        System.out.println("inside request binding");
        return BindingBuilder.bind(empRequestQueue()).to(empDirectExchange()).with(requestRoutingKey);
    }

    @Bean
    Binding empCallBackBinding() {
        return BindingBuilder.bind(empCallBackQueue()).to(empDirectExchange()).with(requestRoutingKey + Constants.CALLBACKQUEUE);
    }

    @Bean
    public MessageConverter jsonMessageConverter(){
        System.out.println("inside json msg converter");
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public RabbitTemplate empFixedReplyQRabbitTemplate() {
        System.out.println("inside rabbit template");
        RabbitTemplate template = new RabbitTemplate(this.rabbitConnectionFactory);
        template.setExchange(empDirectExchange().getName());
        template.setRoutingKey(requestRoutingKey);
        template.setMessageConverter(jsonMessageConverter());
        template.setReceiveTimeout(100000);
        template.setReplyTimeout(100000);

        return template;
    }

    @Bean
    public SimpleMessageListenerContainer empReplyListenerContainer() {
        System.out.println("inside listener");
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        try{
            container.setConnectionFactory(this.rabbitConnectionFactory);
            container.setQueues(empCallBackQueue());
            container.setMessageListener(new EmployeeResponseReceiver());
            container.setMessageConverter(jsonMessageConverter());
            container.setConcurrentConsumers(10);
            container.setMaxConcurrentConsumers(20);
            container.start();
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            System.out.println("inside listener finally");
        }

        return container;
    }

    @Autowired
    @Qualifier("empReplyListenerContainer")
    private SimpleMessageListenerContainer empReplyListenerContainer;
}

EmployeeResponseReceiver.

package com.employee.service;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Component;

import com.employee.config.ApplicationContextProvider;
import com.employee.model.Employee;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;

@Component
@EnableAutoConfiguration
public class EmployeeResponseReceiver implements ChannelAwareMessageListener {

    ApplicationContextProvider applicationContextProvider = new ApplicationContextProvider();

    String msg = null;
    ObjectMapper mapper = new ObjectMapper();
    Employee employee = null;

    @Override
    public void onMessage(Message message, Channel arg1) throws Exception {
        try {
            msg = new String(message.getBody());
            System.out.println("Received Message : " + msg);

            employee = mapper.readValue(msg, Employee.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

问题是每当我启动我的应用程序,我会得到以下例外情况。

2018-03-17 14:18:36.695  INFO 12472 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-03-17 14:18:36.696  INFO 12472 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 5060 ms
2018-03-17 14:18:37.004  INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-03-17 14:18:37.010  INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-17 14:18:37.010  INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-17 14:18:37.011  INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-17 14:18:37.011  INFO 12472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
inside listener
inside call back queue
inside json msg converter
2018-03-17 14:18:37.576  INFO 12472 --- [cTaskExecutor-8] o.s.a.r.c.CachingConnectionFactory       : Created new connection: SimpleConnection@3d31af39 [delegate=amqp://guest@127.0.0.1:5672/foo, localPort= 50624]
2018-03-17 14:18:37.654  WARN 12472 --- [cTaskExecutor-7] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.655  WARN 12472 --- [cTaskExecutor-6] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.655  WARN 12472 --- [cTaskExecutor-5] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.655  WARN 12472 --- [cTaskExecutor-3] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.657  WARN 12472 --- [cTaskExecutor-1] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.658  WARN 12472 --- [cTaskExecutor-8] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.661  WARN 12472 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.660  WARN 12472 --- [cTaskExecutor-4] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.661  WARN 12472 --- [cTaskExecutor-9] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.666  WARN 12472 --- [TaskExecutor-10] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:18:37.667  WARN 12472 --- [cTaskExecutor-2] o.s.a.r.listener.BlockingQueueConsumer   : Queue declaration failed; retries left=3

org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[EMP_QUEUE1_CBQ]
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:636) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:535) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389) [spring-rabbit-1.7.2.RELEASE.jar:na]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]
Caused by: java.io.IOException: null
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50) ~[amqp-client-4.0.2.jar:4.0.2]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:955) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at com.sun.proxy.$Proxy58.queueDeclarePassive(Unknown Source) ~[na:na]
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:615) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    ... 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 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117) ~[amqp-client-4.0.2.jar:4.0.2]
    ... 12 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 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)
    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572) ~[amqp-client-4.0.2.jar:4.0.2]
    ... 1 common frames omitted

2018-03-17 14:08:36.689  WARN 11076 --- [cTaskExecutor-4] o.s.a.r.listener.BlockingQueueConsumer   : Failed to declare queue:EMP_QUEUE1_CBQ
2018-03-17 14:08:36.695 ERROR 11076 --- [cTaskExecutor-4] o.s.a.r.l.SimpleMessageListenerContainer : Consumer received fatal exception on startup

org.springframework.amqp.rabbit.listener.QueuesNotAvailableException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:563) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]
Caused by: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):[EMP_QUEUE1_CBQ]
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:636) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:535) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    ... 2 common frames omitted
Caused by: java.io.IOException: null
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:105) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:101) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:123) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:992) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:50) ~[amqp-client-4.0.2.jar:4.0.2]
    at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_151]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_151]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:955) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    at com.sun.proxy.$Proxy58.queueDeclarePassive(Unknown Source) ~[na:na]
    at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:615) ~[spring-rabbit-1.7.2.RELEASE.jar:na]
    ... 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 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:32) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:229) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:117) ~[amqp-client-4.0.2.jar:4.0.2]
    ... 11 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 'EMP_QUEUE1_CBQ' in vhost 'foo', class-id=50, method-id=10)
    at com.rabbitmq.client.impl.ChannelN.asyncShutdown(ChannelN.java:505) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.ChannelN.processAsync(ChannelN.java:336) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:143) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:90) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQConnection.readFrame(AMQConnection.java:634) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQConnection.access$300(AMQConnection.java:47) ~[amqp-client-4.0.2.jar:4.0.2]
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:572) ~[amqp-client-4.0.2.jar:4.0.2]
    ... 1 common frames omitted

2018-03-17 14:08:36.697  INFO 11076 --- [TaskExecutor-10] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2018-03-17 14:08:36.699  INFO 11076 --- [cTaskExecutor-5] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2018-03-17 14:08:36.700  INFO 11076 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2018-03-17 14:08:36.701  INFO 11076 --- [cTaskExecutor-3] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2018-03-17 14:08:36.700  INFO 11076 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2018-03-17 14:08:36.702  INFO 11076 --- [cTaskExecutor-7] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2018-03-17 14:08:36.765 ERROR 11076 --- [cTaskExecutor-8] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer
2018-03-17 14:08:36.766 ERROR 11076 --- [cTaskExecutor-6] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer
2018-03-17 14:08:36.779 ERROR 11076 --- [cTaskExecutor-9] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer
2018-03-17 14:08:36.791 ERROR 11076 --- [cTaskExecutor-4] o.s.a.r.l.SimpleMessageListenerContainer : Stopping container from aborted consumer
inside app ctx provider
inside rabbit admin
inside exchange
inside request queue
inside request binding
inside rabbit template
2018-03-17 14:08:38.978  INFO 11076 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@33b37288: startup date [Sat Mar 17 14:08:16 IST 2018]; root of context hierarchy
2018-03-17 14:08:39.395  INFO 11076 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-03-17 14:08:39.398  INFO 11076 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-03-17 14:08:39.663  INFO 11076 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-17 14:08:39.663  INFO 11076 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-17 14:08:39.826  INFO 11076 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-17 14:08:40.648  INFO 11076 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-03-17 14:08:40.677  INFO 11076 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
2018-03-17 14:08:40.685  INFO 11076 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]
2018-03-17 14:08:40.746  INFO 11076 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase -2147482648
2018-03-17 14:08:40.747  INFO 11076 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2018-03-17 14:08:41.258  INFO 11076 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-03-17 14:08:41.270  INFO 11076 --- [           main] com.employee.MainClass                   : Started MainClass in 26.141 seconds (JVM running for 28.02)

有谁能帮我解决我的问题吗?根据我的理解,当创建SimpleMessageListenerContainer的对象时,回调队列不会在rabbitmq服务器上创建。我尝试使用RabbitAdmin对象声明队列,但随后执行停止,没有任何进展。当我在默认虚拟主机中声明队列时,这个问题并不存在。但当我添加虚拟主机foo时,所有的东西都突然停止了。您可以使用上面的代码复制此问题。我已经粘贴了我所有的代码。如果有其他需要张贴的内容,请告诉我。

有趣的是,即使我得到了这些异常,我的应用程序也已经启动并运行。这意味着创建了我的回调队列,并且SimpleMessageListenerContainer的对象获得了该队列。我在某处读到,当创建队列时,我的SimpleMessageListenerContainer对象将监听它。

请帮我解决这个问题。

共有1个答案

狄阳华
2023-03-14

当我在默认虚拟主机中声明队列时,这个问题并不存在。但当我添加虚拟主机foo时,所有的东西都突然停止了。

访问新虚拟主机的用户是否具有configure权限?声明队列需要配置权限。

需要RabbitAdmin来声明队列/绑定;容器只执行被动声明以检查队列是否存在。

container.start();

从日志中可以清楚地看出,容器启动得太早了--在其他bean(admin、queue等)声明之前。

 类似资料:
  • 我收到了一个关于这个问题的建议,一个评论,说我可能没有我需要的交换,因为我的队列已经存在。于是,我就全部手动删除了。 但是,在重新部署应用程序时,我发现所有队列都有以下异常: 我不确定这意味着什么,因为我显然想要创建队列<code>myInput。组,它似乎在抱怨它不存在。。。 我也检查了这个问题,我的问题可能是权限。但我应该有它们——否则我相信我无法删除队列...... 你能给我一个解决方案吗?

  • 我试图让队列在laravel 5中工作,队列侦听器正在输出: 未定义索引:表 存在"作业"和"failed_jobs"表,config.php设置为"数据库"。 搜索laravel论坛和google都没有找到解决办法,艾米的想法去哪里找?

  • 我当前将我的rabbit listener注释设置为: @RabbitListener(queues=“my queue”) 是否无法从我的yaml文件中提取队列名称。我想这样做的原因是,我可以将队列更改为集成测试的测试队列,只需更改yaml文件中的队列名称即可。看来注释必须接受常量字符串,有什么办法吗?谢谢

  • null 结果:队列已从RabbitMQ GUI中删除,但当我试图通过已删除的RabbitMQ队列发送消息时,连接仍然有效。(con.isConnected()==true)我需要找到一种方法来侦听队列,如果它被删除,我不应该向已删除的队列发送任何消息。 注意:删除队列后,我不会重新启动RabbitMQ。 渠道创建: 正在发送消息:

  • 在my provider:block中,我将一个VPC声明为VPC: 我怎样才能在我的资源块中获得这个专有网络的id/ARN/什么的?我有一个AWS云信息资源,我想把我的VPC id作为VpcId传递。有什么${self:}东西可以获取id吗? 我尝试了Ref: vpc,但那不起作用。