我正在使用Apache Camel和Spring从我的Java服务发送消息。如果exchange发生任何错误,我需要处理/触发某些事件。我使用以下代码来实现我的目标。
try
{
producerTemplate.sendBody(endPoint, bytes);
}
catch (final RuntimeCamelException exception)
{
LOGGER.error("Exception occured in sendBody", exception.getMessage(), exception);
handleError(); // handle error here.
}
为了进行测试,我将端点的值设置为错误的路由名称
广播模拟器。路线1
. 当我运行上述代码时,我可以在控制台中看到以下错误,但它从未出现在catch块中。
[33m16:15:51,714 WARN [org.springframework.jms.connection.CachingConnectionFactory] (QpidJMS Connection Executor: ID:7dacac8c-93ce-48c0-92fe-8dc0e8:1) Encountered a JMSException - resetting the underlying JMS Connection: javax.jms.JMSSecurityException: Admin@QPID9019 cannot publish to broadcast with routing-key broadcast.SIMULATOR.ROUTE1 (/builddir/build/BUILD/qpid-cpp-1.36.0/src/qpid/broker/amqp/Authorise.cpp:126) [condition = amqp:unauthorized-access]
at org.apache.qpid.jms.provider.amqp.AmqpSupport.convertToException(AmqpSupport.java:143) [qpid-jms-client-0.23.0.jar:]
at org.apache.qpid.jms.provider.amqp.AmqpSupport.convertToException(AmqpSupport.java:117) [qpid-jms-client-0.23.0.jar:]
我正在向路由发送多条消息。对于第一条消息,
JMSSecurityException
登录控制台并继续执行。从第二条消息开始,执行进入catch内部
非法状态异常(会话已关闭)
如何仅使用第一条消息在catch块内执行(对于JMSSecurityException)?