NestJS Azure service bus based on @azure/service-bus package
NestJS Azure service bus based on @azure/service-bus package. See Examples folder for usage.
``bash`
yarn add @djeka07/nestjs-azure-service-bus
#### Importing module with only one provider
`typescript
import { AzureServiceBusModule } from '@djeka07/nestjs-azure-service-bus';
@Module({
imports: [
AzureServiceBusModule.forAsyncRoot({
useFactory: async () => {
return {
connectionString: '
senders: [ // Senders to send messages. Optional if for example if only will recieve messages
{
name: '
identifier: 'The identifier of the sender' // Optional
}
],
receivers: [ // Recievers to recieve messages, Optional if only will send messages
{
name: '
subscription: '
}
],
};
},
}),
],
controllers: [],
providers: [],
})
export class AModule {}
`
#### Importing module with multiple providers
`typescript
import { AzureServiceBusModule } from '@djeka07/nestjs-azure-service-bus';
@Module({
imports: [
AzureServiceBusModule.forAsyncRoot([
{
useFactory: async () => {
return {
name: '
connectionString: '
senders: [ // Senders to send messages. Optional if for example if only will recieve messages
{
name: '
identifier: 'The identifier of the sender' // Optional
}
],
receivers: [ // Recievers to recieve messages, Optional if only will send messages
{
name: '
subscription: '
}
],
};
},
},
{
useFactory: async () => {
return {
name: '
connectionString: 'connection string'
senders: [ // Senders to send messages. Optional if for example if only will recieve messages
{
name: '
identifier: 'The identifier of the sender' // Optional
}
],
receivers: [ // Recievers to recieve messages, Optional if only will send messages
{
name: '
subscription: '
}
],
};
},
}
]),
],
controllers: [],
providers: [],
})
export class AModule {}
`
#### Emitting messages with one provider
`typescript
import { Controller, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { AzureServiceBusClient } from '@djeka07/nestjs-azure-service-bus';
@Controller()
export class AppController {
constructor(
public readonly azureServiceBusClient: AzureServiceBusClient,
public readonly appService: AppService,
) {}
@Post()
post(): void {
this.azureServiceBusClient.emit({
payload: { body: { test: 'test' } },
name: '
});
}
}
`
#### Emitting messages with multiple providers
`typescript
import { Controller, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { AzureServiceBusClient } from '@djeka07/nestjs-azure-service-bus';
@Controller()
export class AppController {
constructor(
@Inject('
private readonly azureServiceBusClient: AzureServiceBusClient,
@Inject('provider name')
private readonly azureServiceBusSecondService: AzureServiceBusClient,
) {}
@Post()
post(): void {
this.azureServiceBusClient.emit({
payload: { body: { test: 'test' } },
name: '
});
}
@Post('/second')
post(): void {
this.azureServiceBusSecondService.emit({
payload: { body: { test: 'second test' } },
name: '
});
}
}
`
#### Reveive messages
`typescript
import { Subscribe } from '@djeka07/nestjs-azure-service-bus';
import { Injectable } from '@nestjs/common';
@Injectable()
export class TestService {
@Subscribe({ name: '
onMessage(data) {
console.log('message one', data);
}
@Subscribe({ name: '
onMessageTwo(data) {
console.log('message two', data);
}
}
`
#### Reveive messages with multiple providers
`typescript
import { Subscribe } from '@djeka07/nestjs-azure-service-bus';
import { Injectable } from '@nestjs/common';
@Injectable()
export class TestService {
@Subscribe({ name: '
onMessage(data) {
console.log('message one', data);
}
@Subscribe({
name: '
subscription: '
provider: '
})
onMessageTwo(data) {
console.log('message two', data);
}
}
``
André Ekbom Github
Licensed under the MIT License - see the LICENSE file for details.