activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: ActiveMQ-CPP: how to send to temp queue?
Date Thu, 16 Jul 2009 14:30:54 GMT
On Thu, 2009-07-16 at 06:56 -0700, Ivan Pechorin wrote:
> Hello
> 
> I'm trying to implement Request-Response pattern with:
>  - ActiveMQ broker,
>  - NMS (C#) on the client (requestor) side,
>  - CMS (ActiveMQ-CPP) on the server (responder) side.
> 
> This pattern is described very clearly 
>  - for JMS:
> http://remark.wordpress.com/articles/implementing-request-response-with-activemq-and-nms/
>  - for NMS:
> http://activemq.apache.org/how-should-i-implement-request-response-with-jms.html
> 
> So, on the ActiveMQ-CPP side I perform the following steps:
>  1) create consumer that receives request from normal (permanent) queue,
>  2) obtain ReplyTo from the request using method getCMSReplyTo() of
> cms::Message,
>  3) dynamic_cast from cms::Destination* to cms::TemporaryQueue*, 
>  4) retrieve name of the temporary queue using method getQueueName() of
> cms::TemporaryQueue (cms::Destination doesn't have this method),
>  5) store name of the temporary queue in std::string,
>  6) when a reply is ready, I need to send it to the temporary queue
> specified by client in ReplyTo of the request.
> 
> The problem is that I don't understand how to send a message to a temporary
> queue by its name.
> 
> For normal queues, I resolve a destination by its name using method
> resolveDestinationName() of activemq::cmsutil::DynamicDestinationResolver.
> However, it seems like DynamicDestinationResolver has nothing to do with
> temporary queues.
> 
> Should I cast cmd::TemporaryQueue to activemq::commands::ActiveMQTempQueue,
> clone it using cloneDataStructure() and store a pointer to this object
> instead of storing std::string with a name of the temporary queue?
> 
> P.S. I tried hard to find answer on this question in this mailing list, in
> ActiveMQ-CPP examples and docs, but I failed.
> 
> Best regards, 
> Ivan


Actually its not nearly as hard as all that.  Each of the Destination
classes in CMS extends from cms::Destination which defines a clone
method.  When you receive a message that has a replyTo destination you
can simply clone the destination and use the new instance you created to
create a new producer for that destination or you can use an existing
producer and call one of the send methods that takes a Destination as an
argument.  You shouldn't need to do any casting or muck about with queue
names etc.

You code might look something like this

cms::Destination* replyToAddress = NULL;

if( message->getCMSReplyTo() != NULL ) {
    replyToAddress = message->getCMSReplyTo()->clone();
}

// Creates a new response message....

producer->send( replyToAddress, responseMessage );


Regards
Tim.


Mime
View raw message