Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/netcore-jroger/SimpleRpc
A light-weight RPC wrap of google gRPC framework.
https://github.com/netcore-jroger/SimpleRpc
grpc grpc-net-core rpc
Last synced: 2 months ago
JSON representation
A light-weight RPC wrap of google gRPC framework.
- Host: GitHub
- URL: https://github.com/netcore-jroger/SimpleRpc
- Owner: netcore-jroger
- License: mit
- Created: 2019-04-28T01:46:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T08:03:37.000Z (9 months ago)
- Last Synced: 2024-04-13T21:13:31.347Z (9 months ago)
- Topics: grpc, grpc-net-core, rpc
- Language: C#
- Size: 85 KB
- Stars: 12
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleRpc
A light-weight RPC wrap of google gRPC framework.![Build Status](https://github.com/netcore-jroger/SimpleRpc/workflows/SimpleRpc-CI/badge.svg)
![GitHub](https://img.shields.io/github/license/netcore-jroger/SimpleRpc.svg)| **Package** | **NuGet** |
| --- | --- |
| SimpleRpc.Shared | ![Nuget](https://img.shields.io/nuget/v/SimpleRpc.Shared.svg) |
| SimpleRpc.Server | ![Nuget](https://img.shields.io/nuget/v/SimpleRpc.Server.svg) |
| SimpleRpc.Client | ![Nuget](https://img.shields.io/nuget/v/SimpleRpc.Client.svg) |## Getting Started
```csharp
// gRPC Client side
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false, true)
.Build();
var provider = new ServiceCollection()
.AddRpcClient(configuration)
.AddRpcClientService()
.BuildServiceProvider();
```#### Unary
```csharp
// gRPC Client side
var tokenSource = new CancellationTokenSource(1000 * 60 * 2);
var userService = provider.GetService();
var userDto = await userService.GetUserBy(userRequest, tokenSource.Token);```
#### ClientStreaming
```csharp
// gRPC Client side
var tokenSource = new CancellationTokenSource(1000 * 60 * 2);
var rpcChannel = provider.GetService();
var call = rpcChannel.AsyncClientStreamingCall("greet.Greeter", "TestClientStreaming", tokenSource.Token);
await call.RequestStream.WriteAsync(new UserDto { Id = 1, Name = "abc1" });
await call.RequestStream.WriteAsync(new UserDto { Id = 2, Name = "abc2" });
await call.RequestStream.CompleteAsync();
var userDto = await call;Console.WriteLine($"Id: {userDto.Id}, Name: {userDto.Name}, CreateDate: {userDto.CreateDate:yyyy-MM-dd HH:mm:ss fff}");
```// gRPC Server side
- see `IUserService.cs` line: 19-20
- see `UserService.cs` line: 36-50#### ServerStreaming
```csharp
// gRPC Client side
var tokenSource = new CancellationTokenSource(1000 * 60 * 2);
var rpcChannel = provider.GetService();
var call = rpcChannel.AsyncServerStreamingCall("greet.Greeter", "TestServerStreaming", new UserRequest { Id = 1, Keyword = $"client[ServerStreaming]1: {input}" }, tokenSource.Token);
await call.ResponseStream.MoveNext(tokenSource.Token).ConfigureAwait(false);
var userDto = call.ResponseStream.Current;
Console.WriteLine($"ServerStreaming: Id: {userDto.Id}, Name: {userDto.Name}, CreateDate: {userDto.CreateDate:yyyy-MM-dd HH:mm:ss fff}");await call.ResponseStream.MoveNext(tokenSource.Token).ConfigureAwait(false);
userDto = call.ResponseStream.Current;
Console.WriteLine($"ServerStreaming: Id: {userDto.Id}, Name: {userDto.Name}, CreateDate: {userDto.CreateDate:yyyy-MM-dd HH:mm:ss fff}");
```// gRPC Server side
- see `IUserService.cs` line: 22-23
- see `UserService.cs` line: 52-76#### DuplexStreaming
```csharp
var tokenSource = new CancellationTokenSource(1000 * 60 * 2);
var rpcChannel = provider.GetService();
var call = rpcChannel.AsyncDuplexStreamingCall("greet.Greeter", "TestDuplexStreaming", tokenSource.Token);
await call.ResponseStream.MoveNext(tokenSource.Token).ConfigureAwait(false);
var userDto = call.ResponseStream.Current;
Console.WriteLine($"DuplexStreaming: Id: {userDto.Id}, Name: {userDto.Name}, CreateDate: {userDto.CreateDate:yyyy-MM-dd HH:mm:ss fff}");await call.ResponseStream.MoveNext(tokenSource.Token).ConfigureAwait(false);
userDto = call.ResponseStream.Current;
Console.WriteLine($"DuplexStreaming: Id: {userDto.Id}, Name: {userDto.Name}, CreateDate: {userDto.CreateDate:yyyy-MM-dd HH:mm:ss fff}");await call.RequestStream.WriteAsync(new UserRequest { Id = 1, Keyword = $"client[DuplexStreaming]1 - {input}" });
await call.RequestStream.WriteAsync(new UserRequest { Id = 2, Keyword = $"client[DuplexStreaming]2 - {input}" });
await call.RequestStream.CompleteAsync();
```// gRPC Server side
- see `IUserService.cs` line: 25-26
- see `UserService.cs` line: 78-107## Roadmap
- [x] Unary supported.
- [x] ClientStreaming supported.
- [x] ServerStreaming supported.
- [x] DuplexStreaming supported.