一、生产端(Producer)

applicationContext.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"
       xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- 真正可以产生Connection的ConnectionFactory,由对应的 JMS服务厂商提供 -->
    <bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://192.168.137.1:61616" />
        <property name="userName" value="afeng" />
        <property name="password" value="111111" />
    </bean>

    <!-- Spring用于管理真正的ConnectionFactory的ConnectionFactory -->
    <bean id="connectionFactory"
          class="org.springframework.jms.connection.SingleConnectionFactory">
        <!-- 目标ConnectionFactory对应真实的可以产生JMS Connection的ConnectionFactory -->
        <property name="targetConnectionFactory" ref="targetConnectionFactory" />
    </bean>


    <!-- 定义JmsTemplate的Queue类型 -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <constructor-arg ref="connectionFactory"/>
        <!-- 非pub/sub模型(发布/订阅),即队列模式 -->
        <property name="pubSubDomain" value="false"/>
    </bean>

    <bean id="queueSender" class="com.afeng.utils.activeMq.QueueSender">
        <property name="JmsTemplate" ref="jmsTemplate"/>
    </bean>

    <!-- 定义JmsTemplate的Topic类型 -->
    <bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
        <!-- 这个connectionFactory对应的是我们定义的Spring提供的那个ConnectionFactory对象 -->
        <constructor-arg ref="connectionFactory"/>
        <!-- pub/sub模型(发布/订阅) -->
        <property name="pubSubDomain" value="true"/>
    </bean>

    <bean id="topicSender" class="com.afeng.utils.activeMq.TopicSender">
        <property name="jmsTemplate" ref="jmsTopicTemplate"/>
    </bean>

</beans>
View Code

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-10-25
  • 2022-01-05
  • 2022-01-05
  • 2021-06-24
  • 2021-10-08
猜你喜欢
  • 2021-09-18
  • 2021-06-15
  • 2021-12-04
  • 2021-11-25
  • 2022-01-25
  • 2021-06-29
相关资源
相似解决方案