SimpleMessageListenerContainer:消费者引发异常,如果处理支持,处理可以重新启动

时间:2016-10-19 11:04:49

标签: rabbitmq spring-integration spring-amqp spring-rabbit

我有一个Spring Boot应用程序与rabbitmq代理连接,后者设法启动正常,但无论队列中是否有消息,我都会获得消息使用者的持续启动/关闭。下面是我的应用程序日志和客户端类的副本:

  

2016-10-19 11:40:25,909警告:[SimpleAsyncTaskExecutor-106] SimpleMessageListenerContainer:消费者引发异常,如果连接工厂支持它,处理可以重启   java.lang.NullPointerException:null       在com.rabbitmq.client.impl.ChannelN.validateQueueNameLength(ChannelN.java:1232)〜[amqp-client-3.5.5.jar:na]       在com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:884)〜[amqp-client-3.5.5.jar:na]       在com.rabbitmq.client.impl.ChannelN.queueDeclarePassive(ChannelN.java:61)〜[amqp-client-3.5.5.jar:na]       at sun.reflect.GeneratedMethodAccessor334.invoke(Unknown Source)〜[na:na]       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_51]       在java.lang.reflect.Method.invoke(Method.java:497)〜[na:1.8.0_51]       在org.springframework.amqp.rabbit.connection.CachingConnectionFactory $ CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:666)〜[spring-rabbit-1.4.6.RELEASE.jar:na]       在com.sun.proxy。$ Proxy181.queueDeclarePassive(未知来源)〜[na:na]       在org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.attemptPassiveDeclarations(BlockingQueueConsumer.java:533)〜[spring-rabbit-1.4.6.RELEASE.jar:na]       在org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:453)〜[spring-rabbit-1.4.6.RELEASE.jar:na]       在org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer $ AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1083)〜[spring-rabbit-1.4.6.RELEASE.jar:na]       在java.lang.Thread.run(Thread.java:745)[na:1.8.0_51]   2016-10-19 11:40:25,909 INFO t:[SimpleAsyncTaskExecutor-106] SimpleMessageListenerContainer:Restarting Consumer:tags = [{}],channel = Cached Rabbit Channel:AMQChannel(amqp://guest@127.0.0.1:5672 / ,1),acknowledgeMode = AUTO本地队列大小= 0   2016-10-19 11:40:25,910 DEBUG t:[SimpleAsyncTaskExecutor-106] BlockingQueueConsumer:Closing Rabbit Channel:Cached Rabbit Channel:AMQChannel(amqp://guest@127.0.0.1:5672 /,1)   2016-10-19 11:40:25,910 DEBUG t:[SimpleAsyncTaskExecutor-106] CachingConnectionFactory:关闭缓存的频道:AMQChannel(amqp://guest@127.0.0.1:5672 /,1)   2016-10-19 11:40:25,911 DEBUG t:[SimpleAsyncTaskExecutor-107] DefaultListableBeanFactory:返回单例bean的缓存实例' macRequestQueue'   2016-10-19 11:40:25,911 DEBUG t:[SimpleAsyncTaskExecutor-107] BlockingQueueConsumer:启动消费者消费者:tags = [{}],channel = null,acknowledgeMode = AUTO本地队列大小= 0   2016-10-19 11:40:25,912 DEBUG t:[SimpleAsyncTaskExecutor-107] CachingConnectionFactory:从AMQChannel创建缓存的Rabbit Channel(amqp://guest@127.0.0.1:5672 /,1)   2016-10-19 11:40:25,912 DEBUG t:[SimpleAsyncTaskExecutor-107] SimpleMessageListenerContainer:在5000毫秒内恢复消费者。

以下是我的客户类的副本:

public class RabbitClientConfiguration extends AbstractEMCRabbitConfiguration     {

@Inject
private JacksonConfiguration jacksonConfiguration;

@Inject
private MessagingConfiguration messagingConfiguration;

//@Value("${data.core.pattern}")
//private String coreDataRoutingKey;

//@Inject
//private ClientHandler clientHandler;

@Override
public void configureRabbitTemplate(RabbitTemplate rabbitTemplate) {
    rabbitTemplate.setRoutingKey(MAC_REQUEST_ROUTING_KEY);
}

@Bean
public SimpleMessageListenerContainer messageListenerContainer(){
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory());
    container.setQueueNames(MAC_REQUEST_QUEUE_NAME);
    container.setMessageListener(messageListenerAdapter());
    container.setAcknowledgeMode(AcknowledgeMode.AUTO);
    return container;
}

@Bean
MessageListenerAdapter messageListenerAdapter(){
    return new MessageListenerAdapter(clientHandler(jacksonConfiguration.objectMapper(),messagingConfiguration.macMessageHandler(messagingConfiguration.messagingFactory())),jsonMessageConverter());
    //return new MessageListenerAdapter(clientHandler,"receiveMessage");
}

@Bean
ClientHandler clientHandler(ObjectMapper objectMapper, IMessageHandler macMessageHandler){
    ClientHandler clientHandler = new ClientHandler();
    clientHandler.setObjectMapper(objectMapper);
    clientHandler.setMacMessageHandler(macMessageHandler);
    return clientHandler;
}


@Bean
public AmqpAdmin rabbitAdmin() { return new RabbitAdmin(connectionFactory());}

}

1 个答案:

答案 0 :(得分:0)

  

java.lang.NullPointerException:null at com.rabbitmq.client.impl.ChannelN.validateQueueNameLength

这意味着MAC_REQUEST_QUEUE_NAME包含null - 看起来容器在您调用setter时不会检查它。

我打开JIRA Issue来检测这种情况。