JMS连接在发送消息给未授权的路由时不抛出JMSSecurityException
问题描述:
我使用Apache Camel和Spring从我的Java服务发送消息。如果在交换时发生任何错误,我需要处理/触发某些事件。我正在使用下面的代码来实现我的目标。JMS连接在发送消息给未授权的路由时不抛出JMSSecurityException
try
{
producerTemplate.sendBody(endPoint, bytes);
}
catch (final RuntimeCamelException exception)
{
LOGGER.error("Exception occured in sendBody", exception.getMessage(), exception);
handleError(); // handle error here.
}
为了测试我端点的值设置为不正确路径名称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: [email protected] 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并继续执行。从第二条消息开始,执行进入IllegalStateException(会话关闭)。
如何在catch块内带有第一条消息(对于JMSSecurityException)?
答
它取决于您正在使用的JMS客户端。由于其中一些人以异步方式发送消息。他们可能有一个配置选项可以用来关闭它。
例如,Apache ActiveMQ具有此异步发送选项 http://activemq.apache.org/async-sends.html然后您可以关闭它。
谢谢。对于JmsConnectionFactory及其工作,我发现类似的属性forceSyncSend = true –