Two microservices that communicates through gRPC that together displays a product list with custom discounts per user.
client // Client folder written in NodeJS
data // Local storaged data in JSON
doc // Architecture Decision Records
protos // Protocol buffers
server // Server folder written in Ruby
This application relies on Docker.
docker-compose build
docker-compose up
A gRPC server made in Ruby (server folder).
The server service receives two RPC arguments and answers with the discount.
server
βββ lib // Serve service functions that connects to the gRPC Client
β βββ models // Models that represents the local storaged data
βββ spec // Rspec tests
Install grpc-tools:
gem install grpc-tools
Then:
rake generate_proto
A gRPC client made in Node (client folder).
The gRPC client consumes the gRPC server and exposes a HTTP endpoint GET /product.
client
βββ src
β βββ api // Espresso endpoints
β βββ repository // Functions to returns the local storaged data
β βββ service // Client services functions that connects to the gRPC Server
GET /
- Health check
Ok!
GET /product?userId=1
- Returns a list of products and its discounts for a specific user.
[
{
id: "1",
price_in_cents: 350,
title: "Coca Cola",
description: "It is nice to drink Coca",
discount: {
pct: 0,
value_in_cents: 24
}
},
{
id: "2",
price_in_cents: 2000,
title: "Cake",
description: "It is good to eat cake too",
discount: {
pct: 0,
value_in_cents: 24
}
}
]