spring-stream 使用 "text/plain" content-type 而不是 "application/json" 发送消息

The spring-stream sends a message with "text/plain" content-type instead of "application/json"

我想在我的 queue 上生成内容类型为 application/json 的响应,因为负载包含 json object。

但是...

不知道为什么我的 spring-stream(基于 RabbitMQ)总是生成以下 headers 的消息(有效负载是正确的并且具有 JSON 形式)。

(view from rabbit ui)
properties:
    delivery_mode:  2
    headers:    
      contentType:  text/plain
      originalContentType:  application/json;charset=UTF-8
    content_type:   text/plain

所以 content_type 等于 text/plain 而不是 application/json;charset=UTF-8.

我试过在如下配置中设置 content-type

spring:
  cloud:
    stream:
      default:
        content-type: application/json
      bindings:
        my-channel:
          content-type: application/json
          destination: my-channel-rs
          producer:
            exchange-type: direct
            max-length: 1000

但没有帮助。

我觉得在正确的响应中,单个 header content-type 应该存在且值为 "application/json"。

但也许我错了?有人能解释以上行为吗?

看来您使用的是 1.3 版本的 S-C-Stream。能否请你确认?我们当然可以看看。 此外,FWIW,只要您有一个消费者是 SCSt 应用程序(因为它将被重置为您期望的),整个 'originalContentType' 问题就不是问题,但我假设它不是,正确的?

此外,您可以随时升级到 2.0.0.M3。 contentType 分辨率方面有很多改进。

我遇到了类似的问题。我需要底层 spring-amqp 来使用 "content-type" header 来设置实际的内容类型。 Spring-amqp 通过检查消息有效负载的 class 来计算,而不考虑 "content-type" header。

我创建了一个可能会或可能不会被接受的拉取请求:https://github.com/spring-projects/spring-amqp/pull/763/commits/25e4f9adf523a802ac5f26dd373eff8bb764fb49