asp.net-core - Grpc.Net vs Grpc.Core:服务器端有什么区别?
问题描述
似乎 Grpc.Net 需要 ASP.NET Core 才能托管服务,而 Grpc.Core 不需要?有什么区别?哪个是首选?
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
// Communication with gRPC endpoints must be made through a gRPC client.
// To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909
endpoints.MapGrpcService<GreeterService>();
});
}
Server server = new Server
{
Services = { RouteGuide.BindService(new RouteGuideImpl(features)) },
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
};
server.Start();
解决方案
Grpc.Core是一个基于 gRPC 原生实现的库。它基本上是与本机库的绑定,可以直接将“原始”gRPC 用于客户端和服务器目的。
Grpc.AspNetCore是 gRPC 的托管重新实现,构建在 Kestrel 服务器堆栈之上。与原生实现相比,这使得 Grpc.AspNetCore 通常效率更高。它是为 ASP.NET Core 本身构建的,它还可以更好地集成到 ASP.NET Core 应用程序中,这还允许您与其他 ASP.NET Core 端点并排托管 gRPC 服务。相比之下,它可能不支持所有 gRPC 功能,并且也仅限于服务器端方面。
推荐阅读
- c# - How to count semicolon for each line of an csv file in c#
- react-native - react-native-camera 从相机屏幕返回时运行缓慢
- ruby - 如何确定 Tempfile 是否为流?
- c# - Visual Studio Step into(F11) does not work in new Configuration
- android - 由于这个原因,android 8.0 和 8.1 中的高 Anr
- http - SPNEGO authentication with uri module
- reactjs - React Native 无法启动
- sql - Finding the journey made by users in Google BigQuery
- c# - 在方法中使用协变泛型类型
- r - R:投资组合优化解决。QP 不是正定的