This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Setting the Routing Key for Messages

The Dead Letter Channel (DLC) is a sub-set of a queue, which is used for storing messages that have not been delivered to the intended subscriber. The DLC provides you the option of deleting these messages, retrieving them or rerouting them to another queue. In the case of rerouting the message to a different queue, the message will be received by the clients subscribed to this second queue. Therefore, since the subscribers of the second queue are not expecting to receive messages from another queue, it will be necessary for such subscriber clients to identify the destination (subscriber) to which the message was originally sent. 

To achieve this, we are using a custom JMS property that embeds the routing key to the message. We are embedding the routing key to a JMS property of the message from the andes-client side. The embedding is enabled only when the “AndesSetRoutingKey” system property is set to a non-null value (any value other than null) in the publisher client. When the mentioned system property is set, each message will have a JMS property of type "string" with the “JMS_ANDES_ROUTING_KEY” name, which will contain the routing key.

Configuring the publisher client

The custom JMS property should be enabled for the publisher client as shown below.

System.setProperty("AndesSetRoutingKey", "1");

Configuring the subscriber client

The subscriber client can retrieve the JMS property in the message as shown below.

System.out.println("PROP:" + message.getStringProperty("JMS_ANDES_ROUTING_KEY"));