﻿
{"id":20419,"date":"2021-01-04T00:03:30","date_gmt":"2021-01-04T00:03:30","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=20419"},"modified":"2021-01-04T00:08:32","modified_gmt":"2021-01-04T00:08:32","slug":"grpc-unary-yontemiyle-client-ve-server-iletisimi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/grpc-unary-yontemiyle-client-ve-server-iletisimi\/","title":{"rendered":"gRPC &#8211; Unary Y\u00f6ntemiyle Client ve Server \u0130leti\u015fimi"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bir \u00f6nceki <a href=\"https:\/\/www.gencayyildiz.com\/blog\/grpcde-client-ve-server-uygulamalari-proto-dosyasi-ve-servislerin-olusturulmasi\/\" rel=\"noopener noreferrer\" target=\"_blank\">gRPC\u2019de Client ve Server Uygulamalar\u0131, Proto Dosyas\u0131 ve Servislerin Olu\u015fturulmas\u0131<\/a> ba\u015fl\u0131kl\u0131 makalemizde gRPC \u00fczerine pratikte uzun ve detayl\u0131 bir incelemede bulunmu\u015ftuk.  Bu i\u00e7eri\u011fimizde ise iki uygulama aras\u0131nda ileti\u015fimin gRPC \u00fczerinden Unary y\u00f6ntemiyle nas\u0131l sa\u011fland\u0131\u011f\u0131n\u0131 pratikte inceliyor olaca\u011f\u0131z.<\/p>\n<p>\u0130lk olarak Unary y\u00f6nteminin ne oldu\u011funu hat\u0131rlayarak ba\u015flayal\u0131m.<\/p>\n<p><div id=\"attachment_20376\" style=\"width: 396px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/gRPC-Nedir-Ne-Amacla-ve-Nasil-Kullanilir-2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-20376\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/gRPC-Nedir-Ne-Amacla-ve-Nasil-Kullanilir-2.png\" alt=\"gRPC Nedir? Ne Ama\u00e7la ve Nas\u0131l Kullan\u0131l\u0131r?\" width=\"386\" height=\"192\" class=\"size-full wp-image-20376\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/gRPC-Nedir-Ne-Amacla-ve-Nasil-Kullanilir-2.png 386w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/gRPC-Nedir-Ne-Amacla-ve-Nasil-Kullanilir-2-300x149.png 300w\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" \/><\/a><p id=\"caption-attachment-20376\" class=\"wp-caption-text\">Client\u2019\u0131n server\u2019a tek bir istek g\u00f6nderdi\u011fi ve normal bir i\u015flev \u00e7a\u011fr\u0131s\u0131 gibi tek bir yan\u0131t geri ald\u0131\u011f\u0131 RPC t\u00fcr\u00fcd\u00fcr.<\/p><\/div>Burada Unary y\u00f6nteminin Http\/1&#8217;de ki davran\u0131\u015f\u0131n birebir benzerini g\u00f6sterdi\u011fini s\u00f6yleyebiliriz. Yani client&#8217;tan gelen bir request&#8217;e kar\u015f\u0131l\u0131k, server bir response d\u00f6nd\u00fcrecektir.<\/p>\n<p>\u015eimdi gelin, bu y\u00f6ntem ile bir client ve server \u00e7al\u0131\u015fmas\u0131 sergileyelim.<\/p>\n<h4 style=\"color:purple;\">Proto Dosyas\u0131<\/h4>\n<p>Client ve server olmak \u00fczere her iki uygulama aras\u0131ndaki kontrat\u0131 a\u015fa\u011f\u0131daki <em>message.proto<\/em> dosyas\u0131 \u00fczerinden sa\u011flayaca\u011f\u0131z.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nsyntax = &quot;proto3&quot;;\r\noption csharp_namespace = &quot;gRPCExample&quot;;\r\npackage message;\r\n\r\nservice Message {\r\n  rpc GetMessage(MessageRequest) returns (MessageResponse);\r\n}\r\nmessage MessageRequest {\r\n  string message = 1;\r\n}\r\nmessage MessageResponse {\r\n  string message = 1;\r\n}\r\n<\/pre>\n<p>Yukar\u0131daki <em>message.proto<\/em> i\u00e7eri\u011fine g\u00f6z atarsan\u0131z e\u011fer i\u00e7erisinde &#8216;GetMessage&#8217; isimli fonksiyon bar\u0131nd\u0131ran &#8216;Message&#8217; isimli bir servis olu\u015fturulmaktad\u0131r. \u0130lgili fonksiyon yap\u0131lacak request neticesinde bir &#8216;MessageRequest&#8217; nesnesi istemekte ve response olarak geriye &#8216;MessageResponse&#8217; de\u011feri d\u00f6nd\u00fcrmektedir.<\/p>\n<h4 style=\"color:purple;\">Server&#8217;da Message Service&#8217;i<\/h4>\n<p>Client&#8217;tan gelecek olan iste\u011fi server&#8217;da kar\u015f\u0131layacak olan &#8216;MessageService&#8217;i a\u015fa\u011f\u0131daki gibi tasarlayal\u0131m.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class MessageService : MessageBase\r\n    {\r\n        public async override Task&lt;MessageResponse&gt; GetMessage(MessageRequest request, ServerCallContext context)\r\n        {\r\n            Console.WriteLine($&quot;Mesaj al\u0131nm\u0131\u015ft\u0131r.&quot;);\r\n            Console.WriteLine(&quot;Gelen mesaj : &quot;);\r\n            Console.WriteLine(request.Message);\r\n\r\n            return new MessageResponse\r\n            {\r\n                Message = &quot;\u0130stek al\u0131nd\u0131 ve i\u015flendi...&quot;\r\n            };\r\n        }\r\n    }\r\n<\/pre>\n<p>Yukar\u0131daki servis detay\u0131n\u0131 incelerseniz e\u011fer kullan\u0131lan Unary y\u00f6ntemine uygun olacak \u015fekilde gelen request&#8217;e kar\u015f\u0131l\u0131k tek bir response d\u00f6n\u00fclmektedir.<\/p>\n<h4 style=\"color:purple;\">Client<\/h4>\n<p>\u0130stek g\u00f6nderecek client&#8217;\u0131n a\u015fa\u011f\u0131daki gibi geli\u015ftirilmesi yeterli olacakt\u0131r;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Program\r\n    {\r\n        static async Task Main(string&#x5B;] args)\r\n        {\r\n            while (true)\r\n            {\r\n                var channel = GrpcChannel.ForAddress(&quot;https:\/\/localhost:5001&quot;);\r\n                var messageClient = new Message.MessageClient(channel);\r\n                Console.WriteLine(&quot;L\u00fctfen g\u00f6nderilecek mesaj\u0131 giriniz.&quot;);\r\n                var messageResponse = await messageClient.GetMessageAsync(new MessageRequest { Message = Console.ReadLine() });\r\n                Console.WriteLine($&quot;Gelen Cevap : {messageResponse.Message}&quot;);\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<p>Dikkat ederseniz client yine kullan\u0131lan Unary y\u00f6ntemine uygun olacak \u015fekilde tek bir istekte bulunmaktad\u0131r.<\/p>\n<h4 style=\"color:purple;\">Test Edelim<\/h4>\n<p><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2021\/01\/gRPC-Unary-Yontemiyle-Client-ve-Server-Iletisimi.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2021\/01\/gRPC-Unary-Yontemiyle-Client-ve-Server-Iletisimi.gif\" alt=\"gRPC - Unary Y\u00f6ntemiyle Client ve Server \u0130leti\u015fimi\" width=\"800\" height=\"315\" class=\"aligncenter size-full wp-image-20533\" \/><\/a><\/p>\n<p>G\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere Unary y\u00f6ntemiyle client ve server aras\u0131nda ba\u015far\u0131yla ileti\u015fim kurulabilmektedir.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar dilerim&#8230;<\/p>\n<p>Not : \u00d6rnek projeleri indirebilmek i\u00e7in a\u015fa\u011f\u0131daki adreslere t\u0131klay\u0131n\u0131z.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2021\/01\/gRPCClientExample-1.zip\">gRPCClientExample<\/a><br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2021\/01\/gRPCServerExample.zip\">gRPCServerExample<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bir \u00f6nceki gRPC\u2019de Client ve Server Uygulamalar\u0131, Proto Dosyas\u0131 ve Servislerin Olu\u015fturulmas\u0131 ba\u015fl\u0131kl\u0131 makalemizde gRPC \u00fczerine pratikte uzun ve detayl\u0131 bir incelemede bulunmu\u015ftuk. Bu i\u00e7eri\u011fimizde ise iki uygulama aras\u0131nda ileti\u015fimin gRPC \u00fczerinden Unary&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":20376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4032],"tags":[4065,4067,4066],"class_list":["post-20419","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-grpc","tag-grpc","tag-grpc-unary-example","tag-unary-grpc"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/20419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=20419"}],"version-history":[{"count":26,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/20419\/revisions"}],"predecessor-version":[{"id":20545,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/20419\/revisions\/20545"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/20376"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=20419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=20419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=20419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}