Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mabuonomo/example-nestjs-microservices-grpc

NestJS + gRPC: a multi microservices example
https://github.com/mabuonomo/example-nestjs-microservices-grpc

docker grpc microservices nestjs nestjs-grpc prisma proto protobuf

Last synced: 2 days ago
JSON representation

NestJS + gRPC: a multi microservices example

Awesome Lists containing this project

README

        

# NestJS + gRPC: a multi microservices example

This repo show as to configure a multi microservices stack in NestJS using gRPC in docker environment.

## Docker Stack

- 3 NestJS microservices
- 1 NestJS client
- 1 Prisma server
- 1 DB MySQL

## Run it!

```bash
make init
docker-compose up
```

Navigate to

```
http://localhost:3000/test/client1
http://localhost:3000/test/client2

http://localhost:3000/test/client_prisma_add
http://localhost:3000/test/client_prisma_get
```

## Protobuf (*.proto) builder
This project use ts-proto library to generate interfaces from *.proto files.

Just add/edit some proto file into proto folder, then run:
```sh
make proto_build
```

For example, this proto file:
```protobuf
syntax = "proto3";
import "google/protobuf/empty.proto";

package micr_prisma;

service MicrService {
rpc FindOne (google.protobuf.Empty) returns (UserList) {}
rpc Save (google.protobuf.Empty) returns (User) {}
}

message User {
string id = 1;
string name = 2;
string surname = 3;
}

message UserList {
repeated User users = 1;
}
```

generate the following typescript code:
```ts
/* eslint-disable */
import { Empty } from './google/protobuf/empty';

export interface User {
id: string;
name: string;
surname: string;
}

export interface UserList {
users: User[];
}

export interface MicrService {

FindOne(request: Empty): Promise;

Save(request: Empty): Promise;

}
```
We can use these interfaces in NestJS project easily.

## Documentation

- Blog

## Thanks to

- NestJS
- gRPC
- Prisma.io
- ts-proto