@nestjstools/messaging 2.16.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -149
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,13 @@ A NestJS library for managing asynchronous and synchronous messages (service bus
|
|
|
18
18
|
- **Extensibility**: Creating new channels is straightforward, allowing developers to expand and integrate with external systems or protocols effortlessly.
|
|
19
19
|
- **Concurrent Handler Execution**: Messages dispatched to multiple handlers are processed concurrently, improving performance and responsiveness across your system.
|
|
20
20
|
|
|
21
|
+
## Channels
|
|
22
|
+
- [Redis channel adapter](https://www.npmjs.com/package/@nestjstools/messaging-redis-extension)
|
|
23
|
+
- [RabbitMQ channel adapter](https://www.npmjs.com/package/@nestjstools/messaging-rabbitmq-extension)
|
|
24
|
+
- [Amazon SQS channel adapter](https://www.npmjs.com/package/@nestjstools/messaging-amazon-sqs-extension)
|
|
25
|
+
- [Google PubSub channel Adapter](https://www.npmjs.com/package/@nestjstools/messaging-google-pubsub-extension)
|
|
26
|
+
- [Nats channel Adapter](https://www.npmjs.com/package/@nestjstools/messaging-nats-extension)
|
|
27
|
+
|
|
21
28
|
---
|
|
22
29
|
|
|
23
30
|
## Documentation
|
|
@@ -156,131 +163,6 @@ export class AppController {
|
|
|
156
163
|
|
|
157
164
|
🛠️ Please ensure you're using a compatible setup when working with multiple handlers, as this could result in unexpected behavior.
|
|
158
165
|
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
## RabbitMQ Integration: Messaging Configuration Example
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
The `MessagingModule` provides out-of-the-box integration with **RabbitMQ**, enabling the use of **AMQP** channels alongside in-memory channels. The configuration below demonstrates **CQRS** by separating command and event buses, ensuring seamless integration of your application with RabbitMQ's flexible messaging capabilities for both **command** and **event handling** + command dispatching.
|
|
166
|
-
|
|
167
|
-
## To make it works for rabbitmq
|
|
168
|
-
We need to install rabbitmq extension for `@nestjstools/messaging`
|
|
169
|
-
|
|
170
|
-
```bash
|
|
171
|
-
npm install @nestjstools/messaging-rabbitmq-extension
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
or
|
|
175
|
-
|
|
176
|
-
```bash
|
|
177
|
-
yarn add @nestjstools/messaging-rabbitmq-extension
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
import { MessagingModule, InMemoryChannelConfig, AmqpChannelConfig, ExchangeType } from '@nestjstools/messaging';
|
|
182
|
-
import { SendMessageHandler } from './handlers/send-message.handler';
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
@Module({
|
|
186
|
-
imports: [
|
|
187
|
-
MessagingModule.forRoot({
|
|
188
|
-
buses: [
|
|
189
|
-
{
|
|
190
|
-
name: 'message.bus',
|
|
191
|
-
channels: ['my-channel'],
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: 'command-bus', // The naming is very flexible
|
|
195
|
-
channels: ['amqp-command'], // Be sure if you defined same channels name as you defined below
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
name: 'event-bus',
|
|
199
|
-
channels: ['amqp-event'],
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
channels: [
|
|
203
|
-
new InMemoryChannelConfig({
|
|
204
|
-
name: 'my-channel',
|
|
205
|
-
middlewares: [],
|
|
206
|
-
}),
|
|
207
|
-
new AmqpChannelConfig({
|
|
208
|
-
name: 'amqp-command',
|
|
209
|
-
connectionUri: 'amqp://guest:guest@localhost:5672/',
|
|
210
|
-
exchangeName: 'my_app_command.exchange',
|
|
211
|
-
bindingKeys: ['my_app.command.#'],
|
|
212
|
-
exchangeType: ExchangeType.TOPIC,
|
|
213
|
-
middlewares: [],
|
|
214
|
-
queue: 'my_app.command',
|
|
215
|
-
autoCreate: true, // Create exchange, queue & bind keys
|
|
216
|
-
}),
|
|
217
|
-
new AmqpChannelConfig({
|
|
218
|
-
name: 'amqp-event',
|
|
219
|
-
connectionUri: 'amqp://guest:guest@localhost:5672/',
|
|
220
|
-
exchangeName: 'my_app_event.exchange',
|
|
221
|
-
bindingKeys: ['my_app_event.#'],
|
|
222
|
-
exchangeType: ExchangeType.TOPIC,
|
|
223
|
-
queue: 'my_app.event',
|
|
224
|
-
avoidErrorsForNotExistedHandlers: true, // We can avoid errors if we don't have handler yet for the event
|
|
225
|
-
autoCreate: true,
|
|
226
|
-
}),
|
|
227
|
-
],
|
|
228
|
-
debug: true,
|
|
229
|
-
}),
|
|
230
|
-
],
|
|
231
|
-
})
|
|
232
|
-
export class AppModule {}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
---
|
|
236
|
-
|
|
237
|
-
### Key Features:
|
|
238
|
-
|
|
239
|
-
1. **Multiple Message Buses**:
|
|
240
|
-
- Configure distinct buses for **in-memory**, **commands**, and **events**:
|
|
241
|
-
- `message.bus` (in-memory).
|
|
242
|
-
- `command.message-bus` (AMQP command processing).
|
|
243
|
-
- `event.message-bus` (AMQP event processing).
|
|
244
|
-
|
|
245
|
-
2. **In-Memory Channel**:
|
|
246
|
-
- Simple and lightweight channel suitable for non-persistent messaging or testing purposes.
|
|
247
|
-
|
|
248
|
-
3. **AMQP Channels**:
|
|
249
|
-
- Fully integrated RabbitMQ channel configuration using `AmqpChannelConfig`.
|
|
250
|
-
|
|
251
|
-
4. **Channel Details**:
|
|
252
|
-
- `connectionUri`: Specifies the RabbitMQ server connection.
|
|
253
|
-
- `exchangeName`: The AMQP exchange to publish or consume messages from.
|
|
254
|
-
- `bindingKeys`: Define message routing patterns using wildcards (e.g., `my_app.command.#`).
|
|
255
|
-
- `exchangeType`: Supports RabbitMQ exchange types such as `TOPIC`.
|
|
256
|
-
- `queue`: Specify a RabbitMQ queue to consume messages from.
|
|
257
|
-
- `autoCreate`: Automatically creates the exchange, queue, and bindings if they don’t exist.
|
|
258
|
-
|
|
259
|
-
5. **Error Handling**:
|
|
260
|
-
- Use `avoidErrorsForNotExistedHandlers` in `amqp-event` to gracefully handle missing handlers for event messages.
|
|
261
|
-
|
|
262
|
-
6. **Debug Mode**:
|
|
263
|
-
- Enable `debug: true` to assist in monitoring and troubleshooting messages.
|
|
264
|
-
|
|
265
|
-
This configuration provides a solid foundation for integrating RabbitMQ as part of your messaging system. It facilitates the decoupling of commands, events, and in-memory operations, ensuring reliable and scalable communication across distributed systems.
|
|
266
|
-
|
|
267
|
-
---
|
|
268
|
-
|
|
269
|
-
## Mapping Messages in RabbitMQ Channel
|
|
270
|
-
|
|
271
|
-
### Topic Exchange
|
|
272
|
-
For optimal routing, it's recommended to use routing keys as part of the binding key. For example, if you bind a queue with the key `my_app.command.#`, messages with routing keys like `my_app.command.domain.action` will automatically be routed to that queue. This ensures that any message with a routing key starting with `my_app.command` is directed to the appropriate queue.
|
|
273
|
-
Here's a more concise and clear version of your explanation:
|
|
274
|
-
|
|
275
|
-
### Direct Exchange
|
|
276
|
-
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.
|
|
277
|
-
|
|
278
|
-
### Additional
|
|
279
|
-
* You can override message routing using `AmqpMessageOptions`. This allows sending a message to a specified exchange and routing it with a custom key.
|
|
280
|
-
```typescript
|
|
281
|
-
this.messageBus.dispatch(new RoutingMessage(new SendMessage('Hello Rabbit!'), 'app.command.execute', new AmqpMessageOptions('exchange_name', 'rabbitmq_routing_key_to_queue')));
|
|
282
|
-
```
|
|
283
|
-
|
|
284
166
|
---
|
|
285
167
|
## Normalizers
|
|
286
168
|
What is a Normalizer?
|
|
@@ -465,7 +347,7 @@ Here’s a table with the documentation for the `MessagingModule.forRoot` config
|
|
|
465
347
|
|
|
466
348
|
### Channels
|
|
467
349
|
|
|
468
|
-
####
|
|
350
|
+
#### **InMemoryChannelConfig**
|
|
469
351
|
|
|
470
352
|
| **Property** | **Description** | **Default Value** |
|
|
471
353
|
|----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
|
|
@@ -474,23 +356,6 @@ Here’s a table with the documentation for the `MessagingModule.forRoot` config
|
|
|
474
356
|
| **`avoidErrorsForNotExistedHandlers`** | Avoid errors if no handler is available for the message. | `false` |
|
|
475
357
|
| **`normalizer`** | Set your custom normalizer for messages | |
|
|
476
358
|
|
|
477
|
-
#### 2. **AmqpChannelConfig**
|
|
478
|
-
|
|
479
|
-
| **Property** | **Description** | **Default Value** |
|
|
480
|
-
|----------------------------------------|----------------------------------------------------------------------------------|-------------------|
|
|
481
|
-
| **`name`** | Name of the AMQP channel (e.g., `'amqp-command'`). | |
|
|
482
|
-
| **`connectionUri`** | URI for the RabbitMQ connection, such as `'amqp://guest:guest@localhost:5672/'`. | |
|
|
483
|
-
| **`exchangeName`** | The AMQP exchange name (e.g., `'my_app.exchange'`). | |
|
|
484
|
-
| **`bindingKeys`** | The routing keys to bind to (e.g., `['my_app.command.#']`). | `[]` |
|
|
485
|
-
| **`exchangeType`** | Type of the RabbitMQ exchange (e.g., `TOPIC`). | |
|
|
486
|
-
| **`queue`** | The AMQP queue to consume messages from (e.g., `'my_app.command'`). | |
|
|
487
|
-
| **`autoCreate`** | Automatically creates the exchange, queue, and bindings if they don’t exist. | `true` |
|
|
488
|
-
| **`enableConsumer`** | Enables or disables the consumer for this channel. | `true` |
|
|
489
|
-
| **`avoidErrorsForNotExistedHandlers`** | Avoid errors if no handler is available for the message. | `false` |
|
|
490
|
-
| **`normalizer`** | Set your custom normalizer for messages | |
|
|
491
|
-
|
|
492
|
-
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.
|
|
493
|
-
|
|
494
359
|
## Creating Your Own Channel and Bus
|
|
495
360
|
This process allows you to define and integrate a custom **Channel** and **MessageBus** for your application, giving you complete flexibility and control over how messages are processed, dispatched, and consumed. Each step provides the necessary building blocks to create your own transport layer with full integration into the `MessagingModule`.
|
|
496
361
|
|
|
@@ -591,9 +456,3 @@ Classes with `Injectable()` decorator must be defined as providers in somewhere
|
|
|
591
456
|
|
|
592
457
|
### Future features
|
|
593
458
|
* INBOX & OUTBOX Pattern
|
|
594
|
-
|
|
595
|
-
### Links
|
|
596
|
-
- [Redis channel adapter](https://www.npmjs.com/package/@nestjstools/messaging-redis-extension)
|
|
597
|
-
- [RabbitMQ channel adapter](https://www.npmjs.com/package/@nestjstools/messaging-rabbitmq-extension)
|
|
598
|
-
- [Amazon SQS channel adapter](https://www.npmjs.com/package/@nestjstools/messaging-amazon-sqs-extension)
|
|
599
|
-
- [Google PubSub channel Adapter](https://www.npmjs.com/package/@nestjstools/messaging-google-pubsub-extension)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjstools/messaging",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "Simplifies asynchronous and synchronous message handling with support for buses, handlers, channels, and consumers. Build scalable, decoupled applications with ease and reliability.",
|
|
5
5
|
"author": "Sebastian Iwanczyszyn",
|
|
6
6
|
"license": "MIT",
|