假设我有一个像这样的原型文件.我可以定义这样的服务吗?
rpc SayHello () returns (Response) {} //service has no input
rpc SayHello (Request1,Request2) returns (Response) {}//service has two inputs
Run Code Online (Sandbox Code Playgroud)
//.proto文件
syntax = "proto3";
service Greeter{
rpc SayHello (Request) returns (Response) {}
}
message Request{
string request = 1;
}
message Response{
string response = 1;
}
Run Code Online (Sandbox Code Playgroud) 在 csharp 中是 grpc 通道线程安全的,或者更一般地说,在任何取决于 C 核心版本的语言中;
对于以下代码:1)通道线程安全吗?2) 客户端线程安全吗?
Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
Task task1 = Task.Factory.StartNew(() =>
{
var client = new Greeter.GreeterClient(channel);
String user = "you";
var reply = client.SayHello(new HelloRequest {Name = user});
Console.WriteLine("Greeting: " + reply.Message);
});
Task task2 = Task.Factory.StartNew(() =>
{
var client = new Greeter.GreeterClient(channel);
String user = "you";
var secondReply = client.SayHelloAgain(new HelloRequest {Name = user});
Console.WriteLine("Greeting: " + secondReply.Message);
});
task1.Wait();
task2.Wait();
channel.ShutdownAsync().Wait();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)