ããã«ã¡ã¯ãã¢ã¼ããã¯ãã®å°æã§ãã
.NET Core 3.0 ãã¤ãã« GA ã«ãªãã¾ããã
.NET Core 3.0 ã§ã¯ gRPC ã®æ©è½ãµãã¼ããçµã¿è¾¼ã¾ãã¦ãã¾ãã
ä»å㯠.NET Core 3.0 ã§ç°¡åã« gRPC ã®éçºãã¹ã¿ã¼ããããã¨ãã§ãããã¨ãç¥ã£ã¦ããã ããããã¨æãã¾ãã¦ãgRPC ãµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã®çé確èªãã§ããã¾ã§ã®æé ãè¨äºã«ãã¦ã¿ã¾ããã
ãããã gRPC ã¨ã¯ä½ï¼
gRPC ã¯ãGoogle ã«ãã£ã¦éçºãããã¹ãã¼ããã¡ã¼ã¹ãã® RPCï¼ãªã¢ã¼ãããã·ã¼ã¸ã£ã¼ã³ã¼ã«ï¼ãã¬ã¼ã ã¯ã¼ã¯ã§ããã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã«ããããµã¼ãã¹ééä¿¡ã«ããã¦æåãªé¸æè¢ã¨ãã¦æ³¨ç®ããã¦ããæè¡ã§ãã
ãã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã§ã¯ã大ããªã·ã¹ãã ãç´°ãããµã¼ãã¹ã«åå²ããåãµã¼ãã¹ãç¬ç«ãããççµåã«ä¿ã¤ãã¨ãéè¦ããã¾ããç´°ãããµã¼ãã¹ã«åå²ããçµæã¨ãã¦ããã¡ããç«ã¦ãã°ãã¡ããç«ãããã¨ããããã¤ãã®åé¡ãçºçãã¦ãã¾ããã¨ã«ãªãã¾ããã
ããã¥ã¡ã³ãã¼ã·ã§ã³ã«é¢ããåé¡
gRPC ã注ç®ãããçç±ã®ä¸ã¤ã API ã®ããã¥ã¡ã³ãã¼ã·ã§ã³ã«é¢ããåé¡ã§ãã
ãã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã§ã¯ããµã¼ãã¹éã®é信㯠API ã RPC ã«ãã£ã¦ç·©ãçµåããã¾ãããã®ã¨ããAPI ã®ããã¥ã¡ã³ã㯠API ã使ãå´ã«ã¨ã£ã¦éè¦ãªæ å ±æºã¨ãªãã¾ãã
ãã¨ãã° .NET ã®ã¢ããªã·ãã¯ãªã¢ããªã±ã¼ã·ã§ã³ã§ããã°ãåã¡ã½ããã«ãµããªã³ã¡ã³ããè¨è¿°ãã¦ããã°ã³ã¼ãã£ã³ã°ä¸ã«ã¤ã³ããªã»ã³ã¹ã§å¿ è¦ãªæ å ±ãå¾ããã¦ããããã§ããããã¡ã½ãããä½ã£ãå´ã¨ä½¿ãå´ã®æ å ±ã®åã渡ããé常ã«ã¹ã ã¼ãºã§ããã
ããããããã REST API ã§ããå ´åãèªåã§ããã¥ã¡ã³ããæºåããããSwagger ã®ãããªãã¼ã«ã使ã£ã¦ããã¥ã¡ã³ããä½æããªããã°ãªãã¾ãããREST API ã¯ãªã¼ãã³ãªæè¡ã®ä¸ã«æãç«ã£ã¦ãã¾ãã®ã§ãè¨è¨è ã«å§ããããé¨åãå¤ãåå¨ãã¾ãããã¨ãã°ãPOST ãªã®ã PUT ãªã®ããXML ãªã®ã JSON ãªã®ã form-urlencoded ãªã®ãããããã¯è¨è¨è ã«ãã£ã¦ããã¥ã¡ã³ããæä¾ããã¦ããå¿ è¦ããããããã¥ã¡ã³ããç¡ããã° API ã使ãå´ã¯ä½ãé²ãããã¨ãã§ããªãã®ã§ããããã¦ããã¥ã¡ã³ãéãã«å®è£ ããã¦ããã®ã¯å½ç¶ã®ãã¨ãªãããAPI ã®å¤æ´ã®ãã³ã«ããã¥ã¡ã³ãã®ç¶æ管çãå¿ è¦ã«ãªãã¾ããã
åãµã¼ãã¹ãç¬ç«ãã¦ççµåã«ãªã£ã¦ããã®ãã®ã®éçºãã¼ã ãã¹ãã¼ãã£ã«éçºã»ãããã¤ã§ããããã«ãªã£ããã¨ã¨å¼ãæãã«ãéçºãã¼ã ã«ã¯ä»ã¾ã§ããããã£ããç´°ããã¬ãã«ã®ããã¥ã¡ã³ãã¼ã·ã§ã³ã課ãã¦ãã¾ããã¨ã«ãªã£ã¦ãã¾ãã¾ãããããã¯ããã¥ã¡ã³ããããåãã³ã¼ããéè¦ããã¢ã¸ã£ã¤ã«ãªéçºããã»ã¹ã«ã¨ã£ã¦ãªã¼ãã¼ãããã§ãããã¨ã¯ééãããã¾ããã
gRPC ã¯ãã¹ãã¼ããã¡ã¼ã¹ãã¨ããã¢ããã¼ãã«ãã£ã¦ããã¥ã¡ã³ãã¨å®è£ ãå®å ¨ã«ä¸è´ããããã¬ã¼ã ã¯ã¼ã¯ã§ããã©ããããã¨ãã¨ããã¨ãã¹ãã¼ããå®ç¾©ããã°ãµã¼ãã¼å´ã®å®è£ ã¹ã±ã«ãã³ï¼æ½è±¡ã¯ã©ã¹ï¼ãçæããã使ãå´ã¯ã©ã¤ã¢ã³ãã®å®è£ ãåºæ¥ä¸ããã®ã§ãã
gRPC ã«ã¯ãã¹ãã¼ããã¡ã¤ã«ã«è¨è¿°ãããå
容ããèªã¿ãããããã¥ã¡ã³ããçæãããã¼ã«ï¼protoc-gen-docï¼ãéçºããã¦ãã¦ãããã¥ã¡ã³ãã¼ã·ã§ã³ã«é¢ããåé¡ãä¸æ°é貫ã«è§£æ±ºãã¦ãããæè¡ã§ããã¨æãã¾ãã
æ§è½ã«é¢ããåé¡
gRPC ã注ç®ãããçç±ã®ããä¸ã¤ããã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã«ãããæ§è½ã«é¢ããåé¡ã§ãã
ãã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã§ã¯ãåãµã¼ãã¹éã®éä¿¡ã API ã® RPC ã«ãã£ã¦ç·©ãçµåãã¦ããã¾ããããã® RPC ã®é度ã¯å ¨ä½ã®æ§è½ã«å¤§ããå½±é¿ãã¾ããRPC ã¯ããããã¯ã¼ã¯ãè¶ ããããã»ã¹ééä¿¡ã«ãªãã¾ãã®ã§ãåãã¢ããªã±ã¼ã·ã§ã³ããã»ã¹ã®ã¡ã¢ãªå ã«é ç½®ãããã¡ã½ããå¼ã³åºãã¨ã¯æ¬¡å ãéãã¬ãã«ã§é ããªã£ã¦ãã¾ãã¾ãã
gRPC ã¯ããã¼ã¿è»¢éæã®ã·ãªã¢ã«åã«ãã㦠Protobuf ï¼ãããã³ã«ãããã¡ã¼ï¼ã¨ãã軽éã§è¶ é«éãªæè¡ã使ãã¾ããProtobuf 㨠XML ãæ¯è¼ããã¨ãµã¤ãºã¯3åï½10å軽éã«ãªããé度ã¯20åï½100åãéããªãã¨ãããã¨ã§ãã
[åè]
https://developers.google.com/protocol-buffers/docs/overview
ã·ãªã¢ã«åã¨éã·ãªã¢ã«åã¯ï¼åã®éä¿¡ã§æ大ï¼åãè¡ããã¦ãã¾ãã®ã§ããã®ãªã¼ãã¼ãããã¯ç¡è¦ã§ãã¾ããã
Google ã¯æ¤ç´¢ã¨ã³ã¸ã³å¸å ´ã®é»ææãéãã«ãã£ã¦å¸å ´ãæä¸ã«åãã¾ããããProtobuf ã¯ãã® Google ã«ãããå ¨ã¦ã®ãã·ã³ééä¿¡ã§æ¡ç¨ããã¦ããæè¡ã¨ã®ãã¨ãéãã¯æ£ç¾©ã§ããã
ãã¦ãgRPCã®è¯ãç¹ã°ãããç´¹ä»ãã¦ãã¾ããããçæãããã¾ãã
ããã¯ããã©ã¦ã¶ããç´æ¥å©ç¨ã§ããªããã¨ã¨ãéä¿¡å
容ããã¤ããªãªã®ã§äººãå¤èªã§ããªãã¨ããç¹ã§ããMSã®ããã¥ã¡ã³ãã«ç¹å¾´ãæ¯è¼ããã¦ãããã¼ã¸ãããã¾ããã®ã§ã詳ããç¥ãããæ¹ã¯ãåç
§ãã ããã
.NET Core 3.0 㯠gRPC ããã¡ã¼ã¹ãã¯ã©ã¹ãµãã¼ã
ãããªãã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã«ãããæå¾ ã®æã§ãã gRPC ã .NET Core 3.0 ã«ã¦ãã¡ã¼ã¹ãã¯ã©ã¹ã®ãµãã¼ããå¾ã¦ã.NET Core ã«ã·ã¼ã ã¬ã¹ã«çµ±åããã¾ããã.NET Core 3.0 以åã¯ã©ãã ã£ãã®ãã¨ããã¨ãgRPC ã®ãã¼ã«ãèµ·åãã¦ãµã¼ãã¼ã»ã¯ã©ã¤ã¢ã³ãå®è£ ãçæããã³ãã³ããå®è¡ããå¿ è¦ãããã¾ããã.NET Core 3.0 ã«ãªã£ã¦ãããã¹ãã¼ããã¡ã¤ã«ãè¨è¿°ãã¦ãããã¸ã§ã¯ããã¡ã¤ã«ï¼.csprojï¼ã«ããããªè¨è¿°ã追è¨ããã ãã§ããã«ãæã«ééçã«å®è£ ãçæãã¦ãããããã«ãªãã¾ããã
ã¾ããKestrel ãµã¼ãã¼ã«å¯¾ã㦠gRPC ãµã¼ãã¼ãç°¡åã«ãã¹ãã§ããããã«ãªã£ã¦ãããVisual Studio ã«ã¯ gRPC ã®ããã¸ã§ã¯ããã³ãã¬ã¼ããæä¾ããã¾ããã極ãã¦ç°¡åã« gRPC ã®éçºãã¹ã¿ã¼ããããã¨ãã§ããããã«ãªã£ã¦ãã¾ãã.NET Core ã§ããã gRPC ãµã¼ãã¼ã Docker ã³ã³ããã«ãããã¨ã§ãAWSãAzure ãåããã¯ã©ã¦ãä¸ã§å®è¡ãããã¨ãå¯è½ã§ãã
.NET Core 3.0 㨠Visual Studio 2019 Community ã®ã¤ã³ã¹ãã¼ã«
åç½®ããããã¶ãã¨é·ããªã£ã¦ãã¾ãã¾ãããããããã㯠gRPC ã®ãµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã®éçºã®ã¯ããæ¹ãæé ã追ã£ã¦ãç´¹ä»ãã¦ããããã¨æãã¾ãã
æåã« .NET Core 3.0 SDK ãã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã¾ãã
ç°å¢ã«åãã㦠SDK ã¤ã³ã¹ãã¼ã©ã¼ããã¦ã³ãã¼ããã¦ã¤ã³ã¹ãã¼ã«ãã¦ãã ããã
.NET Core SDK
https://dotnet.microsoft.com/download/dotnet-core/3.0
次㫠Visual Studio 2019 Community ãã¤ã³ã¹ãã¼ã«ãã¾ããVisual Studio Code ã§ãéçºã¯å¯è½ã§ãããã¯ããã¦éçºããå ´å㯠Visual Studio 2019 ã®æ¹ãããããããã®ã§ããããã§ãã
Visual Studio 2019 Community ã§ããã°å人ã®å¦ç¿ç®çã§ããã°ç¡åã§ãããæ¡ä»¶ãæºããã°åç¨ã¢ããªã±ã¼ã·ã§ã³ã®éçºã«ãå©ç¨ã§ãã¾ãã
Visual Studio 2019 Community
https://visualstudio.microsoft.com/ja/vs/
ã¤ã³ã¹ãã¼ã«æã«ã¯ã¼ã¯ãã¼ããé¸æããå¿ è¦ãããã¾ããgRPC ã®éçºã«å¿ è¦ãªã¯ã¼ã¯ãã¼ãã¯ãASP.NETã¨Web éçºãããAzureã®éçºããã.NET Core ã¯ãã¹ãã©ãããã©ã¼ã ã®éçºããã.NET ãã¹ã¯ãããéçºãããããé¸ãã§ããã°ã ããã OK ãã¨æãã¾ãã
gRPC ãµã¼ãã¼éçºã®ã¯ãããã
Visual Studio 2019 èµ·åããããæ°ããããã¸ã§ã¯ãã®ä½æããã¯ãªãã¯ãã¾ãã
ä¸ã«ã¹ã¯ãã¼ã«ããã¨ãgRPCãµã¼ãã¹ããæ°ãã追å ããã¦ãã¾ãï¼
ããã¸ã§ã¯ããé
ç½®ãããã£ã¬ã¯ããªãç¨æãã¦ãããã¸ã§ã¯ãåãå ´æãã½ãªã¥ã¼ã·ã§ã³åãå
¥åãã¦ä½æãã¯ãªãã¯ãã¾ãã
ããã¸ã§ã¯ããã³ãã¬ã¼ãã¯ä»ã¯ä¸ã¤ããããã¾ããã
ç»é¢å³ã« Docker ãµãã¼ãã®ãªãã·ã§ã³ãããã¾ãããDockerfile ã¯ãã¨ã§æåã§ç¨æããã°ããã®ã§ãã®ã¾ã¾ä½æãã¯ãªãã¯ãã¾ãã
ã¾ãã¯ã½ãªã¥ã¼ã·ã§ã³ããã«ããã¦ã¿ã¦æ£å¸¸ã«ãã«ãã§ãããã¨ã確èªãã¾ãã
ã¤ã¥ãã¦F5ãã¼ãæ¼ãã¦ãããã°å®è¡ãéå§ãã¾ãã
ããã§è¨¼ææ¸ã®ç¢ºèªãã¤ã¢ãã°ãåºã¾ããã
gRPC 㯠HTTP/2 ãåæã¨ãªã£ã¦ãã¾ããããã« HTTP/2 㯠SSL 証ææ¸ãåæã«ãªã£ã¦ããããã èªå·±ç½²å証ææ¸ã Visual Studio ãèªåçã«çæãã¦å¿
è¦ãªè¨å®ãè¡ã£ã¦ããã¾ããããã¯ä¸¡æ¹ã¨ããã¯ããã¨çãã¾ãã
ãããã°å®è¡ãéå§ãããéã«ã¨ã©ã¼ãåºã¦ãã¾ãã¾ããã証ææ¸ã¯ãã¯ããã¨çããã®ã§ããããã¾ãè¨å®ã§ããªãã£ãã¿ããã§ãã
crit: Microsoft.AspNetCore.Server.Kestrel[0] Unable to start Kestrel. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date. To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'. For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
ã¨ã©ã¼ã¡ãã»ã¼ã¸ã«ããã¨ãdotnet dev-certs https --trust ãå®è¡ããã¨è¯ããããªã®ã§ããå®è¡ãã¦ããã¾ãããã¾ããã§ããã
helpã³ãã³ãã§èª¿ã¹ã¦ã¿ãã¨å¦¥å½æ§ã®ãã§ãã¯ãã§ãããããã®ã§ããã£ãããã§ãã¯ãã¦ã¿ãã¨ãæå¹ãªè¨¼ææ¸ãè¦ã¤ããã¾ãããã¨è¨ããã¦ãã¾ãã¾ããã
dotnet dev-certs https --check No valid certificate found.
ãã®åé¡ã解決ãã¦ãããããªé°å²æ°ã® clean ã³ãã³ãããã£ãã®ã§ä¸æ¦åé¤ãã¦ã¿ã¾ããã
dotnet dev-certs https --clean Cleaning HTTPS development certificates from the machine. A prompt might get displayed to confirm the removal of some of the certificates. HTTPS development certificates successfully removed from the machine.
ããä¸åº¦è¨¼ææ¸ãä½æãã¦ã¿ã¾ãã
dotnet dev-certs https --trust Trusting the HTTPS development certificate was requested. A confirmation prompt will be displayed if the certificate was not previously trusted. Click yes on the prompt to trust the certificate. The HTTPS developer certificate was generated successfully.
ãã¾ããã£ãã¿ããã§ããæå¹ãªè¨¼ææ¸ã¨ãã¦èªèããã¦ãããã¨ã確èªã§ãã¾ããã
dotnet dev-certs https --check A valid certificate was found.
ããã§ç¡äºã«ãããã°å®è¡ã§ããããã«ãªãã¾ããã
info: Microsoft.Hosting.Lifetime[0] Now listening on: https://localhost:5001 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: D:\Work\dotnetcore\MyFirstGrpc\src\MyFirstGrpc.Grpc
ç¡äºã« gRPC ãµã¼ãã¼ãç«ã¡ä¸ãã£ãã®ã§ãã¯ã©ã¤ã¢ã³ããã¤ãã£ã¦ã¿ã¾ãããã
gRPC ã¯ã©ã¤ã¢ã³ãéçºã®ã¯ãããã
å¼ãç¶ããç¾å¨ã®ã½ãªã¥ã¼ã·ã§ã³ã« gRPC ã¯ã©ã¤ã¢ã³ãããã¸ã§ã¯ãã追å ãã¾ãã
ãã¡ã¤ã«ã¡ãã¥ã¼ã®ã追å ããããæ°ããããã¸ã§ã¯ãããé¸æãã¦ããã³ã³ã½ã¼ã«ã¢ããªããé¸æãã¾ãã
ããã¸ã§ã¯ãåãå
¥åãã¾ãã
ããã¸ã§ã¯ããä½æã§ãããã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã¼ã®ã¯ã©ã¤ã¢ã³ãããã¸ã§ã¯ããå³ã¯ãªãã¯ãã¦ããNuGet ããã±ã¼ã¸ã®ç®¡çããã以ä¸ã®ï¼ã¤ã®ããã±ã¼ã¸ã追å ãã¾ãã
- Grpc.Net.Client
- Google.Protobuf
- Grpc.Tools
ã¹ãã¼ããã¡ã¤ã«ï¼.protoï¼ã¯ãµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã§å
±éã®å®ç¾©ãã¡ã¤ã«ã使ç¨ãã¾ãã
ãµã¼ãã¼å´ã§ä½æããã¦ãã Protos ãã©ã«ããã¯ã©ã¤ã¢ã³ãå´ã«ãã©ãã°ã¢ã³ãããããã§ã³ãã¼ãã¾ãã
ã¯ã©ã¤ã¢ã³ãã®ã¢ããªã±ã¼ã·ã§ã³ã®ããã¸ã§ã¯ããã¡ã¤ã«ï¼csprojï¼ãéãã¦ç·¨éãã¾ãã
ãã©ãã°ã¢ã³ãããããã§è¿½å ããã¹ãã¼ããã¡ã¤ã«ã¯èªåçã«ãµã¼ãã¼å®è£
ã®ã³ã¼ããåãåºãè¨å®ã«ãªãããã§ãããããã Client ã«æ¸ãæãã¾ãã
<ItemGroup> <Protobuf Include="Protos\greet.proto" GrpcServices="Server" /> </ItemGroup> â <ItemGroup> <Protobuf Include="Protos\greet.proto" GrpcServices="Client" /> </ItemGroup>
Program.csãã¡ã¤ã«ã¯ä»¥ä¸ã®ãããªè¨è¿°ã«å¤æ´ãã¾ãã
using System; using MyFirstGrpc.Grpc; // ãã㯠.proto ãã¡ã¤ã«ã«è¨è¼ãããåå using Grpc.Net.Client; using System.Threading.Tasks; namespace MyFirstGrpc.Client { class Program { static async Task Main(string[] args) { // The port number(5001) must match the port of the gRPC server. var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" }); Console.WriteLine("Greeting: " + reply.Message); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } } }
ããã§ãµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã®æºåãå®äºãã¾ããã
ã¾ãã¯ãMyFirstGrpc.Grpc ããã¸ã§ã¯ããã¹ã¿ã¼ãã¢ããããã¸ã§ã¯ãã«ã㦠Ctrl +F5 ï¼ãããã°ãªãã§éå§ï¼ãã¾ãã
ãã®å¾ãMyFirstGrpc.Clientããã¸ã§ã¯ããã¹ã¿ã¼ãã¢ããããã¸ã§ã¯ãã«ãã¦ãããã°å®è¡ãéå§ãã¦ã¿ã¾ããããç¡äºã«ãµã¼ãã¼ã®å¿çã¡ãã»ã¼ã¸ã表示ããã¾ããï¼
Greeting: Hello GreeterClient Press any key to exit...
ããã¾ã§ã®æé ã®æ¯ãè¿ã
ç°¡åãªæé ã§ãµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã® gRPC éä¿¡ç°å¢ãã§ããããã¾ããã
ã¾ããgRPC ã®ãµã¼ãã¼éçºã¯ããã¸ã§ã¯ããã³ãã¬ã¼ããæä¾ããã¦ãã¦ããããã ãªæ§æã®ã½ã¼ã¹ã³ã¼ãããã¹ã¿ã¼ãã§ããããã«ãªã£ã¦ãã¾ãã
ãµã¼ãã¼éçºã®ããã¸ã§ã¯ããã³ãã¬ã¼ãã«å«ã¾ãã¦ãããã¡ã¤ã«ã¯ä»¥ä¸ã®éãã§ãã
- \Properties\launchSettings.json éçºç°å¢ã«ãããèµ·åè¨å®æ å ±ã§ãã稼åç°å¢ã«ã¯å¿ è¦ããã¾ããã
- \Protos\greet.proto ã¹ãã¼ããã¡ã¤ã«ã§ããgRPC ã®åå¼·ããã¦è¨æ³ãå¦ã³ã¾ããããã¤ã³ããªã»ã³ã¹ãå¹ãã¾ãã
- \Services\GreeterService.cs ãµã¼ãã¹ã®å®è£ ã¯ã©ã¹ã§ããgreet.proto ã§èªåçæãããæ½è±¡ã¯ã©ã¹ãç¶æ¿ãã¦ãã¾ãã
- appsettings.json è¨å®ãã¡ã¤ã«ã§ããç°å¢ãåããªãå ±éã®è¨å®ãè¨è¿°ãã¾ãã
- appsettings.Development.json è¨å®ãã¡ã¤ã«ã§ããç°å¢å¤æ° ASPNETCORE_ENVIRONMENT ã Development ã®ã¨ãã« appsettings.json ã®è¨å®æ å ±ãä¸æ¸ããã¾ãã
- Program.cs ã¢ããªã±ã¼ã·ã§ã³ã®ã¨ã³ããªãã¤ã³ãã¨ãªã Main é¢æ°ãåããã¯ã©ã¹ã§ãã
- Startup.cs gRPC ãµã¼ãã¼ã®ã¹ã¿ã¼ãã¢ããã³ã¼ããè¨è¿°ããã¯ã©ã¹ã§ããDI ã®è¨å®ãã«ã¼ãã£ã³ã°ã®è¨å®ãè¨è¿°ãã¾ãã
.NET Core 3.0 ã® gRPC ã¯ãã¹ãã¼ããã¡ã¤ã«ããåçã«ãããã·ã³ã¼ããçæãã¦ããã¦ãã¾ããçæãããããã·ã³ã¼ã㯠obj ãã©ã«ãå ã§ããããããã·ã³ã¼ããããã¸ã§ã¯ãã«è¿½å ããããã¨ã¯ãªããä¸è¬ç㪠.NET éçºã® .gitignore ã§ããã°ã½ã¼ã¹ã³ã¼ã管çã«å ¥ã£ã¦ãã¾ããã¨ãããã¾ããã
ãããã·ã³ã¼ãã¯ã¨ãã£ã¿ã¼ãã該å½ã¯ã©ã¹ï¼ããã§ã¯ Greeter.GreeterBase ï¼ãå³ã¯ãªãã¯ãã¦ãå®ç¾©ã¸ç§»åãã¨é¸æããã¨ã ãããã·ã³ã¼ããé²è¦§ãããã¨ãã§ãã¾ãã
/// <summary>Base class for server-side implementations of Greeter</summary> [grpc::BindServiceMethod(typeof(Greeter), "BindService")] public abstract partial class GreeterBase { /// <summary> /// Sends a greeting /// </summary> /// <param name="request">The request received from the client.</param> /// <param name="context">The context of the server-side call handler being invoked.</param> /// <returns>The response to send back to the client (wrapped by a task).</returns> public virtual global::System.Threading.Tasks.Task<global::MyFirstGrpc.Grpc.HelloReply> SayHello(global::MyFirstGrpc.Grpc.HelloRequest request, grpc::ServerCallContext context) { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } }
ã¯ã©ã¤ã¢ã³ãã® gRPC ã¯ãï¼ã¤ã® NuGet ããã±ã¼ã¸ã追å ãã¦ããããããªæé 㧠gRPC ãµã¼ãã¼ãå¼ã³åºããã¨ãå¯è½ã«ãªãã¾ãããã¹ãã¼ããã¡ã¤ã«ãããã¸ã§ã¯ãã«æãè¾¼ãã ãã§ãããã«å¼ã³åºãã§ããã¨ããæ軽ããå®æã§ãã¾ããã
ã¾ã¨ã
.NET Core 3.0 ã® gRPC ã¯ã·ã¼ã ã¬ã¹ã«çµ±åããã¦ãã¦ãã¢ããªã±ã¼ã·ã§ã³ã®å®è£ é¨åã«éä¸ããã°è¯ãã¨ããç°å¢ãæ´ã£ã¦ãã¾ããæ¨ä»ã®ãã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã¸ã®ãã©ãã¤ã ã·ãããå¼·åã«ããã¯ã¢ãããã¦ãããã㪠gRPC ã¨ããããè¦äºã«çµã¿è¾¼ãã .NET Core ã«æå¾ æãå端ãªãï¼
ä»åã¯é·ããªã£ã¦ãã¾ã£ãã®ã§ãDocker ã®ã³ã³ããã¼åã¨ã¯ã©ã¦ãã¸ã®ãããã¤ã¯æ¬¡åã«æã¡è¶ããããã¨ã«ãã¾ããã次åã®è¨äºã§ã¯ä»åã® gRPC ãµã¼ãã¹ã Docker ã§ã³ã³ããã¼åãã¦ãAzure ã«ãã¹ãããã¨ããã¾ã§é²ãã¦ã¿ããã¨æãã¾ãã
ããã§ã¯ï¼
ï½ecbeingã§ã¯ .NET Core ã¨ãã¤ã¯ããµã¼ãã¹ã¢ã¼ããã¯ãã£ã«æ³¨ç®ãã¦ãããã¤ã±ã¦ãã¨ã³ã¸ãã¢ã大åéä¸ã§ãï¼ï½
careers.ecbeing.tech