Giter VIP home page Giter VIP logo

nestjs-azure-service-bus's Introduction

Azure Service Bus module for Nest.js framework

NPM Version Package License

Description

Azure Service Bus is a cloud based message broker. You can use Azure Service Bus to send messages between applications or services. It supports AMQP / STOMP protocols, automatic scalability and disaster recovery.

Azure Service Bus module for Nest.js based on the @azure/service-bus package.

Installation

$ npm i --save @skelmen/nestjs-azure-service-bus-module

Usage

Import module

AzureServiceBusModule.forRootAsync([
  {
    name: 'provider_name_1',
    useFactory: (configService: ConfigService) => ({
      connectionString: configService.get('connectionString1'),
      options: {} // Azure service bus client options
    }),
    inject: [ConfigService],
  },
  {
    name: 'provider_name_2',
    useFactory: () => ({
      connectionString: 'connectionString2',
      options: {} // Azure service bus client options
    }),
    inject: [],
  },
]),

Service example

For messages scheduling pass updateTime param to emit method.

@Injectable()
export class AppService {

  constructor(
    @Inject('provider_name_1') private readonly serviceBusClient: AzureServiceBusClient,
  ) { }

  getData(){
    const options = {}; // Azure options for configuring tracing and the abortSignal
    const payload = {
      body: {
        id: '39219'
      }
    };
    this.serviceBusClient.emit({ payload, options });
  }

  scheduleData(){
    const options = {};
    const payload = {
      body: {
        id: '39219'
      }
    };
    // (Optional) For scheduling messages
    const updateTime = new Date('2023-02-20 13:26:00+02');
    this.serviceBusClient.emit({ payload, options, updateTime });
  }
}

Handle events

@Subscribe('service-bus-queue-name')
async handler(data) {
  console.log(data);
}

License

This project is licensed under the MIT License

nestjs-azure-service-bus's People

Contributors

skelmen avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.