1.0.1 • Published 5 months ago

nestjs-base-client-abstraction v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

NestJS Microservice Client

A base client abstraction for NestJS microservices with built-in retry and timeout handling.

Installation

npm install nestjs-microservice-client

Usage

import { BaseClientAbstract } from 'nestjs-microservice-client';
import { Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';

@Injectable()
export class UserServiceClient extends BaseClientAbstract {
  constructor(
    @Inject('USER_SERVICE') client: ClientProxy
  ) {
    super(client, {
      timeout: 10000,      // Optional: override default timeout
      retryAttempts: 10    // Optional: override default retry attempts
    });
  }

  async getUser(id: number) {
    return this.fetchData(
      'user.get',
      { id },
      'User service timeout',
      'User service error'
    );
  }
}

Features

  • Configurable timeout and retry attempts
  • Error handling with appropriate exceptions
  • Built on top of RxJS
  • TypeScript support
  • NestJS integration

License

MIT

1.0.1

5 months ago

1.0.0

5 months ago