我从maven插件'grpc-java'生成了Java代码并发布了。在sbt项目中使用工件连接到grpc服务器。但无法连接(在kubernates集群上)。当我使用端口转发从本地连接时,它会连接并发送消息(来自Maven项目)。
sbt中使用的客户端代码如下
ManagedChannelBuilder<?> managedChannelBuilder = ManagedChannelBuilder.forAddress(host, port).usePlaintext();
MyGrpc.MyBlockingStub myBlockingStub = MyGrpc.newMyStub(managedChannelBuilder.build());
尝试发送消息时遇到错误。这可能是原因。
sbt的依赖性:
"io.grpc" % "grpc-core" % "1.20.0",
"io.grpc" % "grpc-netty-shaded" % "1.20.0",
"io.grpc" % "grpc-protobuf" % "1.20.0",
"io.grpc" % "grpc-stub" % "1.20.0",
"io.netty"%"netty-codec-http2"%"4.1.34.Final",
"io.netty"%"netty-codec-http"%"4.1.34.Final"
还有其他项目依赖项(elasticsearch,postgres,mysql,redis,aws ....)
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:233) ~[io.grpc.grpc-stub-1.18.0.jar:1.18.0]
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:214) ~[io.grpc.grpc-stub-1.18.0.jar:1.18.0]
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:139) ~[io.grpc.grpc-stub-1.18.0.jar:1.18.0]
...... play.core.Router$HandlerInvokerFactory$$anon$4.resultCall(Router.scala:264) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.core.Router$HandlerInvokerFactory$JavaActionInvokerFactory$$anon$15$$anon$1.invocation(Router.scala:255) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:55) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.GlobalSettings$1.call(GlobalSettings.java:67) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at actions.InitAction.call(InitAction.java:47) [gameengine.gameengine-avengers.jar:avengers]
at play.core.j.JavaAction$$anonfun$11.apply(JavaAction.scala:82) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.core.j.JavaAction$$anonfun$11.apply(JavaAction.scala:82) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [org.scala-lang.scala-library-2.11.1.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [org.scala-lang.scala-library-2.11.1.jar:na]
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:40) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:46) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at scala.concurrent.impl.Future$.apply(Future.scala:31) [org.scala-lang.scala-library-2.11.1.jar:na]
at scala.concurrent.Future$.apply(Future.scala:492) [org.scala-lang.scala-library-2.11.1.jar:na]
at play.core.j.JavaAction$class.apply(JavaAction.scala:82) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.core.Router$HandlerInvokerFactory$JavaActionInvokerFactory$$anon$15$$anon$1.apply(Router.scala:252) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:130) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:130) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.utils.Threads$.withContextClassLoader(Threads.scala:21) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:129) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:128) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at scala.Option.map(Option.scala:145) [org.scala-lang.scala-library-2.11.1.jar:na]
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:128) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:121) [com.typesafe.play.play_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:483) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:483) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:519) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:519) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$14.apply(Iteratee.scala:496) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$14.apply(Iteratee.scala:496) [com.typesafe.play.play-iteratees_2.11-2.3.9.jar:2.3.9]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [org.scala-lang.scala-library-2.11.1.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [org.scala-lang.scala-library-2.11.1.jar:na]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41) [com.typesafe.akka.akka-actor_2.11-2.3.4.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393) [com.typesafe.akka.akka-actor_2.11-2.3.4.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2.11.1.jar:na]
Caused by: io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2Exception: First received frame was not SETTINGS. Hex dump for first 5 bytes: 485454502f
at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:85) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.verifyFirstFrameIsSettings(Http2ConnectionHandler.java:350) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:251) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:450) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:502) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:441) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:278) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[io.grpc.grpc-netty-shaded-1.18.0.jar:1.18.0]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_181]```
答案 0 :(得分:0)
该错误消息的其余部分显示,“前5个字节的十六进制转储:485454502f”。十六进制485454502f
是ASCII“ HTTP /”。该服务器可能是HTTP / 1服务器,而不是HTTP / 2服务器。仔细检查您正在联系正确的服务器,并且它支持gRPC。