How is it possible to define a transaction for a complete flow in spring integration (Java DSL)?
With Spring integration we can define an example flow with:
@Bean
public IntegrationFlow myMessageFromMessageAmqpInboundFlow() {
return IntegrationFlows.from(myInboundChannel)
.transform(aMessageTransformer)
.transform(anotherMessageTransformer)
.channel(anOutputChannel)
.get();
}
I need a transaction which overspans the complete flow. Currently, when I access a database with 'aMessageTransformer', the transaction will be closed after this message transformer has been processed. But I need a transaction which is still uncommitted when processing 'anotherMessageTransformer'?
I expected that I just have to add a '@Transactional' (or @Transactional(propagation = Propagation.REQUIRED, readOnly = true))
@Bean
@Transactional
public IntegrationFlow myMessageFromMessageAmqpInboundFlow() {
return IntegrationFlows.from(myInboundChannel)
.transform(aMessageTransformer)
.transform(anotherMessageTransformer)
.channel(anOutputChannel)
.get();
}
but this leads to a 'no session exception' in 'anotherMessageTransformer'