micronaut-data
micronaut-data copied to clipboard
Transaction propagation breaks when io.micrometer#context-propagation added to classpath
Expected Behavior
When io.micrometer#context-propagation is added to the classpath, transaction propagation should still work. As this is frequently referenced as how we need to support context propagation (for example sharing MDC, OTEL, etc)
Actual Behaviour
For a simple new application connecting to a postgres testcontainer, when context-propagation is NOT added, then the simple test case listed below works. However, if io.micrometer#context-propagation is added, then we get an error as it is unable to lookup a transaction:
Rolling back transaction on error: Expected an existing transaction, but none was found in the Reactive context.
io.micronaut.transaction.exceptions.NoTransactionException: Expected an existing transaction, but none was found in the Reactive context.
at io.micronaut.transaction.support.AbstractReactorTransactionOperations.expectedTransaction(AbstractReactorTransactionOperations.java
Steps To Reproduce
New project created via the launcher, with "data-r2dbc" and "postgres" added. Create a controller with "@Transation" annotation, that calls a service with "@Transaction(MANDATORY)" that simply returns an explicit Mono
@Controller
public static class SimpleController {
@Inject MyService service;
@Get("/hello")
@Transactional
public Publisher<String> hello() {
return service.getMessage();
}
}
@Singleton
public static class MyService {
@Transactional(Transactional.TxType.MANDATORY)
public Mono<String> getMessage() {
return Mono.just("hello");
}
}
Hit the /hello endpoint, and you get the server exception listed above.
Environment Information
Windows/Unix
Example Application
https://github.com/turneand/micronaut-transactional-propagation/blob/main/src/main/java/com/example/Application.java
Version
4.3.5