gpt4 book ai didi

java - JMS 连接在向未经授权的路由发送消息时不会抛出 JMSSecurityException

转载 作者:行者123 更新时间:2023-12-02 12:12:14 25 4
gpt4 key购买 nike

我正在使用 Apache Camel 和 Spring 从我的 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 block 内。

[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 记录在控制台中并继续执行。从第二条消息开始,执行进入带有 IllegalStateException( session 已关闭) 的 catch 内。

如何在仅包含第一条消息的 catch block 中执行(对于 JMSSecurityException)?

最佳答案

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

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

关于java - JMS 连接在向未经授权的路由发送消息时不会抛出 JMSSecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46454230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com