Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@niur/nestjs-service-bus

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@niur/nestjs-service-bus

NestJS Azure Service Bus Microservice Transport

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
586
decreased by-19.06%
Maintainers
1
Weekly downloads
 
Created
Source

Nest Logo

NestJs custom transport for Azure Service Bus.

NPM Version Package License NPM Downloads

Description

Azure Service Bus is a fully managed enterprise message broker with message queues and publish-subscribe topics (in a namespace). Service Bus is used to decouple applications and services from each other, providing the following benefits:

  • Load-balancing work across competing workers
  • Safely routing and transferring data and control across service and application boundaries
  • Coordinating transactional work that requires a high-degree of reliability
Installation

To start building Azure Service Bus-based microservices, first install the required packages:

$ npm i --save @azure/service-bus @niur/nestjs-service-bus
Overview

To use the Azure Service Bus strategy, pass the following options object to the createMicroservice() method:

//  main.ts

const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
  strategy: new AzureServiceBusServer({
    connectionString: 'Endpoint=sb://<Name>.servicebus.windows.net/;SharedAccessKeyName=<SharedAccessKeyName>;SharedAccessKey=<SharedAccessKey>',
    options: {}
  }),
});

Options

The Azure Service Bus strategy exposes the properties described below.

retryOptionsRetry policy options that determine the mode, number of retries, retry interval etc (read more here).
webSocketOptionsOptions to configure the channelling of the AMQP connection over Web Sockets (read more here).
userAgentOptionsOptions for adding user agent details to outgoing requests (read more here).
Client
@Module({
  imports: [
    AzureServiceBusModule.forRoot([
      {
        name: 'SB_CLIENT',
        connectionString: 'Endpoint=sb://<Name>.servicebus.windows.net/;SharedAccessKeyName=<SharedAccessKeyName>;SharedAccessKey=<SharedAccessKey>',
        options: {},
      },
    ]),
  ]
  ...
})

// or

@Module({
  imports: [
    AzureServiceBusModule.forRootAsync([
      {
        name: 'SB_CLIENT',
        useFactory: (configService: ConfigService) => ({
          connectionString: configService.get('connectionString'),
          options: {}
        }),
        inject: [ConfigService],
      },
    ]),
  ]
  ...
})


@Injectable()
constructor(
  @Inject('SB_CLIENT') private readonly sbClient: AzureServiceBusClientProxy,
) {}

Producer

Event-based


const pattern = {
  name: 'sample-topic', // topic name
  options: {}
}; // queue name
const data = {
  body: 'Example message'
};

this.sbClient.send(pattern, data).subscribe((response) => {
  console.log(response); // reply message
});

Message-based


const pattern = {
  name: 'sample-topic', // topic name
  options: {}
}; // queue name
const data = {
  body: 'Example message'
};
this.sbClient.emit(pattern, data);
Consumer

To access the original Azure Service Bus message use the Subscription decorator as follows:


@Subscription({
    topic: 'sample-topic',
    subscription: 'sample-subscription',
    receiveMode: 'peekLock', // or receiveAndDelete
  })
getMessages(@Payload() message: ServiceBusMessage) {
  console.log(message);
}

Options

topicName of the topic for the subscription we want to receive from.
subscriptionName of the subscription (under the `topic`) that we want to receive from.
receiveModeRepresents the receive mode for the receiver. (read more here).
subQueueTypeRepresents the sub queue that is applicable for any queue or subscription. (read more here).
maxAutoLockRenewalDurationInMsThe maximum duration in milliseconds until which the lock on the message will be renewed by the sdk automatically.
skipParsingBodyAsJsonOption to disable the client from running JSON.parse() on the message body when receiving the message.
optionsOptions used when subscribing to a Service Bus queue or subscription.

Stay in touch

License

Nestjs Azure Service Bus is MIT licensed.

Keywords

FAQs

Package last updated on 16 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc