Spring JMS 和 ActiveMQ 在哪里查看死信队列中的消息

Posted

技术标签:

【中文标题】Spring JMS 和 ActiveMQ 在哪里查看死信队列中的消息【英文标题】:Spring JMS and ActiveMQ where to see messages in dead letter queue 【发布时间】:2018-07-04 23:57:52 【问题描述】:

这是我的配置:

@Bean
ActiveMQConnectionFactory activeMQConnectionFactory() 
    String url = this.environment.getProperty("jms.broker.url");
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL(url);
    connectionFactory.setRedeliveryPolicy(redeliveryPolicy());
    return connectionFactory;


@Bean
public RedeliveryPolicy redeliveryPolicy() 
    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.setInitialRedeliveryDelay(500);
    redeliveryPolicy.setBackOffMultiplier(2);
    redeliveryPolicy.setUseExponentialBackOff(true);
    redeliveryPolicy.setMaximumRedeliveries(5);
    return redeliveryPolicy;

.....

这是我的消费者:

@Service("msgConsumer")
public class MessageConsumer 

    private static final String ORDER_RESPONSE_QUEUE = "thequeue.Q";

    @JmsListener(destination = ORDER_RESPONSE_QUEUE, containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(final Message<String> message) throws Exception 

        MessageHeaders headers =  message.getHeaders();
        LOG.info("Application : headers received : ", headers);

        String response = message.getPayload();
        LOG.info("Application : response received : ",response);

        if(response.equals("launch"))
            throw new Exception("Error");
    

所以我将一条消息放入队列,payload = "launch"。

我想测试事务,如果有效负载等于“启动”,它会抛出异常。

因此,感谢重新传递策略,消费者尝试消费该消息 5 次。 在 ActiveMq 队列列表中的第五个之后,我没有看到我发送的消息。

消息放在哪里?在死信队列中? 在哪里可以看到带有“启动”消息的死信队列?

谢谢。

【问题讨论】:

【参考方案1】:

ActiveMQ.DLQ - 见the documentation here。

一旦消息的重新传递尝试超过为重新传递策略配置的最大重新传递次数,就会向代理发送回“毒 ACK”,让他知道该消息被视为毒丸。然后,Broker 接收消息并将其发送到死信队列,以便稍后对其进行分析。

ActiveMQ 中默认的死信队列名为 ActiveMQ.DLQ;所有无法投递的消息都将发送到此队列,这可能很难管理。因此,您可以在 activemq.xml 配置文件的目标策略映射中设置 individualDeadLetterStrategy,它允许您为给定队列或主题指定特定的死信队列前缀。如果您愿意,可以使用通配符应用此策略,以便所有队列都有自己的死信队列,如下例所示。

可以在控制台看到DLQ;你可以像其他队列一样消费它。

【讨论】:

如果我有一个名为“myqueue.Q”的队列,DLQ 的正确名称是什么? 阅读我指向您的文档ActiveMQ.DLQ。默认情况下,所有内容都转到同一个 DLQ。 &gt;So, you can set an individualDeadLetterStrategy in the destination policy map of the activemq.xml configuration file, which allows you to specify a specific dead letter queue prefix for a given queue or topic. 愚蠢的问题:activemq.xml中的DLQ配置是在服务器中进行的,而不是在客户端中进行的,对吗?

以上是关于Spring JMS 和 ActiveMQ 在哪里查看死信队列中的消息的主要内容,如果未能解决你的问题,请参考以下文章

深入浅出JMS--Spring和ActiveMQ整合的完整实例

深入浅出JMS--Spring和ActiveMQ整合的完整实例

深入浅出JMS--Spring和ActiveMQ整合的完整实例

深入浅出JMS--Spring和ActiveMQ整合的完整实例

Spring整合JMS——基于ActiveMQ实现

如何构建 Spring Cloud Stream JMS ActiveMQ