You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Steven Turner <st...@gmail.com> on 2013/10/29 07:58:10 UTC

ExceptionListener not getting fired on the client side when using JmsTemplate

Hi, 

I have a custom plugin on the broker side which throws an exception in some
cases from addConnection. I would like to handle this exception on the
client side. My client uses JmsTemplate for sending messages. I am using
ActiveMQConnectionFactory.setExceptionListener to set a listener but this is
never getting invoked. 

I am not sure why the exception listener is not getting invoked here.

org.springframework.jms.UncategorizedJmsException: Uncategorized exception
occured during JMS processing; nested exception is javax.jms.JMSException:
common.jms.ActiveMQAuth$ActiveMQAuthException: Could not establish server
context
        at
org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:260)
        at
org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:172)
        at
org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:441)
        at
org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:485)
        at common.jms.test.JMSProducer.start(JMSProducer.java:228)
        at common.jms.test.JMSProducer.access$900(JMSProducer.java:45)
        at common.jms.test.JMSProducer$1.run(JMSProducer.java:302)
        at java.lang.Thread.run(Thread.java:724)
Caused by: javax.jms.JMSException:
common.jms.ActiveMQAuth$ActiveMQAuthException: Could not establish server
context
        at
org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:49)
        at
org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1391)
        at
org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1496)
        at
org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:325)
        at
org.apache.activemq.pool.ConnectionPool$2.makeObject(ConnectionPool.java:105)
        at
org.apache.activemq.pool.ConnectionPool$2.makeObject(ConnectionPool.java:90)
        at
org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1220)
        at
org.apache.activemq.pool.ConnectionPool.createSession(ConnectionPool.java:142)
        at
org.apache.activemq.pool.PooledConnection.createSession(PooledConnection.java:174)
        at
org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:200)
        at
org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:429)
        ... 5 more
Caused by: java.lang.Throwable:
common.jms.ActiveMQAuth$ActiveMQAuthException: Could not establish server
context
        at
common.jms.ActiveMQAuth.establishServerContext(ActiveMQAuth.java:498)
        at
common.jms.ActiveMQAuthPlugin.addConnection(ActiveMQAuthPlugin.java:141)
        at
org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:91)
        at
org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:766)
        at
org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79)
        at
org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)
        at
org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:329)
        at
org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:184)
        at
org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)
        at
org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:113)
        at
org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:288)
        at
org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)


Could the ActiveMQ gods please shed some light on this and help me out?

-Steve.



--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by samdowning <sa...@gmail.com>.
Hi, 

I too have experimented with ExceptionListener in the past with no success.
I think the exception is invoked in some cases and not in some cases and
perhaps the implementation is buggy. 

ActiveMQ developer team would be best to comment on this. This sounds like a
basic requirement to have in many cases and I observed that exception
listener was not getting invoked in case of several exceptions.

-Sam



--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673297.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by khandelwalanuj <kh...@gmail.com>.
> Well you could force the connection to always sync send or always 
> async send and deal with it in each respective way (on the connecting 
> thread, or on the exception listener). 

I can see that connection can be forced to always sync send using
[alwaysSyncSend=true] .

But how should I force it for always async send, [any property] ? 





--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4685548.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by Christian Posta <ch...@gmail.com>.
Well you could force the connection to always sync send or always
async send and deal with it in each respective way (on the connecting
thread, or on the exception listener).

http://activemq.apache.org/connection-configuration-uri.html

[alwaysSyncSend=true]

Otherwise, the exceptionListener is the callback for asynchronous
scenarios. This is what the failoverTransport uses to detect breakages
in the connection.



