【问题标题】:Message getting expired in ActiveMQ ArtemisActiveMQ Artemis 中的消息过期
【发布时间】:2021-02-25 12:38:23
【问题描述】:

我使用 Eclipse 微配置文件发射器在 Quarkus 应用程序中创建了一个 ActiveMQ Artemis 生产者。但是消息会立即过期,并被移至ExpiryQueue。我不确定这种行为。请建议我如何将消息持久化到队列中,使其仅在指定时间后过期。

我正在使用下面的代码。

        @Inject
        @Channel("my-queue")
        Emitter<String> emitter;

在元数据下创建:

        String message = "my-message";
        OutgoingAmqpMetadata metadata = OutgoingAmqpMetadata.builder()
                    .withExpiryTime(10000L)
                    .withDurable(true)
                    .withMessageId(String.valueOf(message.hashCode()))
                    .build();
       
        emitter.send(Message.of(message, Metadata.of(metadata)));

我正在使用smallrye-amqp 连接器。在application.properties 中添加了以下属性:

mp.messaging.outgoing.my-queue.connector=smallrye-amqp

【问题讨论】:

  • 感谢您的回复!根据您的建议,我能够将消息保留到队列中。
  • 另外,我观察到如果我重新启动 artemis 代理,消息会丢失。我通过使用 Ttl(600000) 设置 TTL 来解决此问题。

标签: quarkus activemq-artemis microprofile smallrye


【解决方案1】:

我相信您在 withExpiryTime 中设置了错误的值。您将其设置为 TTL,但我相信这是一个绝对时间,因此您应该这样设置:

OutgoingAmqpMetadata metadata = OutgoingAmqpMetadata.builder()
            .withExpiryTime(System.currentTimeMillis() + 10000L)
            .withDurable(true)
            .withMessageId(String.valueOf(message.hashCode()))
            .build();

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多