带有春季集成的MQTT标题
我正在使用春季集成的MQTT。
我想在MQTT消息中包括一个ContentType标头。
我正在以这种方式写信给MQTT经纪人:
@Bean
public IntegrationFlow outgoingMqttMsgFlow() {
return IntegrationFlows.from("outgoingMqttMsgChannel")
.enrichHeaders(headers -> headers.header(MqttHeaders.TOPIC, mqttTopic))
.enrichHeaders(headers -> headers.header(MessageHeaders.CONTENT_TYPE, "usp.msg", true))
.handle(new MqttPahoMessageHandler(mqttBroker, UUID.randomUUID().toString())).get();
}
当我在Rabbitmq中看到MQTT消息时,我会看到:
这是,似乎没有包含内容类型的标题 x-mqtt-dup
和 x-mqtt-publish-qos
)。
我做错了吗?
提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MQTT V3没有“标头”的概念;这些标题只是RabbitMQ MQTT插件来处理QoS的机制。
您需要以某种方式将内容类型嵌入有效载荷中。
MQTT v3 has no concept of "headers"; those headers are just the rabbitmq MQTT plugin's mechanism to handle QOS.
You would need to embed the content type in the payload somehow.
MQTT没有标题,而是属性,但它们代表了类似的概念。
自版V5以来,支持MQTT属性。
如果您想能够将弹簧集成标头映射到MQTT属性中,则必须使用
MQTTV5PAHOMESSAGEHANDLER
。最后,考虑到兔子不支持MQTT V5,它都不支持MQTT属性。改用蚊子。
MQTT does not have headers but properties, but they represent a similar concept.
MQTT properties are supported since version v5.
If you want to be able to map Spring Integration headers into MQTT properties you have to use
Mqttv5PahoMessageHandler
.There is an example in https://docs.spring.io/spring-integration/reference/html/mqtt.html
Finally, take into account that since RabbitMQ does not support MQTT v5, it neither supports MQTT properties. Use Mosquitto instead.