Why you need to Glue ?

When I was beginning my career in programming I used to wonder how two applications in different programming language can be made to interplay. Let me ease that.

Suppose your API engine is running over .NET core and you want to implement a PDF creator. Now one solution could be to find a library implemented in .NET core only. But, what if no such library is available or the one that’s available is paid one ? 
Then, another solution could be to implement the PDF creator portion using some other library like PDFkit – which by the way is implemented in Node.js

But wait, how you can make Node.js and .NET core work together ? There can be many methods like COM interfacing, IPC, Web service based approach. But the most easiest and least intrusive among them is achieved by using middleware like Kafka or RabbitMQ

In this post we will be discussing Kafka.

To keep things easy, I will be using docker so that I get a pre-configured kafka environment. Find it’s image here.

What we will be building ?

We will simulate control of applications in different technologies. We shall build :

  1. Master app (.NET Core console app) – that will direct slave app to initiate or kill project.
  2. Slave app (.NET Core console app) – that will start or close a C++ app that prints “Hello World” in an infinite while loop.
  3. Controlled app (C++ app) – simple hello world application in C++.
  4. Slave and Master app will communicate over Kafka.

In this example I am using two .NET Core console program to control a CPP application. In similar fashion, multiple applications in different languages can be made to communicate. Kafka producer-consumer connectors are available for all major languages.

Please find code of the demo project at: https://github.com/jyotendra/kafka-demo

Here’s the final result:

I have coded it over ubuntu – you might need to change your build command in case of C++ sample project to suit your OS. Let me know in comments if you have any questions.