Skip to content

πŸ”— Two microservices that communicates through gRPC that together displays a product list with custom discounts per user.

Notifications You must be signed in to change notification settings

paulononaka/ruby_node_grpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

68 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

mailto:paulononaka@email.com CI


✨ Ruby & Node with gRPC ✨


Two microservices that communicates through gRPC that together displays a product list with custom discounts per user.

Project structure

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

Requirements

This application relies on Docker.

Setup

docker-compose build

Running

docker-compose up

Server

A gRPC server made in Ruby (server folder).

The server service receives two RPC arguments and answers with the discount.

Server structure

server
β”œβ”€β”€ lib         // Serve service functions that connects to the gRPC Client
β”‚   └── models  // Models that represents the local storaged data
β”œβ”€β”€ spec        // Rspec tests  

How to regenerate the protos

Install grpc-tools:

gem install grpc-tools

Then:

rake generate_proto

Client

A gRPC client made in Node (client folder).

The gRPC client consumes the gRPC server and exposes a HTTP endpoint GET /product.

Client structure

client
β”œβ”€β”€ src
β”‚   └── api     // Espresso endpoints
β”‚   └── repository  // Functions to returns the local storaged data
β”‚   └── service     // Client services functions that connects to the gRPC Server 

Request samples

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
    }
  }
]

About

πŸ”— Two microservices that communicates through gRPC that together displays a product list with custom discounts per user.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published