Spring 4 introduced org.springframework.messaging.support.MessageBuilder<T>
. And there is one existing org.springframework.integration.support.MessageBuilder<T>
in Spring Integration framework.
So when I am using Spring Integration with Spring 4, which message builder should I use and why?
Well, both of them produce the same type of Message
objects. So, no need to worry about the final result.
Anyway there is some tiny difference between them and for the Spring Websocket components it would be better to use org.springframework.messaging.support.MessageBuilder<T>
and for Spring Integration components - another one.
From other side the best practice is to build your application based on the POJO and MessageChannel
interaction. Having that you won't worry about builders at all, because you deal only with your domain.
Note: Spring Integration has built-in bean called messageBuilderFactory
, which produces MessageBuilder
by default. But you can override it to the MutableMessageBuilderFactory
and all Spring Integration components (IntegrationObjectSupport
extensions) will interact with MutableMessageBuilder
and MutableMessage
already.