I'm trying to run a gRPC server in our WildFly application to connect to from a client Java microservice using Quarkus.
I was able to set up a running server on port 9002 for gRPC where the client microservice can connect to.
When doing a call to the running gRPC service, I can see the rpc function is executed inside the WildFly application. I'm running into 2 issues however.
For the Server and Service setup, I used this code as an example.
Issues
- Dependency injection does not work in this service. The bean is created in WildFly but whatever object I @Inject into the gRPC Service, it always has a
nullvalue. - The server executes the code and replies with an appropriate gRPC message but this message never arrives at client side. No error is displayed whatsoever.
Does anyone have experience with these issues or knows if it is even possible to run a gRPC server within a WildFly application?
What I tried:
I tried to find an existing gRPC integration with WildFly but this is currently in the works as I could derive from this open pull request.
From this mailing list it seems that someone made a Proof Of Concept and made changes to the WildFly code to make it work, however this is not the solution that we are looking for since we'd prefer not to change the WildFly code.
Relevant code
The client code hangs on the blockingStub.updateBalance(request) call because no reply is ever received:
BalanceUpdateGrpc.BalanceUpdateBlockingStub blockingStub = BalanceUpdateGrpc.newBlockingStub(channel);
var request = BalanceUpdateRequest.newBuilder()
.setContractNumber("111")
.setBalance((float) 100.2)
.setDate(BalanceUpdateRequest.Date
.newBuilder()
.setDay(3)
.setMonth(11)
.setYear(2020)
.build())
.build();
var reply = blockingStub.updateBalance(request);
The service code:
@Singleton
public class BalanceUpdateService extends BalanceUpdateGrpc.BalanceUpdateImplBase {
@Inject
private DossierDAO dossierDAO;
@Override
public void updateBalance(BalanceUpdateRequest balanceUpdateRequest, StreamObserver<BalanceUpdateReply> responseObserver) {
//Just reply with true
//dossierDAO is always null when used in this code block
responseObserver.onNext(BalanceUpdateReply.newBuilder().setSuccess(true).build());
}
}