NextGen Server/Client Architecture - gRPC + Unity + C#
- 30. public class TestService : MagicOnionService
{
// define public method
public async Task<int> Sum(int x, int y)
{
return x + y;
}
public async Task<string> Download(string url)
{
// async/await support
var result = await new HttpClient().GetStringAsync(url);
return result;
}
}
struct DynamicTuple
{
public int x;
public int y;
}
- 31. // standard gRPC connection
var channel = new Channel("127.0.0.1:12345");
// Client will be run-time generated as “.Create<TService>()” and called seamlessly.
var result = await MagicOnionClient.Create<TestService>(channel).Sum(100, 200);
- 33. // filter can attach per global/class/method
public class SampleFilterAttribute : MagicOnionFilterAttribute
{
public override async Task Invoke(ServiceContext context)
{
try
{
/* before invoke next */
await Next.Invoke(context);
/* after invoke next */
}
catch (Exception ex)
{
/* when exception */
}
finally
{
/* finalize */
}
}
}
- 38. C#で統一 + gRPCで統一
Web APIもRealtimeも含めて、gRPCに徹底的に移行(中)
実にリスキーで愚かな話です!
Next Standard を作るつもりでやってるし、黒騎士で証明する!
gRPCは成長途上
周辺環境が弱い(ロードバランサーもあんま対応してないし)
情報があるようでない(UnaryはともかくStreamingのノウハウは……)
が、しかしgoogleの本気度は高い(GCPのAPIはどんどんgRPCで提供
されてってるし←こないだのSpannerなども)
全力で乗っかっていくし、C#でのBest Practiceを確立していきたい