【问题标题】:Artemis: How to stop consuming messages on error?Artemis:如何停止消费错误消息?
【发布时间】:2017-12-13 14:19:06
【问题描述】:

如何配置 ActiveMQ Artemis 或我的 Spring JMS 客户端在出错时不使用任何其他消息?

我的代理配置如下:

<addresses>
    <address name="SimplePointToPoint">
        <anycast>
            <queue name="SimplePointToPoint"/>
        </anycast>
    </address>
</addresses>
<address-settings>
    <address-setting match="SimplePointToPoint">
        <max-delivery-attempts>-1</max-delivery-attempts>
    </address-setting>
</address-settings>

这是我的消费者的代码:

@JmsListener(destination = "SimplePointToPoint")
public void consumeMessage(Message<String> message) {
    if (message.getPayload().contains("error"))
        throw new RuntimeException();

    log.info("received message: {}", message.getPayload());
}

发送message1message2 with errormessage3 时,我希望消费者处理message1 并永远重试message2 with error。在成功使用 message2 with error 之前,不应处理 message3。实际发生的是message3 在重试之间被消耗。如何改变这种行为?有什么想法吗?

【问题讨论】:

    标签: spring spring-jms activemq-artemis


    【解决方案1】:

    ActiveMQ 预取默认为 1000。

    the documentation

    您可以在 ActiveMQConnectionFactory 或 ActiveMQConnection 上指定 ActiveMQPrefetchPolicy 的实例。这允许您配置所有单独的预取值;因为每一种不同的服务质量都有不同的价值。例如

    持久队列(默认值:1000)

    ...

    【讨论】:

    • 您的回答适用于 Apache ActiveMQ 5.x,但问题是关于 Apache ActiveMQ Artemis 代理。
    猜你喜欢
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    相关资源
    最近更新 更多