[英]SI subscription to multiple mqtt topics
I'm trying to learn how to handle MQTT Messages in Spring-Integration . 我正在尝试学习如何在Spring-Integration中处理MQTT消息 。 Have created a converter, that subscribes with a single MqttPahoMessageDrivenChannelAdapter per MQTT Topic for consuming and converting the messages. 已创建一个转换器,每个MQTT主题都订阅一个MqttPahoMessageDrivenChannelAdapter来转换和使用消息。
The problem is our data provider is planning to "speed-up" publishing messages on his side. 问题在于我们的数据提供商正计划“加快”他一方的发布消息。 So instead of having a few(<=10) topics each of which has messages with about 150 fields it is planned to publish each of those fields to the separate MQTT topic. 因此,计划将每个字段都发布到单独的MQTT主题,而不是只包含几个主题(<= 10),每个主题都具有包含约150个字段的消息。
This means my converter would have to consume ca. 这意味着我的转换器将不得不消耗约。 1000 mqtt topics, but I do not know whether: 1000个mqtt主题,但我不知道是否:
Thanks in advance for your answers! 预先感谢您的回答!
I think your idea makes sense. 我认为您的想法很有道理。
For that purpose you need to implement a passthrough MqttMessageConverter
and provide an MqttMessage
as a payload
and topic
as a header: 为此,您需要实现直通 MqttMessageConverter
并提供MqttMessage
作为payload
,并提供topic
作为标头:
public class PassThroughMqttMessageConverter implements MqttMessageConverter {
@Override
public Message<?> toMessage(String topic, MqttMessage mqttMessage) {
return MessageBuilder.withPayload(mqttMessage)
.setHeader(MqttHeaders.RECEIVED_TOPIC, topic)
.build();
}
@Override
public Object fromMessage(Message<?> message, Class<?> targetClass) {
return null;
}
@Override
public Message<?> toMessage(Object payload, MessageHeaders headers) {
return null;
}
}
So, you really will be able to perform a target conversion downstream, after a mentioned ExecutorChannel
in the custom transformer
. 因此,在自定义transformer
ExecutorChannel
中提到了ExecutorChannel
之后,您实际上将能够在下游执行目标转换。
You also may consider to implement a custom MqttPahoClientFactory
(an extension of the DefaultMqttPahoClientFactory
may work as well) and provide a custom ScheduledExecutorService
to be injected into the MqttClient
you are going create in the getClientInstance()
. 您还可以考虑实现自定义MqttPahoClientFactory
( DefaultMqttPahoClientFactory
的扩展也可以工作),并提供一个自定义ScheduledExecutorService
注入到要在getClientInstance()
创建的MqttClient
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.