我有两个 gRPC 服务,一个将通过正常的 gRPC 方法调用另一个服务(两边都没有流),我使用 istio 作为服务网格,并将 sidecar 注入到这两个服务的 kubernetes pod 中。
正常负载下gRPC调用正常,但在高并发负载情况下,gRPC客户端一直抛出以下异常:
<#bef7313d> i.g.StatusRuntimeException: UNAVAILABLE: upstream connect error or disconnect/reset before headers
at io.grpc.Status.asRuntimeException(Status.java:526)
at i.g.s.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:434)
at i.g.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at i.g.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at i.g.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at i.g.i.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:678)
at i.g.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at i.g.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at i.g.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at i.g.i.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:397)
at i.g.i.ClientCallImpl.closeObserver(ClientCallImpl.java:459)
at i.g.i.ClientCallImpl.access$300(ClientCallImpl.java:63)
at i.g.i.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:546)
at i.g.i.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:467)
at i.g.i.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:584)
at i.g.i.ContextRunnable.run(ContextRunnable.java:37)
at i.g.i.SerializingExecutor.run(SerializingExecutor.java:123)
at j.u.c.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at j.u.c.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Run Code Online (Sandbox Code Playgroud)
同时,服务端没有异常,istio-proxy客户端Pod的容器也没有错误。但是,如果我禁用 istio sidecar 注入,以便这两个服务直接相互通信,则不会出现此类错误。
有人可以告诉我为什么以及如何解决这个问题吗?
多谢。
我正在使用使用 HTTPS 和自签名证书托管的 GRPC 服务。当我使用如下语法进行连接时:
const client = new productService('https://grpc-server-xxx.com:9090',
grpc.credentials.createInsecure())
Run Code Online (Sandbox Code Playgroud)
我收到这样的错误
{ Error: 14 UNAVAILABLE: DNS resolution failed
at Object.exports.createStatusError (C:\grpc\node_modules\grpc\src\common.js:91:15)
at Object.onReceiveStatus (C:\grpc\node_modules\grpc\src\client_interceptors.js:1209:28)
at InterceptingListener._callNext (C:\grpc\node_modules\grpc\src\client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (C:\grpc\node_modules\grpc\src\client_interceptors.js:618:8) at callback (C:\grpc\node_modules\grpc\src\client_interceptors.js:847:24)code: 14,metadata: Metadata { _internal_repr: {}, flags: 0 },details: 'DNS resolution failed'
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我如何解决这个问题。
注意:我的操作系统是 Windows 10,nodejs -- v10.16.0,GRPC
我正在尝试使用 GRPC 在 Scala 中编写流服务。为此我写了这个原型文件
syntax = "proto3";
package com.abhi.grpc;
message TimeRequest{}
message TimeResponse {
int64 currentTime = 1;
}
service Clock {
rpc StreamTime(TimeRequest) returns (stream TimeResponse);
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务器端代码
import com.abhi.grpc.clock.{ClockGrpc, TimeRequest, TimeResponse}
import io.grpc.stub.StreamObserver
import monix.execution.Scheduler
import monix.execution.Scheduler.{global => scheduler}
import scala.concurrent.duration._
object ClockGrpcServer extends GrpcServer with App {
val ssd = ClockGrpc.bindService(new ClockGRPC(), Scheduler.global)
runServer(ssd, "Clock")
}
class ClockGRPC extends ClockGrpc.Clock {
override def streamTime(request: TimeRequest, responseObserver: StreamObserver[TimeResponse]): Unit = {
scheduler.scheduleWithFixedDelay(0.seconds, 3.seconds) {
responseObserver.onNext(TimeResponse(System.currentTimeMillis))
}
} …Run Code Online (Sandbox Code Playgroud) 我有以下代码,它将创建一个Java gRPC服务器并尝试将其绑定到USD / tmp / foo:
EpollEventLoopGroup group = new EpollEventLoopGroup();
Server server =
NettyServerBuilder.forAddress(new DomainSocketAddress("/tmp/foo"))
.channelType(EpollServerSocketChannel.class)
.bossEventLoopGroup(group)
.workerEventLoopGroup(group)
.addService(new Impl())
.build()
.start();
server.awaitTermination();
Run Code Online (Sandbox Code Playgroud)
但是,此操作失败bind(..) failed: Invalid argument:
Exception in thread "main" java.io.IOException: Failed to bind
at io.grpc.netty.NettyServer.start(NettyServer.java:231)
at io.grpc.internal.ServerImpl.start(ServerImpl.java:151)
at io.grpc.internal.ServerImpl.start(ServerImpl.java:75)
at com.google.devtools.javatools.jade.pkgloader.GrpcLocalServer.main(GrpcLocalServer.java:60)
Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Invalid argument
at io.netty.channel.unix.Errors.newIOException(Errors.java:117)
at io.netty.channel.unix.Socket.bind(Socket.java:291)
at io.netty.channel.epoll.AbstractEpollChannel.doBind(AbstractEpollChannel.java:714)
at io.netty.channel.epoll.EpollServerSocketChannel.doBind(EpollServerSocketChannel.java:70)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:364)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
at …Run Code Online (Sandbox Code Playgroud) I'm occasionally getting cancellation errors when calling gRPC methods.
Here's my client-side code (Using grpc-java 1.22.0 library):
public class MyClient {
private static final Logger logger = LoggerFactory.getLogger(MyClient.class);
private ManagedChannel channel;
private FooGrpc.FooStub fooStub;
private final StreamObserver<Empty> responseObserver = new StreamObserver<>() {
@Override
public void onNext(Empty value) {
}
@Override
public void onError(Throwable t) {
logger.error("Error: ", t);
}
@Override
public void onCompleted() {
}
};
public MyClient() {
this.channel = NettyChannelBuilder
.forAddress(host, port)
.sslContext(GrpcSslContexts.forClient().trustManager(certStream).build())
.build();
var pool = Executors.newCachedThreadPool( …Run Code Online (Sandbox Code Playgroud) 我试图在处理 rpc 服务器调用后使用响应中的值设置一些元数据。计划是使用服务器拦截器和覆盖close方法。
像这样:https : //github.com/dconnelly/grpc-error-example/blob/master/src/main/java/example/Errors.java#L38
由于元数据值取决于响应,我需要某种方式将数据从 rpc 服务器调用传递到服务器拦截器或访问拦截器的响应
在 Golang 中,元数据可以grpc.SetTrailer在处理后的 rpc 调用中轻松设置,但在 java 中无法在 rpc 调用中进行设置。所以我试图使用服务器拦截器。
有人可以帮忙吗?
我试图制作一个连接到数据库并获取信息并通过 grpc 将它们输出到桌面应用程序的项目。但是,当我编译它时,我在目标文件(由 protoc 自动生成)中得到“错误:(20,18)java:找不到符号”。我无法理解这个问题。我试图改变mvn 的编译器,更改 protoc 上的版本,设置不同的 JDK,一切都变得更糟了。
我的项目可以在这里查看:https : //github.com/Diana-Ioana/grpc 我的数据库和崩溃的生成目标文件的错误是:https : //imgur.com/a/T6taLXF
我不知道现在该怎么办。任何帮助都会很棒,谢谢!
我无法带着这种困惑继续前进,因为我不知道该怎么办。Python 中的大多数教程都会获取定义方法的主类名称,但当您只需要编写客户端时,不知道如何执行此操作。
我正在使用官方文档学习gRPC,但发现客户端流和双向流的方法签名非常混乱(两者是相同的)。
从这里的文档来看,该函数StreamObserver<ResponseType>作为输入参数并返回一个StreamObserver<ResponseType>实例,如下所示:
public StreamObserver<RequestType> bidirectionalStreamingExample(
StreamObserver<ResponseType> responseObserver)
Run Code Online (Sandbox Code Playgroud)
但在我看来,它应该将RequestType类型作为输入并返回ResponseType类型:
public StreamObserver<ResponseType> bidirectionalStreamingExample(
StreamObserver<RequestType> responseObserver)
Run Code Online (Sandbox Code Playgroud)
这让我很困惑,实际上我有点惊讶的是,当我在谷歌搜索时,答案没有提示,我以为很多人都会有同样的问题。我在这里遗漏了一些明显的东西吗?为什么 gRPC 会这样定义签名?
我有两个服务器-HelloServer和WorldServer。
两者都实现了相同的原始文件:
// The greeting service definition.
service GreeterService {
// Sends a greeting
rpc GreetWithHelloOrWorld (GreeterRequest) returns (GreeterReply) {}
rpc GreetWithHelloWorld (GreeterRequest) returns (GreeterReply) {}
}
message GreeterRequest {
string id = 1;
}
// The response message containing the greetings
message GreeterReply {
string message = 1;
string id = 2;
}
Run Code Online (Sandbox Code Playgroud)
我想将traceIds添加到请求中。据我了解,这是通过在Metadata对象中添加traceId来实现的。
这是我用来检查traceIds是否通过的测试。向HelloServer发出请求,后者依次调用WorldServer,然后最终返回响应。
@Test
public void greetHelloWorld() {
String traceId = UUID.randomUUID().toString();
Metadata metadata = new Metadata();
metadata.put(MetadataKeys.TRACE_ID_METADATA_KEY, traceId);
Greeter.GreeterRequest greeterRequest = Greeter.GreeterRequest.newBuilder().setId(traceId).build();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", …Run Code Online (Sandbox Code Playgroud) 解决 UnusedPrivateParameter 错误
我试图使用以下插件构建 grpc 服务。似乎该插件无法使用 protoc 实用程序。
操作系统:MAC
Maven版本:3.6.3
错误 :
[ERROR] PROTOC FAILED: google/protobuf/wrappers.proto: File not found.
order-mgmt.proto: Import "google/protobuf/wrappers.proto" was not found or had errors.
order-mgmt.proto:7:16: "google.protobuf.StringValue" is not defined.
...
**[ERROR] Failed to execute goal org.xolstice.maven.plugins:protobuf-maven-plugin:0.6.1:compile (default) on project OrderManagement-gRPC: protoc did not exit cleanly. Review output for more information. -> [Help 1]**
Run Code Online (Sandbox Code Playgroud)
我正在使用的插件是:
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact> </configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
Run Code Online (Sandbox Code Playgroud) grpc-java ×12
grpc ×10
java ×2
protoc ×2
bind ×1
envoyproxy ×1
grpc-go ×1
grpc-node ×1
grpc-python ×1
interceptor ×1
istio ×1
maven ×1
mysql ×1
netty ×1
node.js ×1
python ×1
scala ×1
sockets ×1
unix-socket ×1