Search code examples
javajmsmessagingamqpqpid

Apache Qpid - Set routing key at message level


Is there any option to set a routing key at message level in Apache Qpid. The way I currently do is

  1. Specify routing key in address string. Create a producer with this destination address.

    topic = (Topic) context.lookup("destination"); sender = session.createProducer(topic);

  2. Send messages through the producer.

This way all the messages have the same routing key. What I want to achieve is set a routing key for each message individually.

Let me know if this can be done


Solution

  • This can be easily done by specifying a per message subject. The "subject" as defined by the Qpid address scheme, would map to the routing key for Topics when using the 0-10 protocol.

    Message m = ssn.createMessage();
    m.setStringProperty("qpid.subject", "my-subject");
    prod.send(m);
    

    This allows you to use standard JMS interfacing while still using the Qpid add-ons.