Home > Back-end >  Spring - integration - what MQTT polling switches support consumers
Spring - integration - what MQTT polling switches support consumers

Time:03-02

Led package

Org. Springframework. Integration
Spring - integration - mqtt
5.1.3. RELEASE


Org. Eclipse. Paho
Org. Eclipse. Paho. Client. Mqttv3 & lt;/artifactId>
1.2.0 & lt;/version>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- code
@ Configuration
Public class W1_sub {

The @autowired
Private MqttConfig MqttConfig;

Private String topic="water/smartt200_up";
//private String topic="sm_xfc_topic";
@ Bean
Public MqttPahoClientFactory mqttClientFactory_w1 () {
DefaultMqttPahoClientFactory factory=new DefaultMqttPahoClientFactory ();
Factory. SetServerURIs (mqttConfig getServers ());
Return the factory.
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * w1_0
@ Bean
Public MessageChannel iotMqttInputChannel () {
Return new DirectChannel ();
//return new PublishSubscribeChannel ();
}

@ Bean
Public MessageProducer the inbound () {
MqttPahoMessageDrivenChannelAdapter adapter=new MqttPahoMessageDrivenChannelAdapter (MqttAsyncClient generateClientId (), mqttClientFactory_w1 (), topic);
Adapter. SetCompletionTimeout (5000);
Adapter. SetConverter (new DefaultPahoMessageConverter ());
Adapter. SetQos (0);
Adapter. SetOutputChannel (iotMqttInputChannel ());
Return the adapter.
}
@ Bean
@ ServiceActivator (inputChannel="iotMqttInputChannel")
Public MessageHandler handlerTest () {
The return message - & gt; {
Try {
String String=message. GetPayload (). The toString ();
System. The out. Println (" w1_1: "+ string);
{} the catch (MessagingException ex)
//logger. The info (ex. GetMessage ());
}
};
}


//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@ Bean
Public MessageChannel iotMqttInputChannel_w1_2 () {
Return new DirectChannel ();
//return new PublishSubscribeChannel ();
}

@ Bean
Public MessageProducer inbound_w1_2 () {
MqttPahoMessageDrivenChannelAdapter adapter=new MqttPahoMessageDrivenChannelAdapter (MqttAsyncClient generateClientId (), mqttClientFactory_w1 (), topic);
Adapter. SetCompletionTimeout (5000);
Adapter. SetConverter (new DefaultPahoMessageConverter ());
Adapter. SetQos (0);
Adapter. SetOutputChannel (iotMqttInputChannel_w1_2 ());
Return the adapter.
}

@ Bean
@ ServiceActivator (inputChannel="iotMqttInputChannel_w1_2")
Public MessageHandler handler_w1_2 () {
The return message - & gt; {
Try {
String String=message. GetPayload (). The toString ();
System. The out. Println (" W1_2: "+ string);
{} the catch (MessagingException ex)
//logger. The info (ex. GetMessage ());
}
};
}
}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
reported results data
W1_1: {
"Dev_name" : "Csmartt200,"
"Varible" : {
"DCD4. DCSW_WD0_R0" : "0.000000",
"DCD4. DCSW_WD0_R1" : "429961.000000",
"DCD4. DCSW_WD0_R2" : "0.000000",
"DCD4. DCSW_WD0_R3" : "0.000000",
"DCD4. DCSW_WD0_R4" : "0.000000",
"DCD4. DCSW_WD0_R5" : "194956.000000",
"DCD4. DCSW_WD0_R6" : "0.000000",
"DCD4. DCSW_WD0_R7" : "3.000000",
"DCD4. DCSW_WD0_R8" : "0.000000",
"DCD4. DCSW_WD0_R9" : "0.000000",
"DCD4. DCSW_WD0_R10" : "0.000000",
"DCD4. DCSW_WD0_R11" : "0.000000",
"DCD4. DCSW_WD0_R12" : "0.000000",
"DCD4. DCSW_WD0_R13" : "1.000000",
"DCD4. DCSW_WD0_R14" : "171524.000000"
},
"Up_time" : "20210301124825856"
}
W1_2: {
"Dev_name" : "Csmartt200,"
"Varible" : {
"DCD4. DCSW_WD0_R0" : "0.000000",
"DCD4. DCSW_WD0_R1" : "429961.000000",
"DCD4. DCSW_WD0_R2" : "0.000000",
"DCD4. DCSW_WD0_R3" : "0.000000",
"DCD4. DCSW_WD0_R4" : "0.000000",
"DCD4. DCSW_WD0_R5" : "194956.000000",
"DCD4. DCSW_WD0_R6" : "0.000000",
"DCD4. DCSW_WD0_R7" : "3.000000",
"DCD4. DCSW_WD0_R8" : "0.000000",
"DCD4. DCSW_WD0_R9" : "0.000000",
"DCD4. DCSW_WD0_R10" : "0.000000",
"DCD4. DCSW_WD0_R11" : "0.000000",
"DCD4. DCSW_WD0_R12" : "0.000000",
"DCD4. DCSW_WD0_R13" : "1.000000",
"DCD4. DCSW_WD0_R14" : "171524.000000"
},
"Up_time" : "20210301124825856"
}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
problemDescription: "DCD4 DCSW_WD0_R14" : "171524.000000" this is the batch number increasing value, two consumers received message
the batchOfficially: using direct switches multiple subscribers is polling mechanism, but the test is not found, do not know how to solve?
  • Related