【问题标题】:gRPC Java cannot find a NameResolver when using in OSGi bundle在 OSGi 包中使用 gRPC Java 时找不到 NameResolver
【发布时间】:2020-07-13 12:08:00
【问题描述】:

我正在尝试在 OSGi 包中使用 JAVA gRPC。我正在使用 maven 并使用 org.apache.servicemix.bundles.grpc-1.30.2_1,它是从 1.30.2_1 的发布标签本地构建的。

OSGi 包可以正常启动,没有任何问题,但在运行时创建 ManageChannel 时,我得到了 java.lang.IllegalArgumentException: cannot find a NameResolver for localhost:4435 异常。

堆栈跟踪的相关部分

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:?]

当我在运行时调试 gRPC 代码时,我可以看到添加了零个 NameResolvers。我认为这可能是一个类加载问题。

这是来自 Apache Felix 插件的配置的一部分,

<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>

频道构建代码​​(这里使用io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder

ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 4435)
                    .usePlaintext()
                    .build();

我只需要让 gRPC 客户端在 OSGi 包中工作。 非常感谢您对此提供任何帮助。

【问题讨论】:

    标签: java osgi grpc osgi-bundle grpc-java


    【解决方案1】:

    META-INF/services 中添加相关的 gRPC 提供程序有效。

    通过引用 this 弄明白了,它也在 OSGi 包中使用 gRPC https://github.com/wso2/micro-integrator/tree/v1.2.0-m4/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 2021-02-11
      • 2014-05-17
      相关资源
      最近更新 更多