Open
Description
Bug report
I am experiecing weird behavior when using SimpleRoutingConnectionFactory together with RabbitTemplate with filled sendConnectionFactorySelectorExpression
. Then usage with @Transactional
method, message has been sent immediately just like without any open transaction
var connectionFactory = new SimpleRoutingConnectionFactory();
// + setup some connections e.g. with key/lookup "someLookup"
RabbitTemplate rabbitTemplate = new RabbitTemplate();
rabbitTemplate.setConnectionFactory(connectionFactory());
rabbitTemplate.setChannelTransacted(true);
var expression = exprParser.parseExpression("someLookup");
rabbitTemplate.setSendConnectionFactorySelectorExpression(expression);
@GetMapping("/test/rabbitmq")
@Transactional
public String rabbitTest() {
rabbitTemplate.convertAndSend(MessagingConfig.EXCHANGE, MessagingConfig.RT, new MessageDto(1L, TenantContext.getTenantId()));
System.out.println("breakpoint - in this point message is already sent");
return "ok";
}
I am using this construct for publishing instead of SimpleResourceHolder.bind
Imo it is caused in RabbitTemplate, when creating channel - method obtainTargetConnectionFactory
is used to obtain connection (this method takes into account sendConnectionFactorySelectorExpression
) but then, when "transaction" context is evaluated, simple getter getConnectionFactory
is used