0
votes

The DefaultMessageListenerContainer class in spring JMS has the setter method setMessageConverter(...) which allows to supply any converter we want.

For an annotated message listener, this makes sense as we can directly define

@JmsListener(destination = "myDestination")
public void processOrder(MyConvertedType data) { ... }

and spring will take care of converting and passing the message to this listener.

So, this clearly makes sense for an annotated listener. My question is, is setting a message converter useful for non-annotated message listeners? Something like

public void registerListener(String queueName, MessageListener listener) {
        DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setMessageConverter(getMessageConverter());
        container.setDestinationName(queueName);
        container.setMessageListener(listener);
        container.initialize();
        container.start();
}

From my search in the docs/javadocs and the limited understanding of source code, I think that setting a message converter for this case is not helpful, i.e. message conversion will not handled by spring. The conversion has to be handled in the passed MessageListener callback? Correct me if I am wrong.

1

1 Answers

2
votes

It's used only when the container is created to support a @JmsListener annotation - the converter is transferred from the container factory to the container, and thence to the MessagingMessageListenerAdapter which is used to invoke the annotated POJO method.

The container is just a conduit to configure the adapter via the container factory.

So, yes, it's ignored for a simple MessageListener.