我是否应该将 CachingConnectionFactory 与 hornetq 2.4.1 一起使用

2024-04-30

根据有关在 hornetq 中使用 JMSTemplate 的长期信息,我们在连接到服务器时一直使用 CachingConnectionFactory。这是一个示例配置,与我们正在使用的配置非常相似:

<bean id="jmsConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
    <constructor-arg name="ha">
        <value>false</value>
    </constructor-arg>
    <constructor-arg name="initialConnectors">
        <bean class="org.hornetq.api.core.TransportConfiguration">
            <constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
            <constructor-arg>
                <map key-type="java.lang.String" value-type="java.lang.Object">
                    <entry>
                        <key>
                            <util:constant static-field="org.hornetq.core.remoting.impl.netty.TransportConstants.HOST_PROP_NAME"/>
                        </key>
                        <value>${message-server.host}</value>
                    </entry>
                    <entry>
                        <key>
                            <util:constant static-field="org.hornetq.core.remoting.impl.netty.TransportConstants.PORT_PROP_NAME"/>
                        </key>
                        <value>${message-server.port}</value>
                    </entry>
                </map>
            </constructor-arg>
        </bean>
    </constructor-arg>
</bean>

<bean id="connectionFactory"
    class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="jmsConnectionFactory" />
    <property name="username" value="${message-server.user-name}" />
    <property name="password" value="${message-server.password}" />
</bean>

<bean id="caching.connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="connectionFactory" />
    <property name="sessionCacheSize" value="${session-cache}" />
    <property name="cacheProducers" value="${cache-producers}" />
    <property name="cacheConsumers" value="${cache-consumers}" />
</bean>

<bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    <property name="connectionFactory" ref="connectionFactory" />
</bean>

<!-- Input Integration -->

<bean id="inputTopic" class="org.hornetq.jms.client.HornetQTopic">
    <constructor-arg>
        <value>${topicName}</value>
    </constructor-arg> 
</bean>
<int-jms:message-driven-channel-adapter connection-factory="connectionFactory"
    destination="inputTopic" 
    transaction-manager="transactionManager"
    pub-sub-domain="true" 
    channel="command.serialized.objectInputChannel" />

这已经为我们工作了近三年了。当尝试升级到最新的 hornetq 库时,我们遇到与此类似的异常:

2014-05-22 08:56:59,063 [Service-0] ERROR Error sending event to channel allOutput.channel 
org.springframework.integration.MessageHandlingException: error occurred in message handler [org.springframework.integration.jms.JmsSendingMessageHandler#0]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:178) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:149) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:330) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:169) ~[spring-integration-core-3.0.2.RELEASE.jar:na]

    ... lines omitted to fit

    at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:169) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:134) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:178) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:149) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    at c.i.e.p.ListenerChannelAdapter.sendEventToChannel(ListenerChannelAdapter.java:147) [processing-library-1.6.0-SNAPSHOT.jar:na]
    at c.i.e.p.ListenerChannelAdapter.update(ListenerChannelAdapter.java:75) [processing-library-1.6.0-SNAPSHOT.jar:na]
    at com.espertech.esper.core.service.EPRuntimeImpl.processMatches(EPRuntimeImpl.java:924) [esper-4.9.0.jar:na]
    at com.espertech.esper.core.service.EPRuntimeImpl.processWrappedEvent(EPRuntimeImpl.java:459) [esper-4.9.0.jar:na]
    at com.espertech.esper.core.thread.InboundUnitSendMap.run(InboundUnitSendMap.java:54) [esper-4.9.0.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_55]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_55]
    at java.lang.Thread.run(Unknown Source) [na:1.7.0_55]
Caused by: org.springframework.jms.IllegalStateException: Producer is closed; nested exception is javax.jms.IllegalStateException: Producer is closed
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:279) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:169) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:566) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:689) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.integration.jms.JmsSendingMessageHandler.send(JmsSendingMessageHandler.java:139) ~[spring-integration-jms-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.jms.JmsSendingMessageHandler.handleMessageInternal(JmsSendingMessageHandler.java:112) ~[spring-integration-jms-3.0.2.RELEASE.jar:na]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73) ~[spring-integration-core-3.0.2.RELEASE.jar:na]
    ... 140 common frames omitted
