# @kerthin/microservice

> kerthin microservice

Latest version **0.0.1-alpha.7** (published 2022-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kerthin/microservice
pnpm add @kerthin/microservice
yarn add @kerthin/microservice
bun add @kerthin/microservice
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.7 |
| Published | 2022-02-22 |
| First published | 2020-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 109.7 KB |
| Known vulnerabilities | 0 (+4 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | thekerthin@gmail.com |
| Maintainers | sebastian.delaroche |
| Keywords | kerthin, microservice |

## Links

- npm: https://www.npmjs.com/package/@kerthin/microservice
- Repository: https://github.com/thekerthin/miscellaneous
- Homepage: https://github.com/thekerthin/miscellaneous#readme
- Issues: https://github.com/thekerthin/miscellaneous/issues
- npm.io page: https://npm.io/package/@kerthin/microservice

## Dependencies (13)

- [mqtt](https://npm.io/package/mqtt.md) ^4.0.1
- [nats](https://npm.io/package/nats.md) ^1.4.9
- [rxjs](https://npm.io/package/rxjs.md) ^6.5.5
- [uuid](https://npm.io/package/uuid.md) ^8.0.0
- [ramda](https://npm.io/package/ramda.md) ^0.27.0
- [redis](https://npm.io/package/redis.md) ^3.0.2
- [amqplib](https://npm.io/package/amqplib.md) ^0.5.5
- [kafkajs](https://npm.io/package/kafkajs.md) ^1.11.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^7.0.11
- [@types/sinon](https://npm.io/package/@types/sinon.md) ^9.0.0
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^7.0.11
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 0.0.1-alpha.7 (latest) — 2022-02-22
- 0.0.1-alpha.2 — 2021-11-02
- 0.0.1-alpha.1 — 2021-11-02
- 0.0.1-alpha.0 — 2021-08-10
- 0.0.2-0 — 2020-05-25
- 0.0.1-0 — 2020-05-25

## README

# `@kerthin/microservice`

This package helps you building decouple systems where the projects can scale up from a monolith system to microservice system without any troubles just changing a couple code lines.

## Installation

```sh
$ yarn add @kerthin/microservice
# or
$ npm i @kerthin/microservice
```

## Usage

_**Note:** So far this package is only available for [nest.js](https://nestjs.com/) framework but in the future we'll support different frameworks and programing languages_

### Create DTO

```ts
import { TransferDataDto } from '@kerthin/microservice';

class CreateUserDto extends TransferDataDto {

  name: string;

  lastName: string;

  birthday: Date;

  ...
}
```


### Create Command

```ts
import { Command } from '@kerthin/microservice';

class CreateUserDto extends Command<CreateUserDto> {

  public readonly action = 'create';

  public readonly context = 'user';

}
```

### Create Service

```ts
import { Injectable } from '@nestjs/common';
import { Broker } from '@kerthin/microservice';

@Injectable()
export class UserService {

  constructor(private readonly broker: Broker) {}

  create(data: CreateUserDto) {
    return this.broker
      .start()
      .add(new CreateUserDto(data))
      .end();
  }

}
```

### Create Command Handle

```ts
import { CommandHandler, ICommandHandler } from '@kerthin/microservice';

@CommandHandler(CreateUserCommand)
export class CreateUserHandler implements ICommandHandler<CreateUserCommand> {

  handle(command: CreateUserCommand) {
    // command.data -> compute your logic
  }

}
```

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