Sample nodejs demo project to learn gRPC client and server procedure call.
Protocal buffer are a mrthod of serializing data, helpful in communication between microservice unlike json and xml protocal buffer are optimized way to serailize the data. and protocal buffer are independent to the language in implementation.
Key Feature
- Binary mode of data transfer.
- Separartion of data and context.
- Message format data
Reason to use proto buffer
- Schema are awesome
- Backward compatibility for free.
- Validation and extensibility.
- Easy language interporability.
Writing proto file
proto file Name: employee.proto
syntax = "proto3";
message Employee {
int32 id = 1;
string name = 2;
float salary = 3;
}
message Employees {
repeated Employee employeeList = 1; /** Array of Employee **/
}
Generate CA
1. Generate RSA
`openssl genrsa -aes256 -out ca-key.pem 4096`
2. Generate a public CA Cert
`openssl req -new -x509 -sha256 -days 365 -key ca-key.pem -out ca.pem`
Generate Certificate
1. Create a RSA key
`openssl genrsa -out cert-key.pem 4096`
2. Create a Certificate Signing Request (CSR)
`openssl req -new -sha256 -subj "/CN=yourcn" -key cert-key.pem -out cert.csr`
3. Create a extfile with all the alternative names
``
- Clone the repo
- Install all dependencies in both client and server
npm i
- Add .env file
- run both client and server in different port
- Make api call from clinet to make RPC call