I am following this example which is supposed to send a scheduled message to a JMS queue in ActiveMQ Artemis. I am connecting to a Docker ActiveMQ Artemis version 2.32.0 using:
ConnectionFactory cf = new JmsConnectionFactory("amqp://localhost:5672?jms.username=artemis&jms.password=artemis");
But the messages is sent immediately as shown below.
Sent message: This is a scheduled message message which will be delivered in 5 sec.
Time of send: Thu, 8 Feb 2024 13:45:21
Received message: This is a scheduled message message which will be delivered in 5 sec.
Time of receive: Thu, 8 Feb 2024 13:45:21
What I am missing?
The problem is that the example you're following is using the core protocol. However, your code is using the AMQP protocol instead.
Typically with AMQP if you want to send a scheduled message to ActiveMQ Artemis you'd use one of the following message annotations as noted in the documentation:
x-opt-delivery-time
: The specified value must be a positive long corresponding to the time the message should be made available for delivery (in milliseconds).x-opt-delivery-delay
: The specified value must be a positive long corresponding to the amount of milliseconds after the broker receives the given message before it should be made available for delivery.However, since your using Qpid JMS which supports JMS 2 you can use the setDeliveryDelay
method on your MessageProducer
. There's no need to set a provider-specific property.
You could, of course, also switch to the core protocol just like the example does.