Java 我应该还是不应该';我是否使用带有hornetq 2.4.1的CachingConnectionFactory

Java 我应该还是不应该';我是否使用带有hornetq 2.4.1的CachingConnectionFactory,java,spring,caching,spring-integration,hornetq,Java,Spring,Caching,Spring Integration,Hornetq,基于长期以来关于在hornetq中使用JMSTemplate的信息,我们在连接到服务器时一直在使用CachingConnectionFactory。下面是一个配置示例,与我们正在使用的配置非常类似: <bean id="jmsConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory"> <constructor-arg name="ha"> <va

基于长期以来关于在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" />

假的
${message server.host}
${message server.port}
${topicName}
这已经为我们工作了将近3年了。当尝试升级到最新的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
2014-05-22 08:56:59063[Service-0]向通道allOutput.channel发送事件时出错
org.springframework.integration.MessageHandlingException:消息处理程序[org.springframework.integration.jms.JmsSendingMessageHandler#0]中出现错误
在org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:79)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.dispatcher.UnicastingDispatcher.dispatcher(UnicastingDispatcher.java:102)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:178)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:149)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:330)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:169)~[spring-integration-core-3.0.2.RELEASE.jar:na]
... 漏掉的线条
在org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:169)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:134)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.dispatcher.UnicastingDispatcher.dispatcher(UnicastingDispatcher.java:102)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:178)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:149)~[spring-integration-core-3.0.2.RELEASE.jar:na]
在c.i.e.p.ListenerChannelAdapter.sendEventToChannel(ListenerChannelAdapter.java:147)[processing-library-1.6.0-SNAPSHOT.jar:na]
在c.i.e.p.ListenerChannelAdapter.update(ListenerChannelAdapter.java:75)[processing-library-1.6.0-SNAPSHOT.jar:na]
在com.espertech.esper.core.service.EPRuntimeImpl.processMatches(EPRuntimeImpl.java:924)[esper-4.9.0.jar:na]
在com.espertech.esper.core.service.EPRuntimeImpl.processWrappedEvent(EPRuntimeImpl.java:459)[esper-4.9.0.jar:na]
在com.espertech.esper.core.thread.InboundUnitSendMap.run(InboundUnitSendMap.java:54)[esper-4.9.0.jar:na]
位于java.util.concurrent.ThreadPoolExecutor.runWorker(未知源)[na:1.7.0_55]
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(未知源)[na:1.7.0_55]
在java.lang.Thread.run(未知源代码)[na:1.7.0_55]
原因:org.springframework.jms.IllegalStateException:生产者已关闭;嵌套异常为javax.jms.IllegalStateException:生产者已关闭
在org.springframework.jms.support.JmsUtils.convertjmsaccesception(JmsUtils.java:279)~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.jms.support.JmsAccessor.convertjmsaccesexception(JmsAccessor.java:169)~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494)~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:566)~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:689)~[spring-jms-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.integration.jms.JmsSendingMessageHandler.send(JmsSendingMessageHandler.java:139)~[spring-integration-jms-3.0.2.RELEASE.jar:na]
在org.springframework.integration.jms.JmsSendingMessageHandler.handleMessageInternal(JmsSendingMessageHandler.java:112)~[spring-integration-jms-3.0.2.RELEASE.jar:na]
在org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)~[spring-integration-core-3.0.2.RELEASE.jar:na]
... 省略140个公共帧
Ca