You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by JRR <jr...@cisco.com> on 2011/12/10 01:25:45 UTC

How can a producer/consumer tell if its connection is still good?

Hello,

I am using the Active MQ CPP 3.4.0 client.

We have a multi-threaded application that has multiple producers, and they
share a single connection. These connections are */not/* fail over
connections, nor can they be.

I'm trying to find the fastest, most efficient way to determine if a
connection is still up? For example, consider if the broker was up, then my
application starts, and establishes its connection and sends a few messages.
Then later the broker restarts. So, I need to reestablish the connection.

What I've done so far is get the cached connection. And then try to create a
session on it. If the session create throws an exception, I create a new
connection.

However, this feels clunky/kludgy.

Is there a better way to do this?

Oh, I did look at advisory messages, but there isn't an advisory for
creating the connection, there's an advisory for start and stop.

Thank you,

-=John

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-can-a-producer-consumer-tell-if-its-connection-is-still-good-tp4178865p4178865.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How can a producer/consumer tell if its connection is still good?

Posted by Ivan Pechorin <iv...@gmail.com>.
2011/12/10 JRR <jr...@cisco.com>:
> I am using the Active MQ CPP 3.4.0 client.
>
> We have a multi-threaded application that has multiple producers, and they
> share a single connection. These connections are */not/* fail over
> connections, nor can they be.
>
> I'm trying to find the fastest, most efficient way to determine if a
> connection is still up?

Check cms::ExceptionListener. You should implement its methods in some
class, then setExceptionListener( ExceptionListener* listener ) on
your connection.

You can also check src\examples\consumers\SimpleAsyncConsumer.cpp:
this example uses ExceptionListener.

Re: How can a producer/consumer tell if its connection is still good?

Posted by Todd Crone <to...@lexmark.com>.
There is a .NET implementation of Spring but not sure if that would help
you in your situation.

On Wed, Dec 14, 2011 at 12:27 PM, JRR <jr...@cisco.com> wrote:

> Hello Martin,
>
> Thank you for the suggestion to use Spring, but we're a C++ based client,
> not Java. Hence usage of a Spring client isn't available to us.
>
> Or, is there more to Spring than I'm aware?
>
> Thanks,
>
> -=John
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-can-a-producer-consumer-tell-if-its-connection-is-still-good-tp4178865p4196036.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: How can a producer/consumer tell if its connection is still good?

Posted by "Martin C." <ma...@gmx.at>.
Hi,

you are right, I just read to sloppy, and as most of the traffic on
this list is about the Java part, I simply jumped to the wrong
language in my mind. In my C++ implementations I use the same
recommendation as from Ivan Pechorin, I set the cms::ExceptionListener
and have built a very similar implementation to Spring's
SingleConnectionFactory based on this one. Unfortunately there is no
way before any interaction on the connection to know if it is still
up, like there is also no way to knowing if a TCP connection is still
good before actually trying to read/write to it (timeouts aside).

Best regards,
Martin

On Wed, Dec 14, 2011 at 6:27 PM, JRR <jr...@cisco.com> wrote:
> Hello Martin,
>
> Thank you for the suggestion to use Spring, but we're a C++ based client,
> not Java. Hence usage of a Spring client isn't available to us.
>
> Or, is there more to Spring than I'm aware?
>
> Thanks,
>
> -=John
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-can-a-producer-consumer-tell-if-its-connection-is-still-good-tp4178865p4196036.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How can a producer/consumer tell if its connection is still good?

Posted by JRR <jr...@cisco.com>.
Hello Martin,

Thank you for the suggestion to use Spring, but we're a C++ based client,
not Java. Hence usage of a Spring client isn't available to us.

Or, is there more to Spring than I'm aware?

Thanks,

-=John

--
View this message in context: http://activemq.2283324.n4.nabble.com/How-can-a-producer-consumer-tell-if-its-connection-is-still-good-tp4178865p4196036.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: How can a producer/consumer tell if its connection is still good?

Posted by "Martin C." <ma...@gmx.at>.
Hi,

I'd tend to use Spring's SingleConnectionFactory with
reconnectOnException set to true. I'd compare my cached connection
against the one returned by the SingleConnectionFactory to know if any
other consumer encountered a JMS exception.

Basically I'd also treat any JMSException I encounter as a reason to
recycle my connection and other JMS objects.

Best regards,
Martin

On Sat, Dec 10, 2011 at 1:25 AM, JRR <jr...@cisco.com> wrote:
> Hello,
>
> I am using the Active MQ CPP 3.4.0 client.
>
> We have a multi-threaded application that has multiple producers, and they
> share a single connection. These connections are */not/* fail over
> connections, nor can they be.
>
> I'm trying to find the fastest, most efficient way to determine if a
> connection is still up? For example, consider if the broker was up, then my
> application starts, and establishes its connection and sends a few messages.
> Then later the broker restarts. So, I need to reestablish the connection.
>
> What I've done so far is get the cached connection. And then try to create a
> session on it. If the session create throws an exception, I create a new
> connection.
>
> However, this feels clunky/kludgy.
>
> Is there a better way to do this?
>
> Oh, I did look at advisory messages, but there isn't an advisory for
> creating the connection, there's an advisory for start and stop.
>
> Thank you,
>
> -=John
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-can-a-producer-consumer-tell-if-its-connection-is-still-good-tp4178865p4178865.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.