activemq的學習,第一篇
阿新 • • 發佈:2018-11-28
本地的activemq的地址:
http://localhost:8161/admin/
win10的啟動avtivemq
E:\Program Files\ActiveMQ\apache-activemq-5.15.3\bin\win64
win64裡面的activemq.bat
這是spring集合activemq的地址:github
pom.xml引入的依賴:
<dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.15.3</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>4.3.10.RELEASE</version> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> <version>5.15.0</version> </dependency>
引入相對應的activemq的版本,對應下載的版本
spring配置avtivemq的xml檔案:
<?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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.coder520"/> <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> <bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory" ref="jmsFactory"/> <property name="sessionCacheSize" value="1"/> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="cachingConnectionFactory"/> <property name="messageConverter"> <bean class="org.springframework.jms.support.converter.SimpleMessageConverter"/> </property> </bean> <bean id="testQueue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg name="name" value="spring-queue"/> </bean> <bean id="testTopic" class="org.apache.activemq.command.ActiveMQTopic"> <constructor-arg index="0" value="spring-topic"/> </bean> <bean id="queueListener" class="com.coder520.QueueListener"/> <bean id="topic1Listener" class="com.coder520.Topic1Listener"/> <bean id="topic2Listener" class="com.coder520.Topic2Listener"/> <bean id="queueContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="cachingConnectionFactory"/> <property name="destination" ref="testQueue"/> <property name="messageListener" ref="queueListener"/> </bean> <bean id="topic1Container" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="cachingConnectionFactory"/> <property name="destination" ref="testTopic"/> <property name="messageListener" ref="topic1Listener"/> </bean> <bean id="topic2Container" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="cachingConnectionFactory"/> <property name="destination" ref="testTopic"/> <property name="messageListener" ref="topic2Listener"/> </bean> </beans>