How to setup ContentType for Azure ServiceBus from Spring JMS

ε祈祈猫儿з 提交于 2021-02-11 12:24:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!