带有春季集成的MQTT标题

发布于 2025-02-05 21:07:58 字数 751 浏览 1 评论 0 原文

我正在使用春季集成的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 )。

我做错了吗?

提前致谢。

I'm using MQTT with Spring Integration.

I would like to include a contentType header in the MQTT message.

I'm writing to the MQTT broker in this way:

  @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();
  }

When I see the MQTT messages in RabbitMQ I see this:

enter image description here

This is, it seems that content type header is not being included in the message (only x-mqtt-dup and x-mqtt-publish-qos).

Am I doing something wrong?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清旖 2025-02-12 21:07:58

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.

街角卖回忆 2025-02-12 21:07:58

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文