ActiveMQ 连接池的配置 只需要修改 上篇文章的配置文件和增加jar包
geronimo-spec-jms-1.1-rc4.jar
geronimo-jms_1.1_spec-1.1.1.jar
commons-pool-1.6.jar
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="com" />
<!-- 配置connectionFactoryPool -->
<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61616</value>
</property>
</bean>
</property>
<property name="maxConnections" value="100"></property>
</bean>
<!-- Spring提供的JMS工具类,它可以进行消息发送、接收等 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->
<property name="connectionFactory" ref="jmsFactory"/>
</bean>
<!-- begin MessageListener -->
<!--这个是队列目的地,点对点的-->
<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg>
<value>queue</value>
</constructor-arg>
</bean>
<!-- 消息监听器 -->
<bean id="consumerMessageListener" class="com.listen.ConsumerMessageListener"/>
<!-- 消息监听容器 -->
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsFactory" />
<property name="destination" ref="queueDestination" />
<property name="messageListener" ref="consumerMessageListener" />
</bean>
<!-- end MessageListener -->
<!-- begin SessionAwareMessageListener -->
<!--这个是队列目的地,点对点的-->
<bean id="sessionAwareQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg>
<value>sessionAware</value>
</constructor-arg>
</bean>
<!-- 消息监听器 -->
<bean id="consumerSessionAwareMessageListener" class="com.listen.ConsumerSessionAwareMessageListener">
<property name="destination" ref="queueDestination"/>
</bean>
<!-- 消息监听容器 -->
<bean id="jmsSessionAwareContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsFactory" />
<property name="destination" ref="sessionAwareQueue" />
<property name="messageListener" ref="consumerSessionAwareMessageListener" />
</bean>
<!-- end SessionAwareMessageListener -->
<!-- begin MessageListenerAdapter -->
<!--这个是队列目的地,点对点的-->
<bean id="messageAdapterQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg>
<value>messageAdapter</value>
</constructor-arg>
</bean>
<!-- 消息适配器 -->
<bean id="messageListenerAdapter" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<property name="delegate">
<bean class="com.listen.ConsumerMessageAdapterListener"/>
</property>
<!--
<property name="defaultListenerMethod" value="receiveMessage"/>
-->
<property name="defaultResponseDestination" ref="queueDestination"></property>
</bean>
<!-- 消息监听容器 -->
<bean id="jmsMessageAdapterContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsFactory" />
<property name="destination" ref="messageAdapterQueue" />
<property name="messageListener" ref="messageListenerAdapter" />
</bean>
<!-- end MessageListenerAdapter -->
</beans>