RabbitConfig.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.huaxu.zoniot.config;
  2. import org.springframework.amqp.core.*;
  3. import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
  4. import org.springframework.amqp.rabbit.connection.ConnectionFactory;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. /**
  10. * <p>RabbitMQ配置</p>
  11. *
  12. * @Author wilian.peng
  13. * @Date 2020/4/7 11:50
  14. * @Version 1.0
  15. */
  16. @Configuration
  17. public class RabbitConfig {
  18. @Value("${spring.rabbitmq.exchange}")
  19. private String exchange;
  20. @Value("${spring.rabbitmq.device.queue}")
  21. private String deviceQueue;
  22. @Value("${spring.rabbitmq.community.queue}")
  23. private String communityQueue;
  24. @Value("${spring.rabbitmq.building.queue}")
  25. private String buildingQueue;
  26. //创建队列
  27. @Bean
  28. public Queue createDeviceQueue() {
  29. return new Queue(deviceQueue);
  30. }
  31. //创建队列
  32. @Bean
  33. public Queue createCommunityQueue() {
  34. return new Queue(communityQueue);
  35. }
  36. //创建队列
  37. @Bean
  38. public Queue createBuildingQueue() {
  39. return new Queue(buildingQueue);
  40. }
  41. //创建交换机
  42. @Bean
  43. public TopicExchange exchange() {
  44. return new TopicExchange(exchange);
  45. }
  46. //对列绑定并关联到ROUTINGKEY
  47. @Bean
  48. Binding bindingDeviceExchangeMessage(Queue createDeviceQueue, TopicExchange exchange) {
  49. return BindingBuilder.bind(createDeviceQueue).to(exchange).with(deviceQueue);
  50. }
  51. //对列绑定并关联到ROUTINGKEY
  52. @Bean
  53. Binding bindingCommunityExchangeMessage(Queue createCommunityQueue, TopicExchange exchange) {
  54. return BindingBuilder.bind(createCommunityQueue).to(exchange).with(communityQueue);
  55. }
  56. //对列绑定并关联到ROUTINGKEY
  57. @Bean
  58. Binding bindingBuildingExchangeMessage(Queue createBuildingQueue, TopicExchange exchange) {
  59. return BindingBuilder.bind(createBuildingQueue).to(exchange).with(buildingQueue);
  60. }
  61. }