12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package com.huaxu.zoniot.config;
- import org.springframework.amqp.core.*;
- import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
- import org.springframework.amqp.rabbit.connection.ConnectionFactory;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- /**
- * <p>RabbitMQ配置</p>
- *
- * @Author wilian.peng
- * @Date 2020/4/7 11:50
- * @Version 1.0
- */
- @Configuration
- public class RabbitConfig {
- @Value("${spring.rabbitmq.exchange}")
- private String exchange;
- @Value("${spring.rabbitmq.device.queue}")
- private String deviceQueue;
- @Value("${spring.rabbitmq.community.queue}")
- private String communityQueue;
- @Value("${spring.rabbitmq.building.queue}")
- private String buildingQueue;
- //创建队列
- @Bean
- public Queue createDeviceQueue() {
- return new Queue(deviceQueue);
- }
- //创建队列
- @Bean
- public Queue createCommunityQueue() {
- return new Queue(communityQueue);
- }
- //创建队列
- @Bean
- public Queue createBuildingQueue() {
- return new Queue(buildingQueue);
- }
- //创建交换机
- @Bean
- public TopicExchange exchange() {
- return new TopicExchange(exchange);
- }
- //对列绑定并关联到ROUTINGKEY
- @Bean
- Binding bindingDeviceExchangeMessage(Queue createDeviceQueue, TopicExchange exchange) {
- return BindingBuilder.bind(createDeviceQueue).to(exchange).with(deviceQueue);
- }
- //对列绑定并关联到ROUTINGKEY
- @Bean
- Binding bindingCommunityExchangeMessage(Queue createCommunityQueue, TopicExchange exchange) {
- return BindingBuilder.bind(createCommunityQueue).to(exchange).with(communityQueue);
- }
- //对列绑定并关联到ROUTINGKEY
- @Bean
- Binding bindingBuildingExchangeMessage(Queue createBuildingQueue, TopicExchange exchange) {
- return BindingBuilder.bind(createBuildingQueue).to(exchange).with(buildingQueue);
- }
- }
|