Search code examples
quarkusactivemq-artemismicroprofilesmallrye

Message getting expired in ActiveMQ Artemis


I have created an ActiveMQ Artemis producer in Quarkus application using Eclipse microprofile emitter. But the messages are getting expired instantly, and being moved into ExpiryQueue. I am not sure about this behavior. Please suggest how could I persist message into the queue so that it expires only after specified time.

I am using below code.

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

Created below metedata:

        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)));

I am using smallrye-amqp connector. Added below property in application.properties:

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

Solution

  • I believe you're setting the wrong value in withExpiryTime. You're setting it like a TTL, but I believe it's an absolute time so you should so something like this:

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