Related to How do we hook into before/After message processing using @RabbitListener
If I want to configure RabbitTemplate globally and set MessagePostProcessor
, what is the best way?
- Should I copy the bean definition from
RabbitAutoConfiguration
? - Or should I intercept the bean definition using
BeanPostProcessor
?
The problem with first solution is that,
RabbitTemplate in RabbitAutoConfiguration
is not just bounding the properties to the bean instance but also set message converts:
MessageConverter messageConverter = this.messageConverter.getIfUnique();
if (messageConverter != null) {
template.setMessageConverter(messageConverter);
}
So, should I duplicate this logic as follows, or just follow the second option of BeanPostProcessor
as in Sleuth?
@ConfigurationProperties(prefix = "spring.rabbitmq.template")
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory,
ObjectProvider<MessageConverter> messageConverterObjectProvider) {
RabbitTemplate template = new RabbitTemplate(connectionFactory);
MessageConverter messageConverter = messageConverterObjectProvider.getIfUnique();
if (messageConverter != null) {
template.setMessageConverter(messageConverter);
}
template.setBeforePublishPostProcessors(myBeforePublishMPP());
return template;
}