spring+activeMq搭建出现的问题

来源:互联网 发布:php 发送手机验证码 编辑:程序博客网 时间:2024/05/29 13:41

发送者的工厂配置,如下配置,在服务启动时发送第一次是不会有问题的,第二次调用,如果引入的activeMq的版本包是5.1.0的话,会出现org.apache.activemq.alreadyClosedException:this connection 错误,如果使用其他版本的activeMq版本包5.14.0的话,初选javax.jms.illegalStatteException:connnetion closed 错误。在网上搜了一大堆碰到这个问题的很少,发现有这么一个答案 

Previously I was using org.apache.activemq.pool.PooledConnectionFactory which is causing this exception. I have replaced PooledConnectionFactory with org.springframework.jms.connection.SingleConnectionFactory and this has resolved the problem

再查看配置文件发现配置的是PooledConnectionFactory,如果配置activemqFactory则不会出现该问题。将如下的配置文件修改进行修改

  <!-- ActiveMQ 连接工厂 -->
     <bean id="amqConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
          destroy-method="stop">
        <property name="connectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL">
                    <value>${amq.broker.url}</value>
                </property>
                <property name="userName">
                    <value>${amq.username}</value>
                </property>
                <property name="password">
                    <value>${amq.password}</value>
                </property>
            </bean>
        </property>
        <property name="maxConnections" value="${amq.max.connections}"></property>
    </bean>

修改后:

  <beanid="amqConnectionFactory"  class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL">
                    <value>${amq.broker.url}</value>
                </property>
                <property name="userName">
                    <value>${amq.username}</value>
                </property>
                <property name="password">
                    <value>${amq.password}</value>
                </property>
            </bean>

修改完之后重新启动程序,访问正常。

http://www-01.ibm.com/support/docview.wss?uid=swg21267957

Note: while the PooledConnectionFactory does allow the creation of a collection of active consumers, it does not 'pool' consumers. Pooling makes sense for connections, sessions and producers, which can be seldom-used resources, are expensive to create and can remain idle a minimal cost. Consumers, on the other hand, are usually just created at startup and left going, handling incoming messages as they come. When a consumer is complete, it's preferred to shut down it down rather than leave it idle and return it to a pool for later reuse: this is because, even if the consumer is idle, ActiveMQ will keep delivering messages to the consumer's prefetch buffer, where they'll get held up until the consumer is active again.

原创粉丝点击