Developing retained message applications
The publisher of a message can specify that a copy of the message must be kept on Eclipse Amlen as a retained message. This retained message is sent to any subscribers that subscribe after the message was published. Eclipse Amlen supports both MQTT and JMS retained messages.
Only one message is retained for each topic, so existing retained messages are deleted when a new retained message is published to the topic. The deletion of the existing message might not occur synchronously with the arrival of the new retained message. In the case where more than one publisher publishes retained messages to a single topic, it is not possible to know which message is stored. It is possible that an earlier message sent by one publisher is stored as the retained message, rather than a later message sent by another publisher. Therefore, where possible, have no more than one publisher sending retained messages to a topic.
Messages are not retained after Eclipse Amlen is restarted if the retained messages are not sent as persistent messages. Consider sending retained messages as persistent messages so that the messages continue to be available to new subscribers even if Eclipse Amlen is restarted. For more information about persistent messages, see Message delivery.
- For non-durable subscriptions, if a client disconnects and reconnects to a topic, reconnecting creates a new subscription. Therefore, the retained message on the topic that is subscribed to is sent to the client, even if the client received the message before it disconnected.
- For durable subscriptions, if a client disconnects and reconnects, reconnecting uses the same durable subscription. Messages that were published after the client disconnected are delivered as normal, not as retained messages. The only instance in which an application with a durable subscription receives retained messages is when the subscription is first created. If the application disconnects before it receives the initial retained messages, the messages are delivered as retained messages when the application reconnects.
cleanSession=0
flag.MQTT retained messages
MQTT applications
can be configured to use retained messages by setting the RETAIN
flag.
When a subscriber receives a message with the RETAIN
flag
set, it indicates that the message is not being delivered at the time
of publication. Retained messages that are delivered at the time of
publication are delivered without the RETAIN
flag
set.
With Eclipse Amlen, you can clear an MQTT retained message from a topic by sending a retained message with a zero length payload. The message is delivered normally, and the current retained message is cleared.
JMS retained messages
JMS applications that
are developed for Eclipse Amlen can
be configured to use retained messages by setting the integer property JMS_IBM_Retain
to
the value 1
. When a subscriber receives a message
with the JMS_IBM_Retain
property set to the value 1
,
it indicates that the message was published and marked as retained
before the subscription was made. Retained messages that are delivered
at the time of publication are delivered with the value set to 0
.
If retained messages are published to a queue, the retained flag is ignored. Retained messages cannot be cleared. Publishing a zero-length, empty, or null JMS message does not clear a retained message. However, as the mechanism for retained messages is the same for JMS and MQTT, you can send a zero-length MQTT retained message to delete the JMS retained message.
If a JMS retained message is sent with a message expiry, the retained message is deleted after the expiration time.
If
a JMS subscription uses the noLocal=True
setting,
any retained messages that were previously published by the same connection
are delivered to the subscriber. Only messages that are delivered
at the time of publication are filtered out by the noLocal=True
setting.