2014-12-11 07:17:29 -05:00
|
|
|
# Scheduled Messages
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
Scheduled messages differ from normal messages in that they won't be
|
|
|
|
delivered until a specified time in the future, at the earliest.
|
|
|
|
|
|
|
|
To do this, a special property is set on the message before sending it.
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
## Scheduled Delivery Property
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
The property name used to identify a scheduled message is
|
2015-04-14 12:07:26 -04:00
|
|
|
`"_AMQ_SCHED_DELIVERY"` (or the constant
|
2014-12-04 10:25:29 -05:00
|
|
|
`Message.HDR_SCHEDULED_DELIVERY_TIME`).
|
|
|
|
|
|
|
|
The specified value must be a positive `long` corresponding to the time
|
|
|
|
the message must be delivered (in milliseconds). An example of sending a
|
|
|
|
scheduled message using the JMS API is as follows.
|
|
|
|
|
2018-03-08 15:46:38 -05:00
|
|
|
```java
|
2014-12-11 07:17:29 -05:00
|
|
|
TextMessage message = session.createTextMessage("This is a scheduled message message which will be delivered in 5 sec.");
|
2015-04-14 12:07:26 -04:00
|
|
|
message.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + 5000);
|
2014-12-11 07:17:29 -05:00
|
|
|
producer.send(message);
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
...
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
// message will not be received immediately but 5 seconds later
|
|
|
|
TextMessage messageReceived = (TextMessage) consumer.receive();
|
|
|
|
```
|
2014-12-04 10:25:29 -05:00
|
|
|
Scheduled messages can also be sent using the core API, by setting the
|
|
|
|
same property on the core message before sending.
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
## Example
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
See the [Scheduled Message Example](examples.md#scheduled-message) which shows how scheduled messages can be used with
|
2014-12-04 10:25:29 -05:00
|
|
|
JMS.
|