【发布时间】:2017-09-28 15:41:13
【问题描述】:
我正在使用带有 Spring 的 Apache Camel 从我的 Java 服务发送消息。如果交换时发生任何错误,我需要处理/触发某些事件。我正在使用下面的代码来实现我的目标。
try
{
producerTemplate.sendBody(endPoint, bytes);
}
catch (final RuntimeCamelException exception)
{
LOGGER.error("Exception occured in sendBody", exception.getMessage(), exception);
handleError(); // handle error here.
}
为了测试,我将 endPoint 的值设置为不正确的路由名称 broadcast.SIMULATOR.ROUTE1。当我在上面运行代码时,我可以在控制台中看到以下错误,但它永远不会出现在 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 内部,并带有 IllegalStateException (Session is closed) 。
如何仅在第一条消息的情况下在 catch 块内执行(针对 JMSSecurityException)?
【问题讨论】:
标签: java apache-camel spring-jms qpid jms-topic