DisconnectedMqttConfiguration.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.xy.consumer.disconnect;
  2. import com.xy.configuration.MqttConfigUtils;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.integration.annotation.IntegrationComponentScan;
  6. import org.springframework.integration.annotation.ServiceActivator;
  7. import org.springframework.integration.channel.DirectChannel;
  8. import org.springframework.integration.core.MessageProducer;
  9. import org.springframework.messaging.MessageChannel;
  10. import org.springframework.messaging.MessageHandler;
  11. @Configuration
  12. @IntegrationComponentScan
  13. public class DisconnectedMqttConfiguration {
  14. /**
  15. * topic
  16. */
  17. public final static String TOPIC = "disConnectedNotify";
  18. /**
  19. * 入站通道名(消费者)订阅的bean名称
  20. */
  21. public static final String CHANNEL_NAME_IN = TOPIC + "MqttInboundChannel";
  22. /*******************************消费者*******************************************/
  23. /**
  24. * MQTT信息通道(消费者)
  25. */
  26. @Bean(name = CHANNEL_NAME_IN)
  27. public MessageChannel mqttInboundChannel() {
  28. return new DirectChannel();
  29. }
  30. /**
  31. * MQTT消息订阅绑定(消费者)
  32. */
  33. @Bean(name = TOPIC + "Inbound")
  34. public MessageProducer inbound() {
  35. return MqttConfigUtils.inbound(TOPIC, mqttInboundChannel());
  36. }
  37. /**
  38. * MQTT消息处理器(消费者)
  39. */
  40. @Bean(name = TOPIC + "Handler")
  41. @ServiceActivator(inputChannel = CHANNEL_NAME_IN)
  42. public MessageHandler handler() {
  43. return MqttConfigUtils.handler();
  44. }
  45. }