0
votes

How do I define a MessageConverter for a destination using spring boot? I have already defined my message broker and JMS Listener.

@JmsListener(destination = "new.clinic.queue")
public void receiveNewClinic(MyCustomDTO message) {

}

and my message broker

@Bean
public BrokerService broker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName(brokerName);
    broker.addConnector(brokerAddress);
    return broker;
}

How do I add my own message converter for MyCustomDTO

1

1 Answers

4
votes

You need to create a JmsMessageContainerFactory and configure it accordingly. Spring Boot creates one for you but you can create as much instances as you want with your own customizations and refer them using the containerFactory of the @JmsListener annotation.

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
        ConnectionFactory connectionFactory) {
  DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
  factory.setConnectionFactory(connectionFactory);
  factory.setMessageConverter(yourMessageConverter());
  // .. other settings
  return factory;
}

Note that the bean name here is the default name so you don't need to specify a connectionFactory attribute.

Spring Boot 1.4 will auto-detect your MessageConverter and assign it to the default factory it auto-creates for you.