【问题标题】:JMS Connection not throwing JMSSecurityException on sending message to unauthorized routeJMS 连接在向未经授权的路由发送消息时未抛出 JMSSecurityException
【发布时间】: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


    【解决方案1】:

    这取决于您使用的 JMS 客户端。因为其中一些以异步方式发送消息。他们可能有一个配置选项,您可以使用它来关闭它。

    例如 Apache ActiveMQ 有这个带有 asyncSend 选项 http://activemq.apache.org/async-sends.html 然后您可以将其关闭。

    【讨论】:

    • 谢谢。我为 JmsConnectionFactory 及其工作找到了类似的属性 forceSyncSend=true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    相关资源
    最近更新 更多