Spring RabbitMQ连接,监听

<!-- 以下为全部rabbitmq监听配置 -->
	
	 <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
        <property name="username" value="guest" />
        <property name="password" value="guest" />
        <property name="host" value="192.168.0.140" />
        <property name="port" value="5672" />
    </bean> -->
    <!-- <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
        <property name="username" value="admin" />
        <property name="password" value="admin" />
        <property name="host" value="127.0.0.1" />
        <property name="port" value="5672" />
    </bean> -->

    <!-- <bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
        <constructor-arg ref="connectionFactory" />
    </bean>

    <bean id="serializerMessageConverter" class="org.springframework.amqp.support.converter.SimpleMessageConverter" />

  	  创建rabbitTemplate 消息模板类
    <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
        <constructor-arg ref="connectionFactory" />
        <property name="exchange" value="SendAlarm_Exchange_forjava" />
        <property name="routingKey" value="SendAlarm_Exchange_forjava" />
        <property name="queue" value="weixin_queue" />
        <property name="messageConverter" ref="serializerMessageConverter" />
    </bean>

    <bean id="queue" class="org.springframework.amqp.core.Queue">
        <constructor-arg index="0" value="weixin_queue"></constructor-arg>
        <constructor-arg index="1" value="true"></constructor-arg>
        <constructor-arg index="2" value="false"></constructor-arg>
        <constructor-arg index="3" value="false"></constructor-arg>
    </bean>
   
   
   
    <bean id="directExchange" class="org.springframework.amqp.core.DirectExchange">
        <constructor-arg index="0" value="routingKey"></constructor-arg>
        <constructor-arg index="1" value="true"></constructor-arg>
        <constructor-arg index="2" value="false"></constructor-arg>
    </bean>

    <util:map id="arguments"></util:map>

    <bean id="binding" class="org.springframework.amqp.core.Binding">
        <constructor-arg index="0" value="weixin_queue"></constructor-arg>
        <constructor-arg index="1" value="QUEUE"></constructor-arg>
        <constructor-arg index="2" value="SendAlarm_Exchange_forjava"></constructor-arg>
        <constructor-arg index="3" value="routingKey"></constructor-arg>
        <constructor-arg index="4" value="#{arguments}"></constructor-arg>
    </bean>
   
  
    <bean id="rmqConsumer" class="com.yeexun.rabbit.RmqConsumer" />
    <bean id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
        <constructor-arg ref="rmqConsumer" />
        <property name="defaultListenerMethod" value="rmqConsumeMessage"></property>
        <property name="messageConverter" ref="serializerMessageConverter"></property>
    </bean>

    <bean id="listenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
        <property name="queues" ref="queue"></property>
        <property name="connectionFactory" ref="connectionFactory"></property>
        <property name="messageListener" ref="messageListenerAdapter"></property>
    </bean> 
weixin_queue标识队列名称
SendAlarm_Exchange_forjava标识exchange


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值