I am trying to use JAVA gRPC in an OSGi bundle. I am using maven and using org.apache.servicemix.bundles.grpc-1.30.2_1 which is locally built from the release tag for 1.30.2_1.
The OSGi bundle starts up fine without any issue but at runtime when a ManageChannel is created I get a java.lang.IllegalArgumentException: cannot find a NameResolver for localhost:4435
exception.
The relevant part of the stacktrace
java.lang.IllegalArgumentException: cannot find a NameResolver for localhost:4435
at io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:724) ~[org.apache.servicemix.bundles.grpc-1.30.2_1.jar:?]
at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:606) ~[org.apache.servicemix.bundles.grpc-1.30.2_1.jar:?]
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:518) ~[org.apache.servicemix.bundles.grpc-1.30.2_1.jar:?]
When I debug the gRPC code at runtime I can see that there is zero NameResolvers added. I think that this can be a classloading issue.
This is part of the config from the Apache Felix plugin,
<Import-Package>
...,
org.apache.servicemix.bundles.grpc.*; version="1.30.2_1",
io.grpc*;
</Import-Package>
<Embed-Dependency>org.apache.servicemix.bundles.grpc;scope=compile</Embed-Dependency>
Channel building code (This is using io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder
)
ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 4435)
.usePlaintext()
.build();
I only need to get the gRPC client working in the OSGi bundle. Any help on this is much appreciated.
Adding the relevant gRPC providers in the META-INF/services
worked.
Got it figured out by referencing this, which also uses gRPC inside a OSGi bundle https://github.com/wso2/micro-integrator/tree/v1.2.0-m4/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint