You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by ironrooster <gr...@lowell.edu> on 2010/01/15 01:43:46 UTC
how to get topicName from within onMessage()
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.
---
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!*"
--
View this message in context: http://old.nabble.com/how-to-get-topicName-from-within-onMessage%28%29-tp27170708p27170708.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: how to get topicName from within onMessage()
Posted by Timothy Bish <ta...@gmail.com>.
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/