简体   繁体   中英

Spring Boot JMS MarshallingMessageConverter in replies

I've a JMS listener similar to the one done here:

Synchronous Message send and receive using JMS template and Spring Boot

It receives a XML payload. But different from that one, I want to also return a reply. If I return a String, it works ok, but as I'm doing with the message payload, I want to return a JAXB object.

However, if I return a Message, Spring tries to convert the object using the SimpleMessageConverter.

How can I configure the MarshallingMessageConverter to be used when converting the reply payload?

I had to configure the DefaultJmsListenerContainerFactory's message converter.

But what is weird, I already have a MarshallingMessageConverter there for DefaultMessageHandlerMethodFactory and JmsMessagingTemplate, and it's from another Java package (org.springframework.messaging.converter.MarshallingMessageConverter).

@Bean
public JmsListenerContainerFactory<?> jmsListenerFactory(ConnectionFactory connectionFactory,
    DefaultJmsListenerContainerFactoryConfigurer configurer)
{
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setErrorHandler(errorHandler());
    factory.setMessageConverter(jmsMarshallingMessageConverter());  // !!!!

    configurer.configure(factory, connectionFactory);

    return factory;
}

@Bean
public org.springframework.jms.support.converter.MarshallingMessageConverter jmsMarshallingMessageConverter()
{
    Jaxb2Marshaller marshaller = marshaller();

    org.springframework.jms.support.converter.MarshallingMessageConverter converter =
        new org.springframework.jms.support.converter.MarshallingMessageConverter();
    converter.setMarshaller(marshaller);
    converter.setUnmarshaller(marshaller);
    converter.setTargetType(MessageType.TEXT);

    return converter;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM