mq推送消息
场景:BDM(实名制系统)同步数据到CRNS(实名制系统)
一,首先建个队列,队列名字为 bdm_empolyeeinfo_crns
二,applicationContext-rabbitmq.xml增加配置
<!--同步BDM员工到实名制start--> <task:executor id="baseEmpolyeeToCRNSTaskExecutor" pool-size="4-256" queue-capacity="128"/> <bean id="baseEmployeeToCRNSRabbitConnectionFactory" class="com.rabbitmq.client.ConnectionFactory"> <property name="host" value="${rabbitmq.baseEmployeeToCRNS.host}"/> <property name="port" value="${rabbitmq.baseEmployeeToCRNS.port}"/> <property name="username" value="${rabbitmq.baseEmployeeToCRNS.username}"/> <property name="password" value="${rabbitmq.baseEmployeeToCRNS.password}"/> <property name="virtualHost" value="${rabbitmq.baseEmployeeToCRNS.VirtualHost}"/> </bean> <bean id="baseEmpolyeeToCRNSRabbitConnFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"> <constructor-arg ref="baseEmployeeToCRNSRabbitConnectionFactory"/> <property name="channelCacheSize" value="25"/> <property name="executor" ref="baseEmpolyeeToCRNSTaskExecutor"/> </bean> <!--通过指定下面的admin信息,当前producer中的exchange和queue会在rabbitmq服务器上自动生成 --> <rabbit:admin connection-factory="baseEmpolyeeToCRNSRabbitConnFactory"/> <bean id="baseEmployeeToCRNSRabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate"> <constructor-arg ref="baseEmpolyeeToCRNSRabbitConnFactory"></constructor-arg> <property name="exchange" value="${rabbitmq.baseEmployeeToCRNS.ExchangeName}"/> </bean> <rabbit:queue name="${rabbitmq.baseEmployeeToCRNS.QueueName}" durable="${rabbitmq.baseEmployeeToCRNS.QueueDurable}" auto-delete="false" exclusive="false"/> <rabbit:fanout-exchange name="${rabbitmq.baseEmployeeToCRNS.ExchangeName}" durable="${rabbitmq.baseEmployeeToCRNS.ExchangeDurable}" auto-delete="false"> <rabbit:bindings> <!-- 员工同步 --> <rabbit:binding queue="${rabbitmq.baseEmployeeToCRNS.QueueName}"></rabbit:binding> </rabbit:bindings> </rabbit:fanout-exchange> <!--同步BDM员工到实名制end-->
三,config-rabbitmq.properties增加配置
############################ base 员工 rabitmq 推送 crns-start######################################
rabbitmq.baseEmployeeToCRNS.host=172.16.37.2
rabbitmq.baseEmployeeToCRNS.port=5672
rabbitmq.baseEmployeeToCRNS.username=test
rabbitmq.baseEmployeeToCRNS.password=123abc
rabbitmq.baseEmployeeToCRNS.HostName=rabbitmq1.rabbit.com
rabbitmq.baseEmployeeToCRNS.VirtualHost=test
rabbitmq.baseEmployeeToCRNS.AutomaticRecoveryEnabled=true
rabbitmq.baseEmployeeToCRNS.deliveryMode=2
rabbitmq.baseEmployeeToCRNS.heartbeatTime=60
rabbitmq.baseEmployeeToCRNS.ExchangeName=bdm_crns
rabbitmq.baseEmployeeToCRNS.ExchangeDurable=true
rabbitmq.baseEmployeeToCRNS.ExchangeType=fanout
rabbitmq.baseEmployeeToCRNS.QueueName=bdm_empolyeeinfo_crns
rabbitmq.baseEmployeeToCRNS.QueueDurable=true
rabbitmq.baseEmployeeToCRNS.RoutingKey=ebill
############################ base 员工 rabitmq 推送 crns-end######################################
四,service
五,发送消息
六,查看发送的消息
愿你遍历山河
仍觉人间值得