<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vikesh Yadav on Medium]]></title>
        <description><![CDATA[Stories by Vikesh Yadav on Medium]]></description>
        <link>https://medium.com/@yadav-vikesh27?source=rss-e150cb124ff3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*C20C_S9RRZeD6Jpm.jpg</url>
            <title>Stories by Vikesh Yadav on Medium</title>
            <link>https://medium.com/@yadav-vikesh27?source=rss-e150cb124ff3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:43:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yadav-vikesh27/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[gRPC Python implementation from scratch]]></title>
            <link>https://yadav-vikesh27.medium.com/grpc-python-implementation-from-scratch-321226912fb9?source=rss-e150cb124ff3------2</link>
            <guid isPermaLink="false">https://medium.com/p/321226912fb9</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[rpc]]></category>
            <dc:creator><![CDATA[Vikesh Yadav]]></dc:creator>
            <pubDate>Wed, 26 May 2021 17:57:01 GMT</pubDate>
            <atom:updated>2021-05-26T17:57:01.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ASHDUCFGIcYf_IVZE2HYA.jpeg" /></figure><p>The objective of this article is to implement gRPC in Python. We will be implementing both client and server in your favorite programming language ie. Python :).</p><p>By the time you are reading this article, I am sure you have heard about gRPC and it’s working. But still here is a quick introduction to gRPC and its attributes.</p><p>💡<strong><em>What is gRPC?</em></strong><br><a href="https://grpc.io/"><em>gRPC</em></a> is a very lightweight communication protocol from Google. At a high level, it allows you to define REQUEST and RESPONSE for RPC(Remote Procedure Calls) and handles for you.</p><p>gRPC is designed to make the client believe that the server is residing on the same machine as the client. gRPC client invokes the method on the client stub, which is handled by the PRC protocol.</p><p>gRPC is based on <a href="https://developers.google.com/protocol-buffers"><em>Protocol Buffers</em></a><em>, </em>an open-source Interface Definition Language and serialization library. It’s smaller, faster, and more efficient in terms of CPU consumption than other wired-format protocols.</p><p>💡<em> </em><strong><em>Why we should use gRPC?</em><br></strong><em>gRPC</em> works with many transports, by default it uses HTTP/2 but it can also be implemented on <a href="https://blog.cloudflare.com/the-road-to-quic/"><em>QUIC</em></a><em> </em>, <em>Cronet</em>, etc.</p><p>In HTTP/2 protocol client stub talks to the server stub on a single TCP connection called <a href="http://foo.com/"><em>Channel</em></a>. A Channel is a tunnel that is established between client and server stub once and the requests are multiplexed to be in flight without compromising network resources. The payload is converted to binary rather than text(in REST+JSON) that keeps the payload compact and efficient.</p><p>Note that the creation of the channel can take up to <strong>3 seconds</strong>. If you have a deadline configured in the client and sent a request before the channel is established, the request will be dropped and RPC will be canceled, refer to <a href="https://yadav-vikesh27.medium.com/deep-dive-into-grpc-client-implementation-in-java-and-why-we-lose-initial-requests-at-the-server-fd7b8289ea">this</a> for a better understanding of the working of the channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SexBQbuOWEPH_oFt5WTr6Q.png" /></figure><ol><li><strong><em>Create protocol buffers (proto)</em></strong></li></ol><p>The proto contains an API service that has a simple <em>RPC </em>where a client will send a request and wait for the response, the call will be just like a normal function call.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e68dc8f706c8b9f86c102f6c850fa1f9/href">https://medium.com/media/e68dc8f706c8b9f86c102f6c850fa1f9/href</a></iframe><p>This is how your project should look like</p><pre>.<br>├── client.py<br>├── protos<br>│   └── api.proto<br>├── __pycache__<br>├── README.md<br>└── server.py</pre><p>2.<em> </em><strong><em>Let’s create gRPC classes</em></strong></p><p>Once you are done with the proto run the following command to let gRPC auto-generate code for you.</p><pre>mkdir generated_code<br>python -m grpc_tools.protoc -I./protos --python_out=./generated_code --grpc_python_out=./generated_code ./protos/api.proto</pre><p>Two new files (classes) will be generated inside the <em>generated_code </em>folder.</p><pre>╰─➤  tree                                                                                                                                                              <br>├── api_pb2_grpc.py # contains server and client code<br>├── api_pb2.py      # contains request and response code<br>├── client.py<br>├── protos<br>│   └── api.proto<br>├── README.md<br>└── server.py</pre><p>One of these files contains Request and Response classes while the other contains Server and Client classes.</p><p><em>api_pb2_grpc.py — </em>contains <strong>Server </strong>and <strong>Client </strong>classes<br><em>api_pb2.py — </em>contains <strong>Request </strong>and <strong>Response </strong>classes</p><p>3.<strong><em> Server and Client class</em></strong></p><p>Now that all the required piece of code is available, let&#39;s create server and client</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e3367be8026769541e8758b3d82d73f/href">https://medium.com/media/8e3367be8026769541e8758b3d82d73f/href</a></iframe><p>To start the server run the following command</p><pre>╰─➤  python server.py                                                                                                                                                    <br>server stub started on port 7073 ...</pre><p>The client is going to send a username to receive greetings</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20464ae3aa23e82b912e056c81a78120/href">https://medium.com/media/20464ae3aa23e82b912e056c81a78120/href</a></iframe><pre>╰─➤  python client.py                                                                                                          <br>resp: &quot;Hello Vikesh&quot;</pre><p>This is a basic implementation of gRPC in python, we can use it to create micro-services that serve our cause but this is just to show how we start with it.</p><p>If you want me to implement any other feature, feel free to tell me by writing in the comment section.</p><p>The complete codes mentioned here can be found in this repo:</p><p><a href="https://github.com/vickxy/Source-Code-from-Tutorials">vickxy/Source-Code-from-Tutorials</a></p><p>Happy Coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=321226912fb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get Telegram Chat ID and subscribe toVaccine Availability?]]></title>
            <link>https://yadav-vikesh27.medium.com/how-to-get-telegram-chat-id-and-subscribe-vaccine-availability-a9adcead093e?source=rss-e150cb124ff3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9adcead093e</guid>
            <category><![CDATA[vaccines]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[covid-19-vaccine-update]]></category>
            <dc:creator><![CDATA[Vikesh Yadav]]></dc:creator>
            <pubDate>Tue, 11 May 2021 06:26:22 GMT</pubDate>
            <atom:updated>2021-05-11T07:19:53.668Z</atom:updated>
            <content:encoded><![CDATA[<p>Use following steps to get your Telegram Chat ID</p><ol><li>Install Telegram</li><li>Sign-up using your phone number</li><li>Search “get my id” on search bar and select the first result</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*TGKOvpn0Nh4CqEx6Nns27w.jpeg" /></figure><p>3. Now click on “START” to get your Chat ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*wnN0Dol-PgM8-g5t2UNHiQ.jpeg" /></figure><p>4. Once you start the conversation it will return User ID and Chat ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*OF1fXfrQ6kG7nNVPKS2rOw.jpeg" /><figcaption>GET Chat ID from here</figcaption></figure><p>Now that you have got the <strong>Chat ID</strong> submit your form</p><p><a href="https://vickxy.github.io/vaccine-availability-covid19/">Vaccine Availability</a></p><p>In order to receive notification from my BOT you need to start the conversation</p><ol><li>Search “<strong>co1921_bot” </strong>select the first result and start the conversation</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*5O9uln0mq8hoFdaqzzjiOA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*w3UVWFFUUz0Iyx9RhlDVtA.jpeg" /></figure><p>2. Now we will be able to send you notification whenever vaccine is available</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*mnD2SGIGuk45KujNXHh74Q.jpeg" /></figure><p>Thanks for reading.</p><p>You can buy me a coffee if it was helpful :)</p><p><a href="https://www.buymeacoffee.com/vikesh">https://www.buymeacoffee.com/vikesh</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9adcead093e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable Hyper-V Enhanced Session Mode (Full Screen, Clipboard, Drive Access, etc)]]></title>
            <link>https://yadav-vikesh27.medium.com/how-to-enable-hyper-v-enhanced-session-mode-full-screen-clipboard-drive-access-etc-9a9154c1eeaf?source=rss-e150cb124ff3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a9154c1eeaf</guid>
            <category><![CDATA[hyper-v]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Vikesh Yadav]]></dc:creator>
            <pubDate>Tue, 27 Apr 2021 05:21:31 GMT</pubDate>
            <atom:updated>2021-04-27T05:21:31.762Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhaWt7UFIlR3LoLlb1TcQw.jpeg" /></figure><p>If you are a developer who is unable to enable Hyper-V VM in full-screen mode or else the clipboard is not working, this article is for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ie_Lp28sfwEzM5uLhfhCzA.png" /><figcaption>Picture A: A new VM named ubuntu-vm1 is created</figcaption></figure><p>Start the VM and click on connect, Enhanced Session Settings should pop up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i5JlFrEE68fuYZvTWbEL5Q.png" /><figcaption>Picture B: Enhanced Session Setting</figcaption></figure><p>This setting wizard gives you the following options :</p><ul><li>Display (with resolution control [full screen])</li><li>Audio</li><li>USB devices</li><li>Plug-and-play devices</li><li>Smart card</li><li>Printers</li></ul><p>If you are unable to see the Enhanced setting wizard, you need to install XRDP manually in your VM also you need to configure transport type in the host machine.</p><p>Follow the following steps to enable Enhanced Session Mode manually, for that On VM, open terminal and run following command to install XRDP manually</p><ul><li>sudo apt-get update</li><li>sudo apt-get install git</li><li>git clone <a href="https://github.com/Microsoft/linux-vm-tools">https://github.com/Microsoft/linux-vm-tools</a></li><li>cd linux-vm-tools/ubuntu/18.04/</li><li>sudo chmod +x install.sh</li><li>sudo ./install.sh</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czAduWDr0vDpDa6odaNgZg.png" /><figcaption>Picture C: install.sh has run successfully</figcaption></figure><p>Please follow the instructions carefully, you will need to run this script two times. Once the installation is successful, shut the VM down and follow the next step.</p><p>Now we need to set the Enhanced session transport type in the host machine, to set it run following command</p><p>set-vm -VMName ubuntu-vm1 -EnhancedSessionTransportType HvSocket</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5u5caThXsV_5mKB1KvHNDQ.png" /><figcaption>Picture D: Enable enhanced session transport type in the host machine</figcaption></figure><p>Once you are done with the above steps, simply restart the VM and you should see the Enhanced session mode pop-up to control your screen resolution, clipboard, etc</p><p>Restart VM and set the screen resolution to max and XRDP comes into action to make you feel as if you are working on the same machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m88oiijQXXNP0m8zwIZrHw.png" /><figcaption>Picture E: XRDP comes into action</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3fMDfZk735PX-G1t6A9Z8Q.png" /><figcaption>Picture F: Fullscreen of VM and clipboard starts working.</figcaption></figure><p>Video tutorial of this article:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLS2m6iyG7_M%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLS2m6iyG7_M&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLS2m6iyG7_M%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/51930951892e361dfe9ca896255c2372/href">https://medium.com/media/51930951892e361dfe9ca896255c2372/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a9154c1eeaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep dive into gRPC: Client implementation in Java, and Why we lose initial requests at the server…]]></title>
            <link>https://yadav-vikesh27.medium.com/deep-dive-into-grpc-client-implementation-in-java-and-why-we-lose-initial-requests-at-the-server-fd7b8289ea?source=rss-e150cb124ff3------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd7b8289ea</guid>
            <category><![CDATA[wireshark]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Vikesh Yadav]]></dc:creator>
            <pubDate>Sun, 16 Aug 2020 18:36:55 GMT</pubDate>
            <atom:updated>2020-08-17T15:30:27.018Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep dive into gRPC: Client implementation in Java, and Why we lose initial requests at the server side if the Deadline is less than a second?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UstjscP-MnlCuXO4uvDoaQ.png" /></figure><p>This a follow up article of my <a href="https://medium.com/@yadav.vikesh27/grpc-java-implementation-from-scratch-b7bd8f337571"><em>previous article</em></a>. Please go through it for a better understanding.</p><p>Points covered in this article are-</p><ol><li>The architecture of gRPC</li><li>Types of <em>RPC</em></li><li>Channel</li><li>Types of stub</li><li>Deadline</li><li>Java Client example with Deadline</li><li>Why we lose initial requests at the server if the Deadline is less than a second?</li></ol><p><strong>The architecture of gRPC.</strong></p><p>gRPC architecture is divided into 3 layers Surface(contains Surface API and Filters), Transport and IO-Manager.</p><ul><li><strong>Surface API </strong>exposes the underline C-core APIs as the applications do not directly talk to the core APIs of gRPC.</li><li><strong>Filters </strong>provide an extension to the core functionality of the gRPC for example-<br><strong>auth_filter </strong>— this API performs the authentication for RPC calls.<br><strong>deadline_filter </strong>— this filter implements the deadline for RPC calls.<br><strong>client_channel_filter </strong>— this is a very important filter that does name resolution and load balancing etc. We will discuss this filter in detail.</li><li><strong>Transport </strong>implements the wire protocol, by default it uses <em>HTTP/2</em> but we can use other protocols like <em>QUIC </em>and <em>Cronet</em>, etc.</li><li><strong>IO-Manager </strong>layers provide the abstraction for <em>gRPC </em>read/write(i.e. endpoints)<br>This layer also provides the network utilities, Timers and a bunch of other primitives that are platforms specific(Windows-based or <em>POSIX </em>based implementation)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*3xmPESMG5M4AozvdPEqyNA.png" /><figcaption>gRPC architecture</figcaption></figure><p><strong>Types of RPC.</strong></p><ul><li>There are four types of <em>RPC, </em><strong>Unary</strong>, <strong>Client Streaming</strong>, Server Streaming, and Bidirectional Streaming we are going to discuss the first two.</li><li><strong>Unary </strong><em>RPC </em>is used where the client sends exactly one message and receives one response just like a normal function call</li><li><strong>Client Streaming</strong> is where the client writes a sequence of messages and sends then to the server using the provided stream</li></ul><p><strong>Let’s discuss Channel.</strong></p><ul><li>A Channel is a communication pipe or tunnel between the client and the target.</li><li>A call is bound to a <em>Channel</em>, it has many to one relation meaning multiple calls can share the same <em>Channel</em>.</li><li>Client and Server perform ops(Calls) in batches, they can perform all the operations in batch or split it into multiple batches based on the <em>RPC</em>.</li><li>Once a batch of ops is finished it’s notified in the <em>Completion Queue</em>.</li><li>A <em>Completion Queue </em>is a queue that keeps the record of the batches, once a batch is done with the ops its notified in the <em>Completion Queue </em>so that the next batch can be executed.</li><li>Messages exchanged between Client and Server are as following<br><strong>Send the initial metadata. </strong>Exactly once per Call by server and client<br><strong>Receive initial metadata. </strong>Exactly once per Call by server and client<br><strong>Send message. </strong>Zero or more by server and client(only one message sent for Unary <em>RPC</em>)<strong><br>Receive message. </strong>Zero or more by server and client(only one message sent for Unary <em>RPC</em>)<strong><br>Send trailing metadata. </strong>Exactly once per Call by server and client<strong><br>Receive trailing metadata. </strong>Exactly once per Call by server and client</li><li><strong>Channel-Creation</strong><br> — A Completion Queue get created and a thread waits to watch this queue forever<br> — Calls API to create a Channel to the server and specify a server URI<br> — Client channel filter chooses a resolver based on the URI scheme of the server<br> — The resolver returns a list of addresses theses addresses will the server addresses<br> — Client channel filter then initializes LB policy, currently, there are 3 LB policies- Pick First(used by default), Round Robin, gRPC LB<br> — This is called client channel Load Balancing<br> — Client channel filter then creates <em>Channel </em>with all the backends returned by the resolver</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*dsuzwfwdu_ar3747i7g6cQ.jpeg" /><figcaption>The client created a channel with all the servers returned by the resolver</figcaption></figure><ul><li><em>Channel </em>creation happens in a lazy fashion, it doesn’t create the <em>Channel </em>immediately, it waits until a Call(request) is made to the server(please keep it in mind)</li><li>Once the server acknowledges the channel creation by the client, the client creates <strong><em>Sub-Channels.</em></strong></li><li><em>Channel </em>is a collection of <em>Sub-Channels</em>, it’s the <em>Sub-Channels</em> that actually maps the calls to the server</li><li><em>Channel </em>creation can take up to 3 seconds(please keep it in mind we have a use case to discuss)</li></ul><p><strong>Types of Stub</strong></p><ul><li>On the client-side client has an object known as a stub, there are two types of stub- <strong>Blocking, Non-Blocking, </strong>and <strong>Listenable Future Stub.</strong></li><li><strong>Blocking Stub </strong>is when the client sends a request to the server and waits for the response.</li><li><strong>Non-Blocking Stub </strong>is used to make a streaming call, it makes the calls asynchronously and response is returned asynchronously from the server. This stub can be used for Client-side streaming RPC calls.</li><li><strong>Listenable Future Stub</strong> is when the client doesn’t wait for the response and the call returns a ListenableFuture. The client should add a callback to get the response for the requests.</li><li>Refer <a href="https://grpc.io/docs/what-is-grpc/core-concepts/#:~:text=gRPC%20lets%20you%20define%20four,like%20a%20normal%20function%20call.&amp;text=Client%20streaming%20RPCs%20where%20the,again%20using%20a%20provided%20stream."><em>here </em></a>for more info</li></ul><p><strong>What is Deadline?</strong></p><ul><li>A <em>Deadline </em>is a time duration that allows a client to specify for how long it is ready to wait for and <em>RPC </em>to get completed. The<em> deadline</em> is absolute in time. If the server takes more time than the Deadline, the RPC is terminated with <em>DEADLINE_EXCEEDED </em>error.</li></ul><p><strong>How the deadline is propagated across RPC?</strong></p><ul><li>A deadline is calculated before making an RPC calls to the server stub</li><li>Deadline deadline = current timestamp + deadline duration</li><li>When current timestamp becomes greater than the deadline, RPC gets terminated</li><li>The server always knows if an RPC is valid</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSXDF0bXRkDPz7gDMPNK9w.png" /><figcaption>Deadline propagation across RPC</figcaption></figure><p><strong>Java Client example with Deadline</strong> for the server that we had created in the <a href="https://medium.com/@yadav.vikesh27/grpc-java-implementation-from-scratch-b7bd8f337571"><em>previous </em></a>article<em>.</em></p><p>One more class <em>GrpcClient.java</em> is added in the same package where the server is present(check the image for structure). Get the code from this <a href="https://github.com/vickxy/hello.git"><em>GitHub repository</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nR4FesAp5ooZrzuDCMRjLg.png" /><figcaption>Project structure after adding gRPC Java Client</figcaption></figure><p><strong>Let’s discuss gRPC client. </strong>In order to create a gRPC client, we need to create the channel first by providing the <em>host</em> and the <em>port</em>. After that, We are going to create a Blocking and a Listenable Future Sub(explained earlier) to explain the working.</p><p>Once the client stub is created we can now make an RPC call and get the response from the server. We have used a 5 ms deadline for the RPC call.</p><p>In case if the server is not able to reply within 5ms client will terminate the request <em>Stream </em>and a <em>DEADLINE_EXCEEDED </em>exception is thrown. If there is no server-side Deadline, the server will process the request for sure.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/767699549d3ac54775e2038086e94838/href">https://medium.com/media/767699549d3ac54775e2038086e94838/href</a></iframe><p>Response from both Blocking and Future stubs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g2s4y4VqN5619mDOd6hafQ.png" /></figure><p>Exception when Deadline exceeded</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9W-RN6cXLuOqT0uOvphYg.png" /></figure><p><strong>Why gRPC servers don’t receive the first few packets if the Deadline is smaller?</strong></p><p>Scenario: We had to implement a gRPC client with a 5ms Deadline. We noticed that the server was not getting the some of the initial requests sent by the client.</p><p>Now that the server didn’t receive any request from the client but the client made requests and threw <em>DEADLINE_EXCEEDED </em>exception, <strong>what happened to request?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u88DuT6ACtgUmOTIFT9h4w.png" /></figure><p>Read the error message carefully that says <strong>waiting_for_connection</strong>. Let’s dig deep into it and will explain what is going on</p><ul><li>The client sent a request to the server to establish a channel.</li><li>As we know channel creation is a lazy job, it&#39;s not created immediately until we make an RPC call.</li><li>Client starts sending a request(by this time channel is not established) request waits for the channel to get established.</li><li>By the time deadline exceeds and client terminates the RPC and throws <em>DEADLINE_EXCEEDED </em>exception.</li><li>So basically the RPC call didn’t reach the server stub and hence we miss the initial requests at the server-side.</li><li>To conclude this let’s look at the <a href="https://www.tcpdump.org/manpages/tcpdump.1.html"><em>TCPdump</em></a> in <a href="https://www.wireshark.org/"><em>Wireshark</em></a><em>, </em>The IP ending with .224 is the client stub and that ending with .41 is the server stub.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YYgIsQ2sa9xT5Z4j1J5-hg.jpeg" /><figcaption>tcpdump from the client machine</figcaption></figure><ul><li>We can see that the first few attempts failed to establish the channel, hence any RPC call made in this duration will not reach the server.</li><li>We can also see that it took 2.72 seconds to establish the channel and then a successful RPC call was made and it reached the server as well.</li><li>Look at this screenshot, here the first call with a 1-second deadline got served by the server and later request throws the DEADLINE_EXCEEDED exception with message <strong>[remote_addr=/127.0.0.1:8080]</strong>. It means that channel is established.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAn9-RXZbGUnVmzWT52tHg.png" /></figure><p>The complete codes mentioned here can be found in this repo:</p><p><a href="https://github.com/vickxy/hello.git">vickxy/hello</a></p><p>References:<br><a href="https://grpc.io/docs/languages/java/basics/"><em>https://grpc.io/docs/languages/java/basics/</em></a><em><br></em><a href="https://www.wireshark.org/"><em>https://www.wireshark.org/</em></a><em><br></em><a href="https://www.tcpdump.org/manpages/tcpdump.1.html"><em>https://www.tcpdump.org/manpages/tcpdump.1.html</em></a></p><p>Happy Coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd7b8289ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gRPC Java implementation from scratch]]></title>
            <link>https://yadav-vikesh27.medium.com/grpc-java-implementation-from-scratch-b7bd8f337571?source=rss-e150cb124ff3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7bd8f337571</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[protobuf]]></category>
            <dc:creator><![CDATA[Vikesh Yadav]]></dc:creator>
            <pubDate>Sat, 15 Aug 2020 12:30:35 GMT</pubDate>
            <atom:updated>2020-08-15T20:56:05.773Z</atom:updated>
            <content:encoded><![CDATA[<h3>gRPC microservice implementation in Java from scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UstjscP-MnlCuXO4uvDoaQ.png" /></figure><p>The objective of this article is to implement gRPC in Java. There would be a follow-up article as well based on the use cases and the challenges that I have gone through.</p><p>By the time you are reading this article, I am sure you have heard about gRPC and it’s working. But still here is a quick introduction to gRPC and its attributes.</p><p><strong>What is gRPC?</strong> <br><a href="https://grpc.io/"><em>gRPC</em></a> is a very lightweight communication protocol from Google. At high-level, it allows you to define REQUEST and RESPONSE for RPC(Remote Procedure Calls) and handles for you.</p><p>It’s a high performance, standards-based, open-source feature-rich universal <a href="https://users.cs.cf.ac.uk/Dave.Marshall/C/node33.html"><em>remote procedure call</em></a> (RPC) framework. It’s compatible with more than dozens of programming languages.</p><p>gRPC is designed to make the client believe that the server is residing on the same machine as the client. gRPC client invokes the method on the client stub, which is handled by the PRC protocol.</p><p>gRPC is based on <a href="https://developers.google.com/protocol-buffers"><em>Protocol Buffers</em></a><em>, </em>an open-source Interface Definition Language and serialization library. It’s smaller, faster, and more efficient in terms of CPU consumption than other wired-format protocols.</p><p><strong>Why we should use gRPC?<br></strong><em>gRPC</em> works with many transports, by default it uses HTTP/2 but it can also be implemented on <a href="https://blog.cloudflare.com/the-road-to-quic/"><em>QUIC</em></a><em> </em>, <em>Cronet</em>, etc.</p><p>In HTTP/2 protocol client stub talks to the server stub on a single TCP connection called <a href="http://foo.com/"><em>Channel</em></a>. A Channel is a tunnel that is established between client and server stub once and the requests are multiplexed to be in flight without compromising network resources. The payload is converted to binary rather than text(in REST+JSON) that keeps the payload compact and efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*1qX5pzO0ROPPhIl4iaLKoQ.png" /></figure><p><strong>Maven Project Setup<br></strong>It’s time to create a simple server in Java. Let’s set up a new Maven project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*faW2-Ezaj4bg9E-YWOxQdQ.png" /><figcaption>Creating a new Maven project</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR1B-C9cA5nZ8iymwVPweg.png" /><figcaption>The project is ready</figcaption></figure><p><strong>Dependencies<br></strong>Now that we are done with the project set up, let’s add the dependencies for gRPC and Protocol Buffer in pom.xml.</p><p><em>grpc-netty — </em>is used for the networking layer</p><p><a href="https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java/3.6.1"><em>protobuf-java</em></a> — is used for encoding structured data in an efficient yet extensible format.</p><p><a href="https://mvnrepository.com/artifact/io.grpc/grpc-protobuf/1.30.0"><em>grpc-protobuf</em></a> — is used to support the Protocol Buffer layer</p><p><a href="https://mvnrepository.com/artifact/io.grpc/grpc-stub/1.30.0"><em>grpc-stub</em></a><em> — </em>is used to support server stub</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zn7tt3ug23C92QXpN_NwrA.png" /><figcaption>Dependencies are added in the pom.xml</figcaption></figure><p><strong>Define Protocol Buffer<br></strong>We should have two source directories for the code. In the Java directory, we will put the source code of the gRPC server</p><p>In the proto source directory, we will place our Protocol Buffer files</p><p><em>java_multiple_files</em> — option allows the compiler to create different classes for all it’s components i.e. HelloRequest.java and HelloReply.java</p><p>java_package — option allows the compiler to create a new package and keep the gRPC classes in it</p><p>The proto contains a service which has a simple <em>RPC </em>where a client will send a request and wait for the response, the call will be just like a normal function call</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksWrkD89vP6CYlqncqavYA.png" /><figcaption>Protocol Buffer file</figcaption></figure><p>Now that we have protobuf file in place, we will add the plugin in pom.xml to compile it<br><em>inputDirectories</em> — path to .proto files<br>outputDirectories — source path for auto-generated gRPC classes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2cgPWwKBbvoK6TE62Ib0g.png" /><figcaption>Compiler plugin</figcaption></figure><p>Configure manifestEntries<br><em>Main-Class — </em>enter the main class to be executed inside the jar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhDvuEDXhn0dPBuyC7zELw.png" /></figure><p>Generate client and server stub code using protocol buffer compiler by clicking update maven project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhTD4qoD-tcBWjyAE7pNow.png" /><figcaption>Create gRPC classes</figcaption></figure><p>We should see gRPC classes in the configured package</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*w-EwOvf3UBiCpHmBfzaD_Q.png" /><figcaption>Auto-generated gRPC classes</figcaption></figure><p><strong>Server<br></strong>In order to start the gRPC server, we need to extend the generated server class and fill the logic of the service. <br><em>HelloService </em>is a new class present in a separate package <em>src/main/services. </em>In this class, we will extend <em>HelloServiceImplBase </em>and override the <em>sayHello</em> method.<em><br></em>We are preparing the response by greeting the caller with hardcoded <em>“Hello”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAipJM5XLIISaUkmcSDgwg.png" /><figcaption>Implement the service to receive the request and reply back</figcaption></figure><p>Let&#39;s start the server now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtDAOsYqe1SDWUclqjLYng.png" /><figcaption>The server is running on port 8080</figcaption></figure><p>Our gRPC server is running now. We can test the server using <a href="https://github.com/uw-labs/bloomrpc"><em>BloomRPC</em></a> tool that allows us to make an RPC request just like Postman for REST request.</p><p>To set it up we need to download the binary(from <a href="https://github.com/uw-labs/bloomrpc"><em>here</em></a>) and import the proto file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nuK1xLOXghHwGCpSIcDQfw.png" /><figcaption>BloomRPC request to server stub and the response</figcaption></figure><p>The complete codes mentioned here can be found in this repo:</p><p><a href="https://github.com/vickxy/hello.git">vickxy/hello</a></p><p>Happy Coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7bd8f337571" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>