qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brant Boehmann <brant.boehm...@gmail.com>
Subject getJMSDestimation
Date Tue, 15 Dec 2009 13:23:04 GMT
I'm trying to utilize the qpid java client using only JMS classes (not AMQP
or QPID classes). However the Message.getJMSDestination() always returns
null. Note I'm using the C++ broker.

I am subscribing to messages like so:
Topic topic = _session.createTopic("#");
TopicSubscriber messageSubscriber = _session.createSubscriber(topic);
messageSubscriber.setMessageListener(new MyMessageListener());

So my listener is receiving messages from multiple topics. When that message
is received, I'd like to know what topic it was sent to.

Here's what I'm trying:

public void onMessage(Message message) {
   try {
      BytesMessage bytes = (BytesMessage) message;
      String routingKey = null;
      Topic topic =  (Topic)message.getJMSDestination();
      if(topic != null) {
         routingKey = topic.getTopicName();
      }
     System.out.println("Routing Key: " + routingKey);
  } catch(JMSException ex) {
     ex.printStackTrace();
  }
}


Unfortunately, message.getJMSDestination() always returns null for me.

I can get it to work this way, but again I don't want to tie my code to qpid
specific classes:

public void onMessage(Message message) {
  JMSBytesMessage qpidbytes = (JMSBytesMessage) message;
  AMQMessageDelegate_0_10 delegate = (AMQMessageDelegate_0_10)
qpidbytes.getDelegate();
  String routingKey = delegate.getDeliveryProperties().getRoutingKey();
  System.out.println("Routing Key: " + routingKey);
}



I even tried explicitly setting the JMSDestination when publishing the
message, but that doesn't seem to make any difference. Why does
getJMSDestination() always return null? Is there a workaround for me?

Thanks in advance

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message