假设我们使用gRCP/Protobuf来连接许多应用程序.这些应用程序是以自己的速度在自己的团队中开发和发布的.随着时间的推移,将在定义的界面上使用不同版本的相同应用程序的不同版本(例如,在用户PC上安装的桌面应用程序).
虽然Protobuf旨在允许向后兼容,但有没有办法知道哪个版本的接口在不同的点运行?
最简单的实现是使接口版本等于app版本.但是,由于使用了许多语言,在所有语言中实现应用程序版本并非易事.
那么版本界面如何让服务器知道客户端版本?我认为服务器应该能够登录
来自AppName v.version的DATETIME连接[using interface v.version]
我正在使用sbt程序集来创建一个可以在火花上运行的胖罐.有依赖性grpc-netty.spark上的Guava版本比所需的版本旧grpc-netty,我遇到了这个错误:java.lang.NoSuchMethodError:com.google.common.base.Preconditions.checkArgument.我能够通过在spark上将userClassPathFirst设置为true来解决此问题,但会导致其他错误.
如果我错了,请纠正我,但根据我的理解,如果我正确地进行着色,我不应该将userClassPathFirst设置为true.这是我现在的着色方式:
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("com.google.guava.**" -> "my_conf.@1")
.inLibrary("com.google.guava" % "guava" % "20.0")
.inLibrary("io.grpc" % "grpc-netty" % "1.1.2")
)
libraryDependencies ++= Seq(
"org.scalaj" %% "scalaj-http" % "2.3.0",
"org.json4s" %% "json4s-native" % "3.2.11",
"org.json4s" %% "json4s-jackson" % "3.2.11",
"org.apache.spark" %% "spark-core" % "2.2.0" % "provided",
"org.apache.spark" % "spark-sql_2.11" % "2.2.0" % "provided",
"org.clapper" %% "argot" % "1.0.3",
"com.typesafe" % "config" % "1.3.1",
"com.databricks" %% "spark-csv" % "1.5.0",
"org.apache.spark" % "spark-mllib_2.11" % "2.2.0" % …Run Code Online (Sandbox Code Playgroud) 用于创建通道的 gRPC C++ API 返回一个 shared_ptr。生成的函数 NewStub 返回一个 unique_ptr。但是,我已经看到有人在尝试创建存根类型的多个实例、共享频道时遇到问题的报告。他们的解决方案是共享存根。
从文档或 API 中不清楚客户端是要创建多个共享通道的存根实例还是共享单个存根。请阐明存根、通道和唯一客户端连接之间的概念关系。
深入一点:服务器可以提供多个服务,客户端端点可以使用单个通道将相应的存根类型连接到这些服务中的每一个。为此,很明显不同的存根类型共享单个通道以与服务器端点通信。对于给定的服务,gRPC 是否期望每个通道只有一个客户端,或者我可以在客户端端点上有多个客户端与单个服务通信?如果允许,如何在客户端端点上为给定服务实现多个客户端?服务器如何将这些区分为独立的客户端?
顺便说一句,这篇 SO 帖子表明 Channels 和 Stubs 都是线程安全的。(这篇文章是专门针对 Java 的,但我假设它会延续到 C++)。
我正在尝试通过以下方式为我的python代码创建gRPC绑定:
python -m grpc_tools.protoc -I $(pwd)/protos --python_out=./fino/pb2 --grpc_python_out=./fino/pb2 -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf $(pwd)/protos/*
Run Code Online (Sandbox Code Playgroud)
但是生成的文件具有不存在的依赖关系:
from github.com.gogo.protobuf.gogoproto import gogo_pb2 as github_dot_com_dot_gogo_dot_protobuf_dot_gogoproto_dot_gogo__pb2
Run Code Online (Sandbox Code Playgroud)
稍后用于:
DESCRIPTOR = _descriptor.FileDescriptor(
name='oracle.proto',
package='oracle',
syntax='proto2',
serialized_pb=_b('\n\x0coracle.proto\x12\x06oracle\x1a-github.com/gogo/protobuf/gogoproto/gogo.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a\x0btypes.proto\":\n\x0b\x41\x63\x63ountList\x12+\n\x08\x61\x63\x63ounts\x18\x01 \x03(\x0b...')
,
dependencies=[github_dot_com_dot_gogo_dot_protobuf_dot_gogoproto_dot_gogo__pb2.DESCRIPTOR,google_dot_protobuf_dot_timestamp__pb2.DESCRIPTOR,google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,types__pb2.DESCRIPTOR,])
Run Code Online (Sandbox Code Playgroud)
显然,我无法运行此代码。尝试删除不存在的导入后:
TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "oracle.proto":
oracle.proto: Import "github.com/gogo/protobuf/gogoproto/gogo.proto" has not been loaded.
Run Code Online (Sandbox Code Playgroud)
我尝试添加
--include_imports --descriptor_set_out=$(pwd)/protos/all.proto
Run Code Online (Sandbox Code Playgroud)
但我不确定如何将其添加到我的python文件中。我想要的只是我的python代码库中的独立描述。
EDIT1:示例原型文件:
syntax = "proto2";
package etcdserverpb;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;
message …Run Code Online (Sandbox Code Playgroud) 我想为我信任的来源创建一个 grpc 通道,但我缺少其证书。使用默认凭据设置安全通道失败:
import gprc
ssh_channel = grpc.secure_channel(<gprc url>, grpc.ssl_channel_credentials())
grpc.channel_ready_future(ssh_channel).result()
Run Code Online (Sandbox Code Playgroud)
结果是:
E1017 10:05:15.783011100 11539 ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED.
E1017 10:05:16.846366639 11539 ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED.
E1017 10:05:18.688887874 11539 ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED.
E1017 10:05:21.557399186 11539 ssl_transport_security.cc:1229] Handshake failed with fatal error SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED.
Run Code Online (Sandbox Code Playgroud)
我知道这是可能的,因为例如在 Java 中,会执行以下操作:
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
...
sslContext = GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
channel = NettyChannelBuilder.forAddress(<gprc url>, 443).sslContext(sslContext).build(); …Run Code Online (Sandbox Code Playgroud) // api_internal.proto
service InvoiceTemplateMatcher {
rpc Process(InvoiceFilePath) returns (UploadStatus) {}
}
message InvoiceFilePath {
string invoice_id = 1;
string file_path = 2;
}
// template_matcher/src/main.cc
class OrkaEngineInvoiceTemplateMatcherImpl final : public InvoiceTemplateMatcher::Service {
private:
Status Process(
ServerContext* context,
orka_engine_internal::InvoiceFilePath* invoicefp,
orka_engine_internal::UploadStatus* response) override {
// do stuff
}
};
Run Code Online (Sandbox Code Playgroud)
类InvoiceTemplateMatcher::Service是在编译期间从该.proto文件生成的。
当我尝试编译时,出现错误
‘grpc::Status OrkaEngineInvoiceTemplateMatcherImpl::Process(grpc::ServerContext*, orka_engine_internal::InvoiceFilePath*, orka_engine_internal::UploadStatus*)’ marked ‘override’, but does not override
Status Process(ServerContext* context, orka_engine_internal::InvoiceFilePath* invoicefp, orka_engine_internal::UploadStatus* response) override {
Run Code Online (Sandbox Code Playgroud)
据我所知,我的代码与Route Guide example 中的编写方式相同。我错过了什么?
由于您必须共享 .proto 文件来为 gRPC 定义数据和服务,因此服务提供者和客户端需要访问相同的 .proto 文件。是否有分发这些文件的通用策略?我想避免每个项目在其 Git 存储库中都有自己的 .proto 文件,而我们的团队成员需要手动编辑这些文件或通过电子邮件共享它们。
有什么共同的最佳实践吗?
我正在尝试确定是否可以使用 (A/E/N)LB 之一来负载平衡 gRPC 流量。在我们的例子中,一个简单的循环就足够了。
我读过 ALB 不完全支持 HTTP2,因此不能与 gRPC 一起使用。特别提到了缺乏对向下游发送 HTTP2 流量的支持和缺乏对尾部标头的支持。它仍然是真的吗?
找不到关于 NLB 或“经典”ELB 的任何明确答案。任何提示?
networking load-balancing amazon-web-services amazon-elb grpc
我想使用 gRPC 让客户端订阅服务器生成的事件。我有一个 RPC 声明如下:
rpc Subscribe (SubscribeRequest) returns (stream SubscribeResponse);
Run Code Online (Sandbox Code Playgroud)
其中返回的流是无限的。要“取消订阅”,客户端取消 RPC(顺便说一句。有没有更干净的方法?)。
我已经弄清楚客户端如何取消呼叫:
rpc Subscribe (SubscribeRequest) returns (stream SubscribeResponse);
Run Code Online (Sandbox Code Playgroud)
但是,服务器似乎没有注意到客户端已取消其调用。我正在用一个虚拟服务器实现来测试这个:
Context.CancellableContext cancellableContext =
Context.current().withCancellation();
cancellableContext.run(() -> {
stub.subscribe(request, callback);
});
// do other stuff / wait for reason to unsubscribe
cancellableContext.cancel(new InterruptedException());
Run Code Online (Sandbox Code Playgroud)
服务器会很高兴地继续将其消息发送到以太坊中。服务器如何识别调用已被客户端取消并因此停止发送响应?
我正在尝试与不安全的 gRPC 服务器建立连接。我使用 gRPC 在 Docker 容器内的两个进程之间进行通信,这就是为什么我不需要任何加密或强身份验证。
服务器按预期运行,我可以像这样使用 grpcurl 进行调用:
grpcurl -plaintext localhost:42652 SomeService.DoSomething
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试从 .Net Core 应用程序调用相同的 RPC 方法:
// Registration of the DI service
services.AddGrpcClient<DaemonService.DaemonServiceClient>(options => {
// Enable support for unencrypted HTTP2
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
options.Address = new Uri("http://localhost:42652");
// Just a test, doesn't change anything.
options.ChannelOptionsActions.Add(channelOptions => channelOptions.Credentials = ChannelCredentials.Insecure);
});
// Call
var reply = _someServiceClient.DoSomething(new Request());
Run Code Online (Sandbox Code Playgroud)
但是最后一行中的调用导致异常:
fail: Grpc.Net.Client.Internal.GrpcCall[6]
Error starting gRPC call.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.IO.IOException: The response …Run Code Online (Sandbox Code Playgroud) grpc ×10
c++ ×2
python ×2
.net ×1
.net-core ×1
amazon-elb ×1
apache-spark ×1
c# ×1
channel ×1
client ×1
grpc-java ×1
guava ×1
networking ×1
proto ×1
proto3 ×1
sbt ×1
sbt-assembly ×1
ssl ×1
stub ×1
versioning ×1