Caused by: javax.jms.IllegalStateException: Producer is closed
    at org.hornetq.jms.client.HornetQMessageProducer.checkClosed(HornetQMessageProducer.java:520) ~[hornetq-jms-client-2.4.1.Final.jar:na]
    at org.hornetq.jms.client.HornetQMessageProducer.getDeliveryMode(HornetQMessageProducer.java:127) ~[hornetq-jms-client-2.4.1.Final.jar:na]
    at org.springframework.jms.connection.CachedMessageProducer.<init>(CachedMessageProducer.java:89) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.getCachedProducer(CachingConnectionFactory.java:388) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.invoke(CachingConnectionFactory.java:331) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at com.sun.proxy.$Proxy16.createProducer(Unknown Source) ~[na:na]
    at org.springframework.jms.core.JmsTemplate.doCreateProducer(JmsTemplate.java:1044) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate.createProducer(JmsTemplate.java:1025) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:598) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate$3.doInJms(JmsTemplate.java:569) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:491) ~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
    ... 145 common frames omitted

经过调查,这似乎与缓存的使用有关,但对于我们是否应该缓存似乎没有任何明确的答案。

hornetq/jboss 的人们似乎表明,不使用缓存是一种反模式,正如我多年来读过的几篇文章中所指出的,这里有一篇这样的文章:

https://community.jboss.org/wiki/CanIUseTheSpringJMSTemplateWithHornetQ https://community.jboss.org/wiki/CanIUseTheSpringJMSTemplateWithHornetQ

但 Spring 的一些人似乎有相互矛盾的观点。

