activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: how to get topicName from within onMessage()
Date Fri, 15 Jan 2010 01:18:05 GMT
On Thu, 2010-01-14 at 16:43 -0800, ironrooster wrote:
> Hi all,
>     I am an ActiveMQ newbie who has managed to get a consumer/producer
> system working using topics.  I would like to know which topic has sent a
> particular message, but I can't figure out how to do it.  Perhaps someone
> will have mercy on this problem and shoot it, like an injured horse.
> 
> Thanks!
> 
> p.s. here is a code sample, with a lot removed for simplicity.  The
> if...else is what matters to me.
> 

It would be something along these lines.  I didn't have time to workup a
complete test so might not compile as is.

const cms::Topic* topic = dynamic_cast<const
cms::Topic*>( message->getCMSDestination() );

if( topic != null ) {
   std::string name = topic->getTopicName();
}

Regards
Tim.

> ---
> virtual void onMessage( const Message* message ){
> 
>  <do some stuff here>
> 
>   const TextMessage* textMessage =
>                 dynamic_cast< const TextMessage* >( message );
> 
>   string text = textMessage->getText();
> 
>   if( message->propertyExists( "topicName" ))
> 	text.append( message->getStringProperty("topicName") );
>   else
> 	text.append("nope!");
>   text.append("*");
> 
>   <do some more stuff here>
> }
> 
> After execution, "text" always contains "*nope!*"

-- 
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/




Mime
View raw message