Setting Message Properties
The following sections discuss some important message properties that can be set for messages to be published. These properties can affect how messages are routed.
To ensure that stale messages are not consumed, you can set a Time‑To-Live (TTL) value (in milliseconds) for each Guaranteed message published by a producer. The TTL value is ignored for non‑durable endpoints when using Direct Transport.
If destination queues or topic endpoints are configured to respect message TTLs, when received messages’ TTLs have passed, they are either discarded by the endpoint, or, if the messages are eligible for a Dead Message Queue (DMQ), they are moved to a DMQ provisioned on the event broker.
respect-ttl property value set at the
connectionFactory level can be overridden through the
InitialContext environment using
You can set a TTL value for messages in the following ways:
MessageProducer.setTimeToLive(long timeToLive)to set a default TTL value for all messages to be published by the
MessageProducer.(A value of 0 means that the messages never expire.)
- After acquiring a
MessageProducer, a TTL value can be passed in when you call either one of the following methods to publish the message:
send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)or
send(Message message, int deliveryMode, int priority, long timeToLive)
The TTL value set through these methods overrides any set at the
Moving messages to a DMQ
If you want to move messages with expired TTL values to a provisioned DMQ, the endpoints must be configured to respect the messages’ TTL values:
- If you are using SolAdmin to provision endpoints, you must enable the Respect TTL check box and create a new queue or subscription name (that is, endpoint).
- If you want to dynamically create endpoints, the
connectionFactoryused should also be configured to respect TTLs. Therefore, when using SolAdmin to create a
connectionFactory, enable the
Respect TTLcheck box. When using the CLI to create the
true. For more information, refer to Solace JNDI Objects.
Guaranteed messages that have exceeded their TTL, or maximum number of redelivery attempts, can be moved from a durable Queue or a Topic Endpoint to a DMQ, instead of being discarded if those messages are flagged as being DMQ-eligible. A DMQ is just a durable queue that has been assigned to serve as the DMQ for another durable endpoint. For more information, refer to Configuring Dead Message Queues.
You can dynamically create a queue with the name
#DEAD_MSG_QUEUE through the JMS API (refer to Creating Queues), or provision one through CLI or SolAdmin.
You can flag published messages as DMQ eligible on a per-message basis, or you can enable message eligibility for DMQs on a Connection Factory basis so that all messages published by Producers using that Connection Factory are DMQ-eligible.
- To flag individual messages
- To flag messages at the Connection Factory level
SOLACE_JMS_PROP_DEAD_MSG_QUEUE_ELIGIBLE property to
true for each message.
Use SolAdmin or the CLI to enable the
For more information on this message property, refer to Dead Message Queue Eligible.
The message eliding capabilities of Solace PubSub+ enables client applications to only receive the most current messages published to topics that they subscribe to, at a rate that they can manage. Using message eliding can be useful in situations where a slower message rate is required or where there are slow consumers.
To use message eliding, the following steps are required:
- A consuming client application must be assigned a client profile through its client username that permits it to use message eliding. The client profile also sets a rate to control the delay interval at which a new eliding-eligible message elides a previous version that is queued for delivery to the client.
- Published messages must be flagged as eligible for message eliding.
- You can flag published messages as eligible for message eliding on a per‑message basis, or you can enable message eliding eligibility on a Connection Factory basis so that all messages published by Producers using that Connection Factory are eliding-eligible.
- To flag individual messages, set the
truefor each message.
- To flag messages at the Connection Factory level, use SolAdmin or the CLI to enable the
- To flag individual messages, set the
For more information on this message property, refer to Eliding Eligible.
You can set a partition key in your message to take advantage of partitioned queues. Partitioned queues allow you to easily scale the number of consumer applications in your event mesh, while maintaining the message sequence for all published messages with the same partition key. PubSub+ event brokers ensure that all related events are delivered to the same consumer in the correct sequence and also re-balance the event stream when you add or remove consumers. For more information see Partitioned Queues.
To set the partition key, use the
setStringProperty(name,value) method to set a name-value pair on a JMS API message.
SupportedProperty.JMSX_GROUP_IDor the string value
value—A string representing the value of your partition key. Client applications set the value at publish time.
The following example sets the partition key
Message message = message.setStringProperty("JMSXGroupID", "Group-0"); // Or: Message message.setStringProperty(SupportedProperty.JMSX_GROUP_ID, "Group-0");