Skip to main content

Putting gRPC multi language support to the test

Putting gRPC multi language support to the test




gRPC is an RPC framework developed and open-sourced by Google. There are many benefits to gRPC, such as efficient connectivity with HTTP/2, efficient data serialization with Protobuf, bi-directional streaming and more, but one of the biggest benefits is often overlooked: multi-language support.

Out of the box, gRPC supports multiple programming languages : C#, Java, Go, Node.js, Python, PHP, Ruby and more. In the new microservices world, the multi-language support provides the flexibility you need to implement services in whatever language and framework you like and let gRPC handle the low-level connectivity and data transfer between microservices in an efficient and consistent way.

This all sounds nice in theory but does it work in reality? As a long-time Java and C# developer, I wanted to see how well gRPC delivered on its multi-language promise. The plan was to run a couple of Java gRPC samples to see how gRPC worked in Java. Then, I wanted to see how easy it would be to port those samples into C#. Finally, I wanted to mix and match Java and C# clients/servers and see how well they worked together.

gRPC Java support

First, I wanted to figure out how well gRPC supports individual languages. Getting started with Java is pretty straightforward just add the Maven or Gradle dependencies and plugins. Ray Tsang, a colleague and Java expert, has written and published some gRPC samples in Java in his GitHub repository, so I started exploring those.

I tried a simple gRPC client and a simple gRPC server written in Java. These are "Hello World"-type samples, where a client sends a request to the server and the server echoes it back. The samples are Maven projects, so I used my favorite Java editor (Eclipse) to import the projects into a new workspace. First, I started the server:

Starting server on port 8080 Server started!

Then, I started the client. As expected, the client sent a request and received a response from the server:

Sending request Received response: Hello there, Mete

Ray also has a more interesting sample that uses a bi-directional streaming feature. He built a chat server and a chat client based on JavaFX to talk to that server. I was able to get the two chat clients talking to each other through the chat server with little effort.



Two JavaFX clients talking to each other via Java server

gRPC C# support

So far so good. Next, I wanted to see how easy it was to rewrite the same samples in C#. With a little help from the gRPC documentation samples, I was able to create a GreeterClient and a GreeterServer for the Hello World sample. The code is very similar to Java but it looks a little nicer. (Ok, Im biased in favor of C# :-) )

One minor difference: with Java, you can use Maven or Gradle plugins to generate gRPC stub classes automatically. In the case of C#, you need to bring in the gRPC Tools NuGet package and generate the stub classes with it. Take a look at generate_protos.bat to see how I did that. The good news is that you can rely on the same service definition file to generate Java and C# stub clients, which makes it easy to write client and server apps in different languages.

I also implemented the bi-directional streaming chat example with ChatServer and ChatWindowsClient but instead of JavaFX, I used Windows Forms. As before, the code is quite similar to the Java version but gRPC takes advantage of the language to make sure developers are not missing out on language specific features.

For example, ChatServerImpl.java creates and returns a StreamObserver as a handler for client messages. This works but felt a little unintuitive. On the other hand, ChatServerImpl.cs uses the async/await pattern of C# and writes to the response stream asynchronously, which yields a cleaner implementation.

gRPC multi-language test

The real test for multi-language support is how well Java and C# implementations work together. To test that, I started the Java chat server. Then, I started a Java chat client and a C# chat client both talking to the same Java chat server. It was nice to see the two clients talking to each other through the chat server with no special configuration or effort on my part.
One Windows Form client and one JavaFX client talking to each other via Java server


Conclusion

Designing a framework is hard. Designing a framework that works across different languages while maintaining the unique benefits of each language is even harder. Whether I worked with gRPC in Java or C#, it never felt alien. Its obvious that a lot of thought and effort went into making sure that gRPC was idiomatic for each language. Thats great to see from a framework trying to cover a wide range of languages.

If you want to run the samples yourself, take a look at Rays Java gRPC samples and my C# gRPC samples. You can also watch a recording of Ray�s talk on Java gRPC.

Happy gRPCing! :-)

download file now

Popular posts from this blog

Ragnos1997 Low Specs Patches for low PC Download

Ragnos1997 Low Specs Patches for low PC Download Ragnos1997 Low Specs Patches for Low PC Full Download "Let your system breathe, and enjoy even the latest games on your low end hardware. Only with Low Specs Experience�" Which games are affected ? ALAN WAKE ALAN WAKE�S AMERICAN NIGHTMARE ALIEN: ISOLATION ALIEN: COLONIAL MARINES 7 DAYS TO DIE AMERICAN TRUCK SIMULATOR ANNO 2205 ARMA III ASSASSIN�S CREED ASSASSIN�S CREED II ASSASSIN�S CREED BROTHERHOOD ASSASSIN�S CREED REVELATIONS ASSASSIN�S CREED III ASSASSIN�S CREED III LIBERATION HD ASSASSIN�S CREED IV BLACK FLAG ASSASSIN�S CREED UNITY ASSASSIN�S CREED ROGUE ASSASSIN�S CREED SYNDICATE BATMAN ARKHAM ORIGINS BATMAN ARKHAM ORIGINS BATTLEFIELD BAD COMPANY 2 BATTLEFIELD 3 BATTLEFIELD 4 BATTLEFIELD HARDLINE BATTLEFIELD 1 BIOSHOCK INFINITE BORDERLANDS BORDERLANDS 2 BORDERLANDS THE PRE-SEQUEL CALL OF DUTY BLACK OPS CALL OF DUTY BLACK OPS II CALL OF DUTY BLACK OPS III CALL OF DUTY GHOSTS CALL OF DUTY ADVANCED WARFARE CALL OF DUTY INFIN...

TDATS fourth birthday festive greetings to you all!

TDATS fourth birthday festive greetings to you all! No music here....just a thanks to all the people who have been following this blog, four years down the line and I am still finding new ideas and receiving helpful pointers from readers who are often more informed than me....so thanks to you all. Please reply here or email me with any tips and ideas for the blog....you can also join in and contribute to TDATS news in the fb group.....I have some new ideas in the works....the next post in a few days, in time to be a Christmas present to you all, will be a revealing interview and story regarding a great band that I dont think has been spotlighted anywhere as yet.....and I have more plans to do that kind of thing next year....there are plenty more themes in the works....any advice that readers would like to offer on South-East Asia, East-European and latin american bands would be gladly followed up and if you can think of any other themes that will go down well here let me know! Happy ho...

Ramayana Soul Sabdatanmantra � �地獄 Scattered Purgatory God of Silver Grass

Ramayana Soul Sabdatanmantra � �地獄 Scattered Purgatory God of Silver Grass Reviewed by Nathan Ford There are few who read this rag who would doubt that we place Kikagaku Moyo at the very pinnacle of the current Japanese psychedelic scene. That being the case, its not unusual at all to discover that Guruguru Brain, the label run by Kikagaku Moyos Tomoyuki Katsurada is a veritable treasure trove of adventurous psychedelia, inhabited by names known to few in the Western world. Their first release was a wonderful and essential sampler of modern Japanese psychedelia which can still be downloaded for free here, but its two more recent releases that we concern ourselves with today. Ramayana Soul is first on the turntable, and while the band are actually Indonesian, its obvious why Katsuradas interest was peaked. "Sabdatanmantra" is a joyous wonder that perfectly illustrates the singular way in which Eastern psychedelia embraces free form spontaneity without sacrificing a tune, or in...