npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@diamir/nestjs-microservice

v11.0.2

Published

Nestjs microservice-provider wrapper module and base-service

Downloads

348

Readme

nestjs-microservice

Description

RabbitMQ, NestJs-Microservice wrapper for easier microservice interaction.

Create the microservice-server as normal with NestJs (createMicroservice) and in the api (that interacts with that server) use this provider-utils.



Microservice-Provider Module

Register the provider that can be injected in any service to interact with the message-queue. The module is global by default.

import { Module } from '@nestjs/common'
import { MicroserviceProviderModule } from '@diamir/nestjs-microservice'

import { ExampleProvider } from '@libs/microservice-provider'

@Module({
  imports: [
    MicroserviceProviderModule.forRoot({ urls: ['http://localhost:5672'] }, [ExampleProvider])
  ]
})

Options

{ // type: ProviderOptions
  urls // message-queue urls
  clientOptions // (optional) options passed to the underlying `ClientRMQ`
  global // (default: true) if module is imported globally, 
  timeout // (default: 10 minutes) time in milliseconds when a timeout error is thrown if operation not yet completed 
  timeoutErrorFactory // (optional) custom error on time-out
  responseErrorFactory // (optional) custom error on response error
}

Microservice-Provider

To set up a new provider service, use the @MSP() decorator to define the MessageQueue to be used and extend the BaseMicroserviceProvider. In the service define/implement the methods to call the Message-Patterns of that queue.

Setup:

// libs/microservice-provider/mesage-queue.enum.ts
enum MessageQueue { // used in nestjs `createMicroservice` options
  EXAMPLE = 'EXAMPLE'
}

// libs/microservice-provider/provider/example/example.pattern.ts
enum ExamplePattern { // used in nestjs `@MessagePattern(..)`
  COMMAND_A = 'COMMAND_B',
  COMMAND_B = 'COMMAND_B'
}

// libs/microservice-provider/provider/example/example.provider.ts
import { BaseMicroserviceProvider, MSP } from '@diamir/nestjs-microservice'

import { MessageQueue } from '../../message-queue.enum'
import { ExamplePattern } from './example.pattern'

@MSP(MessageQueue.EXAMPLE)
export class ExampleProvider extends BaseMicroserviceProvider<ExamplePattern> {
  commandA (options: { /* some data for command-a */ }): Promise<{ /* microservice response */ }> {
    return this.send(ExamplePattern.COMMAND_A, options)
  }

  // or without payload
  async commandB (): Promise<void> {
    await this.emit(ExamplePattern.COMMAND_B)
  }
}

Usage:

// apps/example/server/modules/example/example.service.ts
@Injectable()
export class ExampleService {
  constructor(private readonly exampleProvider: ExampleProvider){}
  
  async example(): Promise<void> {
    await this.exampleProvider.commandB()
  }
}

Interceptor

  • RequestProfilerInterceptor: logs incoming request patterns and how long they took until their response
import { Module } from '@nestjs/common'
import { APP_INTERCEPTOR } from '@nestjs/core'

import { RequestProfilerInterceptor } from '@diamir/nestjs-microservice'

// microservice server
@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: RequestProfilerInterceptor
    }
  ]
})

Example Output:

[2020-01-01T12:00:00.000Z] [debug] [RequestProfilerInterceptor] - Pattern example starting
[2020-01-01T12:00:00.025Z] [debug] [RequestProfilerInterceptor] - Pattern example finished - took: 0.0250 sec

Links