- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Apache Camel 和 Spring 从我的 Java 服务发送消息。如果交换时发生任何错误,我需要重置 JMS 连接。我正在使用下面的代码来实现我的目标。
try
{
producerTemplate.sendBody(endPoint, bytes);
}
catch (final RuntimeCamelException exception)
{
LOGGER.error("Exception occured in sendBody", exception.getMessage(), exception);
handleError(); // handle error here.
}
在 Camel 上下文中,我定义了带有异常监听器的 CachingConnectionFactory 并设置了 reconnectOnException=true
<bean id="testConnectionFactory" class="org.apache.qpid.jms.JmsConnectionFactory">
<property name="username" value="${user.name}" />
<property name="password" value="${user.password}" />
<property name="clientID" value="${host.address}" />
<property name="remoteURI"
value="amqp://${host.address}:${host.port}?jms.clientID=${host.address}?jms.username=${user.name}&jms.password=${user.password}&jms.redeliveryPolicy.maxRedeliveries=${message.retry.count}&amqp.saslMechanisms=PLAIN" />
</bean>
<bean id="testCachingConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="exceptionListener" ref="testCachingConnectionFactory" />
<property name="targetConnectionFactory" ref="testConnectionFactory" />
<property name="reconnectOnException" value="true" />
</bean>
在我的例子中,JMSSecurityException是从下面一行的try block 中抛出的
producerTemplate.sendBody(endPoint, bytes)
执行进入catch block 内,但即使定义了异常监听器,也永远不会调用SingleConnectionFactory的OnException()。这个想法是最终调用resetConnection()(在OnException内部)来重置JMS连接。
最佳答案
实现ExceptionListener
并将异常监听器定义作为属性添加到您的 spring 连接工厂 testCachingConnectionFactory
.
例如创建异常监听类(组件)JmsExceptionListener
:
public class JmsExceptionListener implements ExceptionListener {
@Override
public void onException(JMSException exception) {
// what ever you wanna do here!
}
}
然后添加 JmsExceptionListener
的 bean 定义:
<bean id="jmsExceptionListener" class="JmsExceptionListener"></bean>
然后将定义添加为异常监听器属性:
<property name="exceptionListener" ref="jmsExceptionListener"/>
而不是您在配置中使用的内容:
<property name="exceptionListener" ref="testCachingConnectionFactory" />
关于java - JMS CachingConnectionFactory onException 方法永远不会在 JMSException 上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47036873/
我收到 JMS 异常,队列似乎没有退出或没有完成任务。 消息是异步的,大部分时间都可以正常工作,但有时会出现异常。似乎听众一直在听另一边,但在生产者那边得到了这个异常。 javax.jms.JMSEx
我正在尝试使用 hornetq 消息,但出现此一般异常: javax.jms.JMSException: access denied (java.lang.RuntimePermission getC
我是一名 Java 初学者,我不太确定 JMSExceptions 是什么以及它们的作用,我查找的所有内容似乎都让我深入了解它到底是什么。我只知道它与 API 有关。 谁能用简单的术语向我解释一下它是
我是 JBoss 的新手。我有一个 Ear 文件在 WAS 上工作正常。但是当我在 JBoss EAP 7.1 上尝试时,它给出了以下错误。 14:15:18,640 WARN [org.jboss
是否可以将一些已检查的异常转换为未检查的异常。 当我阅读文档时jms,我发现了一些方法将已检查的异常转换为未检查的。我不需要再使用“throws”了。这是 Java 的特性吗? 最佳答案 您还可以将自
我正在尝试直接实例化 JMS 资源,而不使用 JNDI 到 REMOTE HORNETQ。 我正在 Eclipse IDE 中运行我的测试代码。设置我的类路径以使用 HornetQ 2.2.5 库。
我正在使用 Apache Camel 和 Spring 从我的 Java 服务发送消息。如果交换时发生任何错误,我需要重置 JMS 连接。我正在使用下面的代码来实现我的目标。 try { pr
在以下代码片段中: Connection connection=getConnection(); try { Session session=connection.createSession(
我会尽量详细。也就是说,这是我的第一篇文章,所以请随时对形式/结构/任何内容提出批评,谢谢! 我正在实现一个 MessageListener (javax.jms.MessageListener),当
我有一个不稳定的 Java JMS 问题。片刻工作正常,但不规律地抛出以下异常并中断执行。 请务必注意,这不会停止代理。 javax.jms.JMSException: Peer (vm://test
有一个像这样的自定义对象: package Messages; import java.io.Serializable; import javax.jms.TextMessage; public cl
我使用 Tibjms jar 进行 JMS 连接,在正常情况下工作正常,但如果与 jms 提供程序的连接丢失然后又恢复,我会遇到问题。为了重现该问题,我执行了以下步骤 - 连接到 Intranet 并
我将 Spring 2.5 与实现 MessageListener 的自定义类一起使用。如果在我的 onMessage() 方法中抛出 JmsException,队列的状态会发生什么变化? 在调用 o
我是一名新手,正在尝试将 qpid 与 Apache Camel 集成。我需要编写java代码来使用qpid从队列中读取和写入。 首先我从 qpid 网站下载了 JMS 示例。我尝试运行的代码是。 /
当我在 Tomcat 中运行 ActiveMQ 时,在通过添加新消息访问服务器后收到以下异常: javax.jms.JMSException: No ManagedConnections availa
我有一个异步 JMS 接收器,这样编码(缺少明显的细节): connection = connectionFactory.createConnection(); connection.setExcep
我正在尝试在 EKS 集群上运行 tomcat 实例以连接到 activeMQ,但是,pod 继续崩溃并出现错误 javax.jms.JMSException: Stopped。 我已尝试重新创建 p
我正在复活一个与 WildFly 8/HornetMQ/Log4J 一起工作的旧应用程序。它是交换 JMS ObjectMessages 的远程 Java GUI 客户端。 到目前为止,当为 Wild
我无法配置 org.apache.activemq.ActiveMQSslConnectionFactoryHermesJMS.It ends up saying an error Caused by
我正在尝试开发一个程序,将消息发送到嵌入在 JBoss EAP 7.2 中的 ActiveMQ Artemis。我已按照 this question 中给出的说明进行操作: 下面是我发送消息的方法:
我是一名优秀的程序员,十分优秀!