@@ -29,6 +29,8 @@ yarn add @nestjstools/messaging @nestjstools/messaging-azure-service-bus-extensi
2929
3030---
3131
32+ ### Basic Example (Queue Mode)
33+
3234``` typescript
3335import { Module } from ' @nestjs/common' ;
3436import { MessagingModule } from ' @nestjstools/messaging' ;
@@ -45,15 +47,52 @@ import { MessagingAzureServiceBusExtensionModule, AzureServiceBusChannelConfig }
4547 channels: [' azure-channel' ],
4648 },
4749 ],
48- channels: [
49- new AzureServiceBusChannelConfig ({
50- name: ' azure-channel' ,
51- enableConsumer: true ,
52- autoCreate: false , // You need to have admin account to create a queue
53- fullyQualifiedNamespace: ' Endpoint=...' ,
54- queue: ' azure-queue' ,
55- }),
50+ channels: [
51+ new AzureServiceBusChannelConfig ({
52+ name: ' azure-channel' ,
53+ autoCreate: false , // Requires admin access in Azure to auto-create resources
54+ enableConsumer: true , // Needed for `autoCreate` and message consumption
55+ connectionString: ' Endpoint=...SharedAccessKey=...' ,
56+ queue: ' azure-queue' ,
57+ // mode: Mode.QUEUE, // Optional: default is 'QUEUE'
58+ }),
59+ ],
60+ debug: true , // Optional: Enable debugging for Messaging operations
61+ }),
62+ ],
63+ })
64+ export class AppModule {}
65+ ```
66+
67+ ### Topic/Subscription Mode (Pub/Sub)
68+
69+ ``` typescript
70+ import { Module } from ' @nestjs/common' ;
71+ import { MessagingModule } from ' @nestjstools/messaging' ;
72+ import { SendMessageHandler } from ' ./handlers/send-message.handler' ;
73+ import { MessagingAzureServiceBusExtensionModule , AzureServiceBusChannelConfig } from ' @nestjstools/messaging-azure-service-bus-extension' ;
74+
75+ @Module ({
76+ imports: [
77+ MessagingAzureServiceBusExtensionModule ,
78+ MessagingModule .forRoot ({
79+ buses: [
80+ {
81+ name: ' azure.bus' ,
82+ channels: [' azure-channel' ],
83+ },
5684 ],
85+ channels: [
86+ new AzureServiceBusChannelConfig ({
87+ name: ' azure-pubsub-channel' ,
88+ autoCreate: true , // Automatically create topic and subscription (if they don’t exist)
89+ enableConsumer: true , // Needed for `autoCreate` and message consumption
90+ connectionString: ' Endpoint=...SharedAccessKey=...' ,
91+ topic: ' azure-topic' ,
92+ subscription: ' azure-subscription' ,
93+ mode: Mode .TOPIC ,
94+ }),
95+ ],
5796 debug: true , // Optional: Enable debugging for Messaging operations
5897 }),
5998 ],
@@ -133,15 +172,19 @@ export class CreateUserHandler implements IMessageHandler<CreateUser>{
133172
134173#### ** AzureServiceBusChannelConfig**
135174
136- | ** Property** | ** Description** | ** Default Value** |
137- | -------------------------------| -----------------------------------------------------------------------------------------------| -------------------|
138- | ** ` name ` ** | The name of the messaging channel within your app (used for internal routing). | |
139- | ** ` fullyQualifiedNamespace ` ** | Azure service bus credentials (e.g., ` Endpoint=sb:... ` ). | |
140- | ** ` enableConsumer ` ** | Whether to enable message consumption (i.e., subscribing and processing messages from queue). | ` true ` |
141- | ** ` autoCreate ` ** | Automatically create the queue, but admin permission is required from IAM | ` true ` |
142- | ** ` queue ` ** | The name of the queue to publish messages and consume. | |
143-
144- ---
145-
146- ## Real world working example with RabbitMQ & Redis - but might be helpful to understand how it works
175+ | ** Property** | ** Description** | ** Default Value** |
176+ | ----------------------------------------| ------------------------------------------------------------------------------------------------------------| -------------------|
177+ | ** ` name ` ** | The name of the messaging channel within your app (used for internal routing). | |
178+ | ** ` connectionString ` ** | Full Azure Service Bus connection string (` Endpoint=sb://...;SharedAccessKeyName=...;... ` ). | |
179+ | ** ` mode ` ** | Messaging mode: ` 'queue' ` (point-to-point) or ` 'topic' ` (publish-subscribe). | ` Mode.QUEUE ` |
180+ | ** ` queue ` ** | The queue name (used in ` Mode.QUEUE ` ). | |
181+ | ** ` topic ` ** | The topic name (used in ` Mode.TOPIC ` ). | |
182+ | ** ` subscription ` ** | The subscription name under the topic (required when ` mode ` is ` TOPIC ` ). | |
183+ | ** ` enableConsumer ` ** | Whether to enable message consumption (subscribe and process messages). | ` true ` |
184+ | ** ` autoCreate ` ** | Automatically create the queue/topic/subscription if not found. Requires Service Bus ** admin privileges** . | ` false ` |
185+ | ** ` middlewares ` ** | Optional array of middleware functions for pre-processing incoming messages. | ` [] ` |
186+ | ** ` avoidErrorsForNotExistedHandlers ` ** | Ignore errors when a routing key doesn’t match any registered handler. | ` false ` |
187+
188+
189+ ### Real world working example with RabbitMQ & Redis - but might be helpful to understand how it works
147190https://github.com/nestjstools/messaging-rabbitmq-example
0 commit comments