0
我使用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)?
謝謝。對於JmsConnectionFactory及其工作,我發現類似的屬性forceSyncSend = true –