Skip to content

Commit c9ee5d9

Browse files
feat: Improve doc
1 parent 198ae39 commit c9ee5d9

File tree

3 files changed

+362
-2356
lines changed

3 files changed

+362
-2356
lines changed

README.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,50 @@ Here's a more concise and clear version of your explanation:
123123
### Direct Exchange
124124
Ensure your queue has defined binding keys, as messages will be routed to queues based on these keys. If no binding keys are defined, the routing key in RabbitMQ will default to the routing key specified in the handler.
125125

126+
### Fanout Exchange
127+
The Fanout Exchange broadcasts messages to all bound queues, ignoring the routing key. This type of exchange is useful for scenarios where you need to distribute the same message to multiple consumers.
128+
126129
### Additional
127130
* You can override message routing using `AmqpMessageOptions`. This allows sending a message to a specified exchange and routing it with a custom key.
128131
```typescript
129132
this.messageBus.dispatch(new RoutingMessage(new SendMessage('Hello Rabbit!'), 'app.command.execute', new AmqpMessageOptions('exchange_name', 'rabbitmq_routing_key_to_queue')));
130133
```
131-
132134
---
133135

136+
## 📨 Communicating Beyond a NestJS Application (Cross-Language Messaging)
137+
138+
### To enable communication with a Handler from services written in other languages, follow these steps:
139+
140+
1. **Publish a Message to the queue**
141+
142+
2. **Include the Routing Key Header**
143+
Your message **must** include a header attribute named `messaging-routing-key`.
144+
The value should correspond to the routing key defined in your NestJS message handler:
145+
```ts
146+
@MessageHandler('my_app_command.create_user') // <-- Use this value as the routing key
147+
```
148+
149+
3. **You're Done!**
150+
Once the message is published with the correct routing key, it will be automatically routed to the appropriate handler within the NestJS application.
151+
---
134152
## Configuration options
135153

136154
### AmqpChannel
137155

138156
#### **AmqpChannelConfig**
139157

140-
| **Property** | **Description** | **Default Value** |
141-
|----------------------------------------|----------------------------------------------------------------------------------|-------------------|
142-
| **`name`** | Name of the AMQP channel (e.g., `'amqp-command'`). | |
143-
| **`connectionUri`** | URI for the RabbitMQ connection, such as `'amqp://guest:guest@localhost:5672/'`. | |
144-
| **`exchangeName`** | The AMQP exchange name (e.g., `'my_app.exchange'`). | |
145-
| **`bindingKeys`** | The routing keys to bind to (e.g., `['my_app.command.#']`). | `[]` |
146-
| **`exchangeType`** | Type of the RabbitMQ exchange (e.g., `TOPIC`). | |
147-
| **`queue`** | The AMQP queue to consume messages from (e.g., `'my_app.command'`). | |
148-
| **`autoCreate`** | Automatically creates the exchange, queue, and bindings if they dont exist. | `true` |
149-
| **`enableConsumer`** | Enables or disables the consumer for this channel. | `true` |
150-
| **`avoidErrorsForNotExistedHandlers`** | Avoid errors if no handler is available for the message. | `false` |
158+
| **Property** | **Description** | **Default Value** |
159+
|----------------------------------------|--------------------------------------------------------------------------------------------|-------------------|
160+
| **`name`** | Name of the AMQP channel (e.g., `'amqp-command'`). | |
161+
| **`connectionUri`** | URI for the RabbitMQ connection, such as `'amqp://guest:guest@localhost:5672/'`. | |
162+
| **`exchangeName`** | The AMQP exchange name (e.g., `'my_app.exchange'`). | |
163+
| **`bindingKeys`** | The routing keys to bind to (e.g., `['my_app.command.#']`). | `[]` |
164+
| **`exchangeType`** | Type of the RabbitMQ exchange (e.g., `TOPIC`). | |
165+
| **`queue`** | The AMQP queue to consume messages from (e.g., `'my_app.command'`). | |
166+
| **`autoCreate`** | Automatically creates the exchange, queue, and bindings if they dont exist. | `true` |
167+
| **`enableConsumer`** | Enables or disables the consumer for this channel. | `true` |
168+
| **`avoidErrorsForNotExistedHandlers`** | Avoid errors if no handler is available for the message. | `false` |
169+
| **`deadLetterQueueFeature`** | Enables a dead-letter queue to capture messages that could not be processed due to errors. | `false` |
151170

152171
This table provides a structured overview of the **`MessagingModule.forRoot`** configuration, with details about each property within **buses** and **channels** and their corresponding default values.
153172

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nestjstools/messaging-rabbitmq-extension",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "Extension to handle messages and dispatch them over AMQP protocol",
55
"author": "Sebastian Iwanczyszyn",
66
"private": false,
@@ -64,7 +64,7 @@
6464
"@nestjs/core": "^11.0.0",
6565
"@nestjs/schematics": "^11.0.0",
6666
"@nestjs/testing": "^11.0.0",
67-
"@nestjstools/messaging": "^2.7.1",
67+
"@nestjstools/messaging": "^2.15.0",
6868
"@semantic-release/github": "^11.0.1",
6969
"@types/express": "^5.0.0",
7070
"@types/jest": "^29.5.2",

0 commit comments

Comments
 (0)