o.s.amqp.rabbit.core.RabbitTemplate.onMessage-超时后收到回复

时间:2020-09-28 12:57:49

标签: java spring

我的代码如下:

@Configuration
public class RabbitMqCommonsConfig
{
    @Value(AmqpConstants.EXCHANGE)
    private String exchangeName;

    @Bean
    DirectExchange exchange()
    {
        return new DirectExchange(exchangeName);
    }

    @Bean
    public MessageConverter jsonMessageConverter()
    {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public SimpleRabbitListenerContainerFactory jsaFactory(ConnectionFactory connectionFactory,
        SimpleRabbitListenerContainerFactoryConfigurer configurer)
    {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        configurer.configure(factory, connectionFactory);
        factory.setMessageConverter(jsonMessageConverter());

        return factory;
    }

    @Bean
    public MessageProducer messageProducer(AmqpTemplate amqpTemplate)
    {
        return new MessageProducer(amqpTemplate);
    }
} 

MessageProducer类:

@Component
public class MessageProducer
{
    private static final Logger logger = LoggerFactory.getLogger(MessageProducer.class);
    private AmqpTemplate amqpTemplate;

    @Autowired
    public MessageProducer(AmqpTemplate amqpTemplate)
    {
        this.amqpTemplate = amqpTemplate;
    }

    public void convertAndSend(String exchangeName, String routingKey, Object message)
    {
        if (message == null)
        {
            logger.warn("Parameter 'message' was null. Omitting sending of message.");
            return;
        }

        this.amqpTemplate.convertAndSend(exchangeName, routingKey, message);
        logger.debug("Sent message to exchange '{}' with routingKey '{}': '{}'", exchangeName, routingKey, message);
    }

    public <T> T convertSendAndReceive(String exchangeName, String routingKey, Object message)
    {
        if (message == null)
        {
            logger.warn("Parameter 'message' was null. Omitting sending of message to exchange '{}' with routingKey '{}'.",
                exchangeName, routingKey);
            return null;
        }

        T result = (T) amqpTemplate.convertSendAndReceive(exchangeName, routingKey, message);

        if (result != null)
        {
            logger.debug("Sent and received message to exchange '{}' with routingKey '{}'. Sent: '{}' - Received: '{}'",
                exchangeName, routingKey, message, result);
        }
        else
        {
            throw new CommunicationException(
                String.format("Response from message bus was 'null' (eventually due to timeout). " +
                              "Exchange Name: '%s' - Routing Key: '%s' - Message: '%s'", exchangeName,
                    routingKey, message));
        }

        return result;
    }
}

错误日志: 28-09-2020 12:33:33.565调试[pool-2-thread-3] o.s.a.r.l.DirectReplyToMessageListenerContainer.handleCancelOk-CancelOk SimpleConsumer [queue = amq.rabbitmq.reply-to,ConsumerTag = amq.ctag-RYvNmU5l01A6UpwvX6SkaQ62 28-09-2020 12:33:33.565调试[rabbitTemplate#0-consumerMonitor-1] o.s.a.r.l.DirectReplyToMessageListenerContainer.cancelConsumer-取消SimpleConsumer [queue = amq.rabbitmq.reply-to,consumerTag = amq.ctag-quugELvPcPh3a7B1 28-09-2020 12:33:33.567警告[pool-2-thread-9] o.s.amqp.rabbit.core.RabbitTemplate.onMessage-552超时后收到回复 28-09-2020 12:33:33.567警告[pool-2-thread-9] o.s.a.r.l.ConditionalRejectingErrorHandler.handleError-Rabbit消息侦听器的执行失败。 org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException:侦听器引发异常 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1506)处 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1417)处 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1337) 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1324) 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1303)处 在org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer $ SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:860)处 在org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer $ SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:849)处 在com.rabbitmq.client.impl.ConsumerDispatcher $ 5.run(ConsumerDispatcher.java:149) 在com.rabbitmq.client.impl.ConsumerWorkService $ WorkPoolRunnable.run(ConsumerWorkService.java:100) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在java.lang.Thread.run(Thread.java:748) 引起原因:org.springframework.amqp.AmqpRejectAndDontRequeueException:超时后收到回复 在org.springframework.amqp.rabbit.core.RabbitTemplate.onMessage(RabbitTemplate.java:2218) 在org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.lambda $ setMessageListener $ 1(DirectReplyToMessageListenerContainer.java:106) 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1414)处 ...省略了10个通用框架 28-09-2020 12:33:33.568错误[pool-2-thread-9] o.s.a.r.l.DirectReplyToMessageListenerContainer.callExecuteListener-无法调用侦听器 org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException:侦听器引发异常 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1506)处 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1417)处 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1337) 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1324) 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1303)处 在org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer $ SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:860)处 在org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer $ SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:849)处 在com.rabbitmq.client.impl.ConsumerDispatcher $ 5.run(ConsumerDispatcher.java:149) 在com.rabbitmq.client.impl.ConsumerWorkService $ WorkPoolRunnable.run(ConsumerWorkService.java:100) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在java.lang.Thread.run(Thread.java:748) 引起原因:org.springframework.amqp.AmqpRejectAndDontRequeueException:超时后收到回复 在org.springframework.amqp.rabbit.core.RabbitTemplate.onMessage(RabbitTemplate.java:2218) 在org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.lambda $ setMessageListener $ 1(DirectReplyToMessageListenerContainer.java:106) 在org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1414)处 ...省略了10个常见框架

在开发环境中,我没有任何错误,在生产环境中,我遇到了以上错误。

任何人都可以答复在生产环境中为什么会发生此问题的原因。 预先感谢。

0 个答案:

没有答案