qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gordon Sim <g...@redhat.com>
Subject Re: qpid C++ client and thread safety
Date Tue, 26 Jan 2010 11:54:35 GMT
On 01/20/2010 06:54 PM, Adam Crain wrote:
> Hi,
>
>
>
> I have an application that needs to both read and write messages to a
> broker, i.e. events can come from two sources
>
>
>
> 1)      the broker, something I've setup callbacks for
>
> 2)      the outside world, for arguments sake say someone presses a
> button
>
>
>
> Can I make read/write equally responsive using a single Session object?
>
>
>
> i.e. can I launch a thread to handle my subscriptions, i.e.:
>
>
>
> connection.open(host, port);
> Session session =  connection.newSession();
>
> SubscriptionManager subscriptions(session);
>
> Listener listener(subscriptions);
>
> subscriptions.subscribe(listener, "message_queue");
>
> subscriptions.start(); //non-blocking call, starts another thread, runs
> until stop is called

There is a bug with start() that does not allow you to handle any 
exceptions making that unreliable. However you can yourself create a 
separate dispatch thread and call SubscriptionManager::run() on it. 
(This is all start() does, and by doing so yourself you could catch and 
handle exceptions).

> and then continue on in the parent thread responding to events from the
> other source:
>
>
>
> void OnEvent()
>
> {
>
>          message.getDeliveryProperties().setRoutingKey("routing_key");
>          message.setData("Hi, Mom!");
>          session.messageTransfer(arg::content=message,
> arg::destination="amq.direct");
>
> }

It should certainly be safe to send messages on the same session from 
one thread while processing messages received on that session from another.


However, unless there is any need to have them on the same session (e.g. 
you need to transactionally tie the input and output streams together 
into atomic chunks), I would probably create a separate session for sending.

> These were just code fragments taken from
> http://qpid.apache.org/docs/api/cpp/html/index.html. Any insight you can
> provide into this would be appreciated.
>
>
>
>
>
> Adam Crain
>
> Manager of R&D
>
> Plymouth Systems, Inc.
>
> 919-428-1002
>
>
>
>


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Mime
View raw message