qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gordon Sim <g...@redhat.com>
Subject Re: messaging::Session bahaviour on error?
Date Fri, 01 Apr 2011 10:41:53 GMT
On 03/21/2011 01:36 PM, Toralf Lund wrote:
> Hi!
>
> I'm sort of new to QPid, and I'm trying to set up a broker link based on
> the qpid::messaging API, with connections, sessions, receivers etc.
> Actually, I've had a setup that works quite all right in the normal case
> for a while, but I'm a bit confused about how errors are supposed to be
> handled, or to be more precise, what happens to the session when an
> operation fails. Specifically, if I have message handling code
> equivalent to:
>
> std::string broker="myBrokerHost";
> qpid::messaging::Connection connection(broker);
> qpid::messaging::Session session;
> qpid::messaging::Receiver receiver;
>
> while(1) {
> try {
> if(!connection.isOpen())
> connection.open();
> if(session.isNull())
> session=authConnection.createSession();
> if(receiver.isNull())
> receiver=session.createReceiver("my-exchange/my-topic"); // .... Check
> for message on receiver, and handle as appropriate
>
> } catch(const qpid::types::Exception &error) {
> fprintf(stderr, "Error - \"%s\" when opening link to %s\n",
> error.what(), broker.c_str());
> }
> }
>
> Which, like I said, works if everything is OK. If the broker connection
> works, but the receiver address ("my-exchange/my-topic") initially
> doesn't exist on the broker I have a problem, on the other hand. In this
> case, I get an error message like
>
> Error - "Queue my-exchange does not exist" when opening power link to
> myBrokerHost
>
> on every iteration of the loop. This is what I expect when the address
> doesn't exist, of course, but - and here is the real problem - even if I
> create the appropriate exchange/topic/queue, the error will keep
> appearing. In fact, it may seem like Session::createReceiver(), once it
> has failed, will just keep re-throwing the exception associated with the
> first failure (on subsequent calls), rather than trying the actual
> broker connection again.
>
> So, what's the expected behaviour related to this? Is simply the session
> invalid once there has been a failure, so that I have to create a new
> one?

Yes, at present exceptions from the broker will invalidate the session. 
You therefore need to recreate it, and the receiver(s) on it. You can 
use the Session::hasError() method to determine whether the session is 
invalid.

> Or is there some way to reset? Or is a re-issued createReceiver()
> (or createSender()) actually supposed to try contacting the broker
> again? And what if I have multiple senders and receivers associated with
> a session, and some addresses exist, but others don't?

I agree that the current behaviour is unfriendly. It is a controversial 
aspect of AMQP 0-10 (and indeed earlier versions) that bubbles up 
through the API. I suspect it would be possible to safely and reliably 
mask this from applications. However we need to do a bit more work on 
clarifying various exceptional cases. I've created 
https://issues.apache.org/jira/browse/QPID-3179 to track this work.

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


Mime
View raw message