我看过加里·拉塞尔关于这个主题的一些笔记(https://stackoverflow.com/users/1240763/gary-russell https://stackoverflow.com/users/1240763/gary-russell)

有几篇文章指出不要将 CachingConnectionFactory 与 DefaultMessageListenerContainer 一起使用。

使用Spring CachingConnectionFactory时什么时候适合缓存Consumers? https://stackoverflow.com/questions/22672419/when-is-it-appropriate-to-cacheconsumers-when-using-spring-cachingconnectionfact/22673967#22673967

使用Spring的CachingConnectionFactory时关闭Session https://stackoverflow.com/questions/18863057/closing-session-when-using-springs-cachingconnectionfactory

我们从所有 int-jms:message-driven-channel-adapter 中删除了 CachingConnectionFactory ,但仍然看到上述异常,直到我关闭了消费者和生产者的缓存,它才消失。

有人可以给我一个关于缓存应该如何工作的指示吗?如果我们正确设置它,这是否是新 hornetq 服务器中的一个错误?


你用的是哪个版本的spring?我相信这实际上是由 spring 中的一个错误引起的,导致它无法与 JMS 2.0 正常工作。

See Spring 4 CachingConnectionFactory 与 JMS 2.0 无法正确缓存生产者 https://stackoverflow.com/questions/24501329/spring-4-cachingconnectionfactory-with-jms-2-0-doesnt-properly-cache-producers and https://jira.spring.io/browse/SPR-11949 https://jira.spring.io/browse/SPR-11949

基本上,您至少需要使用已修复此错误的 Spring 4.0.6 或 4.1RC1。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我是否应该将 CachingConnectionFactory 与 hornetq 2.4.1 一起使用 的相关文章

随机推荐

  • 在 mahout-0.6 上运行“Mahout in Action”中的示例代码时出现 IOException

    我正在学习 Mahout 并阅读 Mahout in Action 当我尝试运行第 7 章 Simple KMeans Clustering java 中的示例代码时 弹出了一个异常 线程 main 中的异常 java io IOExcep
  • 如何查找pdf中文本的x,y位置

    有没有工具可以查找 pdf 文件中文本内容的 X Y 位置 Docotic Pdf 库 http bitmiracle com pdf library 可以做到 请参阅下面的 C 示例 using PdfDocument doc new P
  • Android 2.3 中崩溃服务重启后不会调用 onStartCommand()

    我遇到了 Android 服务重启的问题 我正在针对 API 版本 7 进行构建 并在 Android 2 3 3 的设备上运行 问题是 当我的服务被系统杀死并稍后重新启动时 只有onCreate 我的服务被称为 代码在onStartCom
  • 如何在服务器端应用程序中获取本地数据源?

    我正在使用 blazor 服务器端应用程序 我需要引用本地数据源 我已经使用 Http 作为默认客户端示例 code ChartData dataSource protected override async Task OnInitAsyn
  • Swift loadItem 关闭未运行

    我正在编写一个共享扩展 但捕获并保存共享附件的闭包未运行 我怎样才能找出原因 switch 分支执行 附件就在那里 没有错误消息 它只是永远不会运行 if let contents content attachments as NSItem
  • 我的类可以在 Swift 中重写协议属性类型吗?

    protocol Parent var children AnyObject get set class Foo class Bar Parent error happens here var children Foo init 我收到错误
  • 续集 beforeSave 挂钩未触发

    我已经使用sequelize auto生成了模型 并且需要使用beforeSave钩子 请参阅here https stackoverflow com questions 47795113 insert update postgis geo
  • Microsoft Visual Studio 2012 无法在 C# 文件中设置断点

    我安装了 Microsoft Visual Studio Professional 2012 版本 11 0 60610 01 Update 3 调试 C cs 文件时 当我尝试设置断点时 Visual Studio 会显示以下消息 无法在
  • 将所有 mysql 选定的行放入数组中

    我想知道 php 中是否有一个函数可以允许我将所有选定的数据放入一个数组中 目前我正在使用 mysql fetch array 正如我在手册中读到的那样 该函数不会获取表中的每条记录 result mysql query SELECT FR
  • 获取当前 ClickOnce 的应用程序发布者名称?

    是否可以读取当前运行的 ClickOnce 应用程序的发布者名称 您在Project Properties gt Publish gt Options gt Publisher name在 Visual Studio 中 我需要它的原因是运
  • SQL select通常是如何实现的

    我有两节课 class PopulationMember public void operationOnThisMember1 void operationOnThisMember2 private Population populalti
  • 带有透明图像的可拖动 Tkinter 标签仍然覆盖父画布中的图像

    我正在努力在背景图像顶部添加可拖动标签 其中标签是具有透明背景的图像 用于标签本身的图像是透明的 但标签本身相对于其父画布不透明 由于标签是可拖动的 我无法轻松使用父图像作为标签 并将透明图像粘贴在顶部 龙是一个可拖动的标签 具有透明背景
  • 如何在 AngularJS 中读取 Java 属性文件?

    有什么方法可以从位于网络服务器外部的 angularjs 读取属性文件吗 就像在java中一样 属性文件部署在项目之外 但是我们可以将项目中的这些文件作为filter properties读取 这样任何解决方案都可以在AngularJS中找
  • Android TV 上不会出现通知

    我正在 Android TV 上玩通知 不过 我无法在屏幕上显示通知 我正在使用 Android 6 0 上的 Nexus 播放器 当我在手机上运行此代码时 会出现通知 但在电视上 不会出现通知 我错过了什么吗 Override publi
  • 适用于 Mac OS X 的 SQL 客户端,可与 MS SQL Server 配合使用 [已关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 桌面应用程序的对象持久化策略

    我正在开发一个基于 Java 的桌面应用程序 我需要保留一些从应用程序对象模型生成的数据 最好保存到文件中 还需要保护持久文件 以便其他人无法从数据中获取对象模型详细信息 执行这些操作的最佳策略是什么 我的印象是这些要求对于桌面应用程序来说
  • 运营商部分应用

    如果我想在字符末尾添加一个空格以返回列表 如果我不传递任何参数 我将如何通过部分应用程序来完成此操作 还有类型是 space Char gt Char 由于使用 和 运算符出现 解析错误 我在末尾添加空格时遇到问题 到目前为止我所拥有的是
  • 如何将图像调整为原始大小

    Android s imageView has a serious flaw it makes my image into a square frame with the rest as white space How can I fix
  • EF Code First DBContext 和事务

    我想知道实现交易的最佳方式是什么DBContext 尤其 Does DbContext SaveChanges如果我更改多个实体 请在内部实施交易 如果我想打电话DbContext SaveChanges多次 相同上下文 不同上下文 如何实
  • 我是否应该将 CachingConnectionFactory 与 hornetq 2.4.1 一起使用

    根据有关在 hornetq 中使用 JMSTemplate 的长期信息 我们在连接到服务器时一直使用 CachingConnectionFactory 这是一个示例配置 与我们正在使用的配置非常相似