spring-activemq.xml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:aop="http://www.springframework.org/schema/aop"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-4.2.xsd
  11. http://www.springframework.org/schema/jms
  12. http://www.springframework.org/schema/jms/spring-jms-4.2.xsd
  13. http://activemq.apache.org/schema/core
  14. http://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd">
  15. <!-- 引入properties配置文件 -->
  16. <context:property-placeholder location="classpath*:activemq.properties"
  17. ignore-unresolvable="true" />
  18. <!-- 监听注解支持 -->
  19. <jms:annotation-driven />
  20. <!-- 连接 activemq -->
  21. <amq:connectionFactory id="jmsConnectionFactory"
  22. brokerURL="tcp://${activemq.ip}:${activemq.port}" userName="${activemq.username}"
  23. password="${activemq.password}" />
  24. <!-- 这里可以采用连接池的方式连接PooledConnectionFactoryBean -->
  25. <bean id="jmsConnectionFactoryExtend"
  26. class="org.springframework.jms.connection.CachingConnectionFactory">
  27. <constructor-arg ref="jmsConnectionFactory" />
  28. <!-- 会话的最大连接数 -->
  29. <property name="sessionCacheSize" value="100" />
  30. </bean>
  31. <!-- 消息处理器 -->
  32. <bean id="jmsMessageConverter"
  33. class="org.springframework.jms.support.converter.SimpleMessageConverter" />
  34. <!-- Spring JmsTemplate 的消息生产者 start -->
  35. <!-- 定义JmsTemplate的Queue类型 -->
  36. <bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate">
  37. <constructor-arg ref="jmsConnectionFactoryExtend" />
  38. <!-- 非pub/sub模型,即队列模式 -->
  39. <property name="pubSubDomain" value="false" />
  40. <property name="messageConverter" ref="jmsMessageConverter"></property>
  41. </bean>
  42. <!-- 定义JmsTemplate的Topic类型 -->
  43. <bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
  44. <constructor-arg ref="jmsConnectionFactoryExtend" />
  45. <!-- pub/sub模型(发布/订阅) -->
  46. <property name="pubSubDomain" value="true" />
  47. <property name="messageConverter" ref="jmsMessageConverter"></property>
  48. </bean>
  49. <bean class="com.lote.wms.common.core.mq.QueueProducer" />
  50. <bean class="com.lote.wms.common.core.mq.TopicProducer" />
  51. <!--Spring JmsTemplate 的消息生产者 end -->
  52. <bean id="jmsListenerContainerFactory"
  53. class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
  54. <property name="connectionFactory" ref="jmsConnectionFactoryExtend" />
  55. </bean>
  56. </beans>