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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@digikare/nestjs-azure-eventhub

v1.0.0

Published

<p align="center"> <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a> </p>

Downloads

18

Readme

Description

@digikare/nestjs-azure-eventhub is a transport component provide Event Hub into Nest microservice

Installation

$ npm install @digikare/nestjs-azure-eventhub

# or yarn

$ yarn add @digikare/nestjs-azure-eventhub

How to use

Microservice

import { EventHubServer } from '@digikare/nestjs-azure-eventhub';
// other imports {...}

const app = await NestFactory.createMicroservice(ApplicationModule, {
  startegy: new EventHubServer(
    '<connection_string>',        // the connection string
    '<event_hub_name>',           // the event hub name
    '<optional_consumer_group>',  // optionnal: The consumer group, the default value is $Default
  ),
});

You can also define a specific partitionId to listen if needed (useful for dev/test env).

import { EventHubServer } from '@digikare/nestjs-azure-eventhub';
// other imports {...}

const app = await NestFactory.createMicroservice(ApplicationModule, {
  startegy: new EventHubServer(
    '<connection_string>',          // the connection string
    '<event_hub_name>',             // the event hub name
    '<optional_consumer_group>',    // optionnal: The consumer group, the default value is $Default
    {
      partitionId: '<partition_id>' // optional: the partitionId to listen
    }
  ),
});

And now you can use @EventPattern() and @MessagePattern() decorators!

Checkpoint store

Since 0.1.2, you can add a checkpoint store, that allow your app to treat pending message.

You will need an azure account storage in order to make it works.

import { EventHubServer } from '@digikare/nestjs-azure-eventhub';
// other imports {...}

const app = await NestFactory.createMicroservice(ApplicationModule, {
  startegy: new EventHubServer(
    '<connection_string>',            // the connection string
    '<event_hub_name>',               // the event hub name
    '<optional_consumer_group>',      // optionnal: The consumer group, the default value is $Default
    {
      partitionId: '<partition_id>',  // optional: the partitionId to listen
      checkpointStore: {
        connectionString: '<checkpoint_account_storage_connection_string>',
        containerName: '<checkpoint_container_name>',
      }
    }
  ),
});

Wildcard support on pattern

Wildcard support on pattern can be usefull. When you receive a message, the client will cut out the topic of the event in order to check if handlers are subscribed to these topics.

The restriction at the moment:

  • The wildcard char '' must be at the end (eg: audit.*, 'my.scope.on.`)
  • The split char is '.'

To enable, just set wildcardSuppprt option to true

import { EventHubServer } from '@digikare/nestjs-azure-eventhub';
// other imports {...}

const app = await NestFactory.createMicroservice(ApplicationModule, {
  startegy: new EventHubServer(
    '<connection_string>',            // the connection string
    '<event_hub_name>',               // the event hub name
    '<optional_consumer_group>',      // optionnal: The consumer group, the default value is $Default
    {
      partitionId: '<partition_id>',  // optional: the partitionId to listen
      wildcardSupport: true,          // <<== Support wildcard
    }
  ),
});

Examples

If you send an event on the following topic : event.subevent.topic The handlePatternMessage will test the following topics :

  • *
  • event.*
  • event.subevent
  • event.subevent.*
  • event.subevent.topic

Client

import { ConfigModule, ConfigService } from '@nestjs/config';
import { EventHubClient } from '@digikare/nestjs-azure-eventhub';

@Module({
  imports: [
    ConfigModule,
  ],
  providers: {
    {
      provide: 'EVENT_HUB_CLIENT',
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        const connectionString = configService.get<string>('EVENT_HUB_CONNECTION_STRING');
        const eventHubName = configService.get<string>('EVENT_HUB_NAME');
        const partitionId = configService.get<string>('EVENT_HUB_PARTITION_ID'); // optionnal

        return new EventHubClient(
          connectionString,
          {
            eventHubName: eventHubName,
            partitionId: partitionId, // optional - define partitionId if you want sent to only
          }
        );
      },
    }
  },
})

Hint: When you define a partitionId, the configuration will override every message/event to send. Even if you provide a partitionID or partitionKey.

Build

# To install dependencies, first go to root monorepo and run yarn
$ cd ../../
$ yarn

# development
$ cd packages/nestjs-azure-eventhub
$ yarn build

# watch mode
$ cd packages/nestjs-azure-eventhub
$ npm run dev

License

This library is under MIT licensed.