First of all, you need to install Ballerina language 1.2.0+. Please refer to the official Ballerina website to follow the step by step guidelines to install Ballerina language in your preferred platform (macOS, Linux, or Windows). There are installers released for each platform. However, I normally preferred to use binaries to install Ballerina even though it is not the easiest way to do it.
- Download Ballerina 1.2.0+ binaries from here.
- Extract the zip file. Let assume you have extracted into your
/home
directory. Now you have Ballerina binaries in a directory called/home/ballerina-1.2.0/
. - Setup your
PATH
environment variables like below (Normally, in Linux and macOS environments you can set the PATH variable by changing one of~/.bash_profile, ~/.bashrc, ~/.zshrc, or ~/.profile
files).export BALLERINA_HOME="/home/ballerina-1.2.0/bin" export PATH=$PATH:$BALLERINA_HOME
- That's it, now you can simply reload the terminal and verify ballerina installation.
$ ballerina version
- Clone this repository.
$ git clone https://github.com/BuddhiWathsala/grpc-healthcare-app.git
- Navigate to the app.
$ cd grpc-healthcare-app
- Build the app.
$ ballerina build -a
- Run the gRPC server.
$ ballerina run target/bin/server.jar
- In another terminal, run the gRPC client.
$ ballerina run target/bin/client.jar
Before implementing a gRPC Ballerina app, you need to install Ballerina as I discussed in the previous section.
After that, you can create a new Ballerina project using the following command.
$ ballerina new grpc-healthcare-app
In this implementation, I have created two separate modules for the client and the server implementation. Create client and server Ballerina modules as follows.
$ cd grpc-healthcare-app
$ ballerina add client
$ ballerina add server
The Ballerina CLI tool has enriched with the support of generating boilerplate codes of the gRPC server and client. Hence, you can generate boilerplate codes of the server and the client using the following commands.
Server Code Generation:
$ cd src/server
$ ballerina grpc --input health-stub.proto --mode service --output .
Client Code Generation:
$ cd src/client
$ ballerina grpc --input health-stub.proto --mode client --output .