# celepar-microservices-grpc

> Basic lib to handle microservices with gRPC and Redis

Latest version **1.4.3** (published 2018-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install celepar-microservices-grpc
pnpm add celepar-microservices-grpc
yarn add celepar-microservices-grpc
bun add celepar-microservices-grpc
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.3 |
| Published | 2018-12-06 |
| First published | 2017-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 30.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Andre Avila |
| Maintainers | chameleonbr |
| Keywords | grpc, nodejs, redis, microservices |

## Links

- npm: https://www.npmjs.com/package/celepar-microservices-grpc
- Repository: https://github.com/chameleonbr/celepar-microservices-grpc
- Homepage: https://github.com/chameleonbr/celepar-microservices-grpc#readme
- Issues: https://github.com/chameleonbr/celepar-microservices-grpc/issues
- npm.io page: https://npm.io/package/celepar-microservices-grpc

## Dependencies (8)

- [rr](https://npm.io/package/rr.md) ^0.1.0
- [grpc](https://npm.io/package/grpc.md) ^1.14.2
- [pino](https://npm.io/package/pino.md) ^5.5.0
- [async](https://npm.io/package/async.md) ^2.6.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [ioredis](https://npm.io/package/ioredis.md) ^4.0.0
- [fixedqueue](https://npm.io/package/fixedqueue.md) 0.0.1
- [@grpc/proto-loader](https://npm.io/package/@grpc/proto-loader.md) ^0.3.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.4.3 (latest) — 2018-12-06
- 1.4.2 — 2018-12-03
- 1.4.1 — 2018-11-19
- 1.4.0 — 2018-10-30
- 1.3.7 — 2018-09-11
- 1.3.6 — 2018-08-09
- 1.3.5 — 2018-04-11
- 1.3.4 — 2018-04-10
- 1.3.3 — 2018-04-10
- 1.3.2 — 2018-04-06
- 1.3.1 — 2018-04-06
- 1.3.0 — 2018-04-06
- 1.2.5 — 2017-12-28
- 1.2.4 — 2017-12-28
- 1.2.3 — 2017-12-28
- … 10 more at https://npm.io/package/celepar-microservices-grpc/versions

## README

# celepar-microservices-grpc
Basic Microservices lib, working with gRPC and Redis.

The idea is take advantage of Redis pub/sub and sets to find available servers and connect directly to them.
If you add more services, it will be detected automatically and client will call them.
If one or more service fall, the client will try to another.



server.js
```javascript
const { Server } = require('celepar-microservices-grpc')

const srv = new Server({
    package: 'helloworld',
    service: 'Greeter', // You could make diferent services from the same proto file
    proto: __dirname + '/hello.proto',
    redis: {
        host: 'localhost',
        port: 6379,
        db: 10
    }
})

let obj = {
    SayHello: async(ctx) => {
        return {
            message: 'Hello ' + ctx.request.name + ' ' + Date.now() 
        }
    },
    SayBye: async(ctx) => {
        return {
            message: 'Hello ' + ctx.request.name + ' ' + Date.now() 
        }
    }
}
// OR

class Test {
    SayHello(ctx) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve({
                    message: 'Hello ' + ctx.request.name + ' ' + Date.now() 
                })
            }, Math.floor((Math.random() * 100) + 1)) // random response time

        })
    }
    async SayBye(ctx) {
        return {
            message: 'Hello ' + ctx.request.name + ' ' + Date.now() 
        }
    }
}

srv.use(new Test()).start()
```


client.js
```javascript

const { Client } = require('celepar-microservices-grpc')

let cli = new Client({
    services: [{ // You could add more services from the same proto file
        package: 'helloworld',
        service: 'Greeter',
    }],
    proto: __dirname + '/hello.proto',
    redis: {
        host: 'localhost',
        port: 6379,
        db: 10
    }
}).start()

let test = async() => {
    try {
        let res = await cli.helloworld.Greeter.sayHello({
            name: 'World'
        })
        console.log(res)
    } catch (err) {
        console.log('error', err)
    }
}
test()
```

---
_Source: https://npm.io/package/celepar-microservices-grpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
