Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active May 25, 2021 12:34
Show Gist options
  • Select an option

  • Save rponte/bb849d74098d72afa7a950accb0db0b3 to your computer and use it in GitHub Desktop.

Select an option

Save rponte/bb849d74098d72afa7a950accb0db0b3 to your computer and use it in GitHub Desktop.
Micronaut: mixing @transaction with gRPC Endpoint methods
@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
}
@rponte
Copy link
Author

rponte commented Mar 26, 2021

@rponte
Copy link
Author

rponte commented Mar 31, 2021

@rponte
Copy link
Author

rponte commented May 25, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment