问题
I'm trying to use library azure-servicebus-jms-spring-boot-starter
to send messages to topic. Everything works, however messages are being stored in subscriptions as application/xml
type and I can't find the way how to setup this correctly to have them stored as application/json
.
I've tried to configure message converter to send ContentType
as described here but that doesn't work either.
@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;
}
回答1:
There is no exposed means of setting the content-type on the messages sent from the Qpid JMS client. The client itself uses this field as part of the JMS mapping to AMQP to distinguish certain message types that it sends and to determine at receive time what certain messages should be presented as.
It is technically possible to use reflection to reach in and so the value but the APIs you have to use from the JmsMessageFacade class are not public and could change with any release so choosing to do so comes with significant risk.
来源:https://stackoverflow.com/questions/65938223/how-to-setup-contenttype-for-azure-servicebus-from-spring-jms