Last active
May 25, 2021 12:34
-
-
Save rponte/bb849d74098d72afa7a950accb0db0b3 to your computer and use it in GitHub Desktop.
Micronaut: mixing @transaction with gRPC Endpoint methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Singleton | |
| open class CreateProposalEndpoint(@Inject val repository: ProposalRespository) : ProposalGrpcServiceGrpc.ProposalGrpcServiceImplBase() { | |
| @Transactional // starts the current transaction | |
| open override fun create(request: CreateProposalRequest, responseObserver: StreamObserver<CreateProposalResponse>) { | |
| val proposal = repository.save(request.toModel()) // with Hibernate, the INSERT may not be flushed here | |
| // returns to the client without waiting for the commit | |
| responseObserver.onNext(CreateProposalResponse.newBuilder().build()) | |
| responseObserver.onCompleted() | |
| } // WARNING: the current transaction is only commited (and flushed) here | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Micronaut Data Transactions with R2DBC