java - 无法在 RabbitMQ 接收器中将 content_type 从 application/octet-stream 更改为 application/json
问题描述
我有一个简单的 RabbitMQ 源和接收器。我正在向具有以下属性的源队列发布一条消息:
content_type -> application/json
和一个 JSON 有效负载:
{
"userId": 2,
"customerId": 1,
}
RabbitMQ 接收器使用application/octet-stream
而不是 JSON 来获取消息。
我尝试使用以下属性启动应用程序:
spring.cloud.stream.default.contentType=application/json
但这没有帮助。
流定义:
stream_1=rabbitSource: rabbit --queues=queue1 --password=p --host=h --username=u | sink: rabbit --exchange=ex --routing-key=rk --converter-bean-name=jsonConverter --password=p --host=h --username=u
如何将内容类型设置为application/json
?参考指南似乎没有答案。
发布版本:
- spring-cloud-dataflow-server:2.0.1.RELEASE
- spring-cloud-skipper-server:2.0.0.RELEASE
更新:
正如@SabbyAnandan 的答案所建议的那样,我现在正在运行:
dataflow:>stream create --name test123 --definition "rabbitSource: rabbit --queues=queue --password=p --host=rmq --username=u --spring.cloud.stream.bindings.output.contentType='application/json' | sink: rabbit --exchange=ex --routing-key=rk --converter-bean-name=jsonConverter --password=p --host=rmq --username=p"
Created new stream 'test123123'
dataflow:>stream deploy --name test123 --properties "app.rabbit.spring.cloud.stream.bindings.output.contentType='application/json'"
Deployment request has been sent for stream 'test123'
但是content_type
还是一样的。
解决方案
在 Rabbit-source 的标头中设置的默认内容类型是:content-type: application/x-java-serialized-object
.
您可以通过传递来覆盖该行为:
1)--spring.cloud.stream.bindings.output.contentType='application/json'
作为 Rabbit 源的内联属性。
2) 在部署流时,您可以通过--properties="app.rabbit.spring.cloud.stream.bindings.output.contentType='application/json'
.
http://<APP-HOST>:<APP-PORT?/actuator/configprops
部署后,您可以通过转到特定于应用程序的端点来确认该属性是否被覆盖。
java -jar..
要解决所有这些问题,您可以在通过 SCDF运行应用程序之前独立运行应用程序(即)以确认行为。如果它独立工作,它也应该在 SCDF 中工作。
推荐阅读
- racket - 如何在球拍中使用带有变量的地图函数(定义)
- select - .net 核心中的 react-select 库依赖项
- spring-cloud-gateway - Spring Cloud Gateway 返回“索引 5 处的方案名称中的非法字符”
- azure-devops - ado yaml:是否可以在每次运行的基础上选择执行哪个阶段的作业?
- javascript - 通过 Flask 缓存或 POST 请求更改执行实时更新
- c# - 试图在我的游戏中实现缩放功能,但它不会取消缩放
- excel - 如何同时使用 `FileSystemObject.CreateFolder` 创建文件夹和子文件夹
- html - 填充动态 flexbox 或网格中剩余的空白行空间
- python - 如何从 mssql 表中加载列表?
- java - Spring-Boot:不尊重 Jackson 序列化配置