On Tue, Oct 29, 2013 at 10:06 PM, Steven Turner
<st...@gmail.com> wrote:
> Thanks Christian. Yes, I do see the exception in my logs which I had already
> mentioned in my first post in this thread. I wanted to handle all exceptions
> in a generic way in ExceptionListener instead of handling async and sync
> exceptions differently. Is there any support in ActiveMQ to get callback for
> any exception on the connection between client and broker (especially the
> ones thrown by broker plugins)
>
> org.springframework.jms.UncategorizedJmsException: Uncategorized exception
> occured during JMS processing; nested exception is javax.jms.JMSException:
> common.jms.ActiveMQAuth$ActiveMQAuthException: Could not establish server
> context
>         at
> org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:260)
>         at
> org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:172)
>         at
> org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:441)
>         at
> org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:485)
>         at common.jms.test.JMSProducer.start(JMSProducer.java:228)
>         at common.jms.test.JMSProducer.access$900(JMSProducer.java:45)
>         at common.jms.test.JMSProducer$1.run(JMSProducer.java:302)
>         at java.lang.Thread.run(Thread.java:724
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673346.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.



-- 
Christian Posta
http://www.christianposta.com/blog
twitter: @christianposta

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by Steven Turner <st...@gmail.com>.
Hi Christian,

Did you get a chance to look at this? Could you please help? 

Also, is there any way in ActiveMQ to detect connection breakages with
broker. That is, whenever the broker goes down, I would like to perform some
task on the client side immediately and I need to detect this reliably. Is
there a way I can detect such broker going down events on client side?

-Steve 




--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673820.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by Steven Turner <st...@gmail.com>.
Thanks Christian. Yes, I do see the exception in my logs which I had already
mentioned in my first post in this thread. I wanted to handle all exceptions
in a generic way in ExceptionListener instead of handling async and sync
exceptions differently. Is there any support in ActiveMQ to get callback for
any exception on the connection between client and broker (especially the
ones thrown by broker plugins)

org.springframework.jms.UncategorizedJmsException: Uncategorized exception
occured during JMS processing; nested exception is javax.jms.JMSException:
common.jms.ActiveMQAuth$ActiveMQAuthException: Could not establish server
context 
        at
org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:260) 
        at
org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:172) 
        at
org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:441) 
        at
org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:485) 
        at common.jms.test.JMSProducer.start(JMSProducer.java:228) 
        at common.jms.test.JMSProducer.access$900(JMSProducer.java:45) 
        at common.jms.test.JMSProducer$1.run(JMSProducer.java:302) 
        at java.lang.Thread.run(Thread.java:724



--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673346.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by Christian Posta <ch...@gmail.com>.
Do you see the exception anywhere in your logs?

the exception listener is for async sends resulting in an error. the
connection info is sent sync, so you should see the exception on the same
thread as that creating the connection.


On Tue, Oct 29, 2013 at 1:46 AM, Steven Turner <st...@gmail.com>wrote:

> This issue seems to be happening even if I use the raw ActiveMQ API instead
> of using the Spring's JmsTemplate. If I just set ExceptionListener on the
> ActiveMQ connection or connectionfactory, it is not getting invoked for
> exceptions as part of ActiveMQConnection.start().
>
> It looks to me from the code also that The ExceptionListener is not
> invoked/triggered when exception occurs as part of starting the connection.
> ActiveMQConnection.start() calls ensureConnectionInfoSent() which calls
> syncSendPacket. If the response has an exception here, why is the exception
> handler not getting invoked?
>
> Isn't this a bug?
>
> -Steven
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673287.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by Steven Turner <st...@gmail.com>.
This issue seems to be happening even if I use the raw ActiveMQ API instead
of using the Spring's JmsTemplate. If I just set ExceptionListener on the
ActiveMQ connection or connectionfactory, it is not getting invoked for
exceptions as part of ActiveMQConnection.start().

It looks to me from the code also that The ExceptionListener is not
invoked/triggered when exception occurs as part of starting the connection.
ActiveMQConnection.start() calls ensureConnectionInfoSent() which calls
syncSendPacket. If the response has an exception here, why is the exception
handler not getting invoked?

Isn't this a bug?

-Steven



--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673287.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ExceptionListener not getting fired on the client side when using JmsTemplate

Posted by Steven Turner <st...@gmail.com>.
This is what I am doing:

public class ActiveMQAuthConnectionFactory extends 
     org.apache.activemq.ActiveMQConnectionFactory
{
private static class AMQExceptionListener implements ExceptionListener
    {
        @Override
        public void onException(JMSException exception)
        {
            LOG.info("XXX Exception is " + exception);
        }
    }

public ActiveMQAuthConnectionFactory()
{
        super();
        super.setExceptionListener(new AMQExceptionListener());
}
}

I am then using this ActiveMQAuthConnectionFactory wrapped in a
PooledConnectionFactory which is passed to JmsTemplate.

    <bean id="connectionFactory"
class="common.jms.ActiveMQAuthConnectionFactory">
        <property name="brokerURL"
value="failover://(tcp://test1.hyd:61616)" />
    </bean>

    
    <bean id="jmsConnectionFactory"
        class="org.apache.activemq.pool.PooledConnectionFactory"
        destroy-method="stop">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="maxConnections" value="5" /> 
    </bean>

Could somebody explain what I am doing wrong here?




--
View this message in context: http://activemq.2283324.n4.nabble.com/ExceptionListener-not-getting-fired-on-the-client-side-when-using-JmsTemplate-tp4673285p4673286.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.