gpt4 book ai didi

azure - 如何从 Spring JMS 设置 Azure ServiceBus 的 ContentType

转载 作者:行者123 更新时间:2023-12-02 23:11:36 25 4
gpt4 key购买 nike

我正在尝试使用库azure-servicebus-jms-spring-boot-starter向主题发送消息。一切正常,但是消息以 application/xml 类型存储在订阅中,我找不到如何正确设置它以将它们存储为 application/json 的方法。我已尝试将消息转换器配置为按照描述发送 ContentType here但这也行不通。

  @Bean
public MessageConverter jacksonJmsMessageConverter() {
final MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(){
@Override
protected TextMessage mapToTextMessage(Object object, Session session, ObjectWriter objectWriter)
throws JMSException, IOException {
final TextMessage message = super.mapToTextMessage(object, session, objectWriter);
message.setStringProperty("ContentType", "application/json");
return message;
}
};
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
converter.setObjectMapper(objectMapper);
return converter;
}

message

最佳答案

没有公开的方法可以设置从 Qpid JMS 客户端发送的消息的内容类型。客户端本身使用此字段作为 JMS 映射到 AMQP 的一部分,以区分其发送的某些消息类型并确定在接收时应将某些消息呈现为什么。

技术上可以使用反射来获取,因此您必须从 JmsMessageFacade 类使用的 API 的值不是公开的,并且可能会随着任何版本的发布而改变,因此选择这样做会带来巨大的风险。

关于azure - 如何从 Spring JMS 设置 Azure ServiceBus 的 ContentType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65938223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com