-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MET-32 Update docs * MET-32 Adjust README
- Loading branch information
Showing
2 changed files
with
87 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# AMQP (Advanced Message Queuing Protocol) | ||
|
||
The library provides support for both direct exchanges and topic exchanges. | ||
|
||
> **_NOTE:_** Check [README.md](../../README.md) for transport-agnostic library documentation. | ||
> | ||
## Publishers | ||
|
||
Use `AbstractAmqpQueuePublisher` to implement direct exchange and `AbstractAmqpTopicPublisher` for topic exchange. | ||
|
||
See [test publisher](test/publishers/AmqpPermissionPublisher.ts) for an example of implementation. | ||
|
||
## Consumers | ||
|
||
Use `AbstractAmqpQueueConsumer` to implement direct exchange and `AbstractAmqpTopicConsumer` for topic exchange. | ||
|
||
See [test consumer](test/consumers/AmqpPermissionConsumer.ts) for an example of implementation. | ||
|
||
## Automatic Reconnects | ||
|
||
`message-queue-toolkit` automatically reestablishes connections for all publishers and consumers via `AmqpConnectionManager` mechanism. | ||
|
||
Example: | ||
|
||
```ts | ||
export const TEST_AMQP_CONFIG: AmqpConfig = { | ||
vhost: '', | ||
hostname: 'localhost', | ||
username: 'guest', | ||
password: 'guest', | ||
port: 5672, | ||
useTls: false, | ||
} | ||
|
||
const amqpConnectionManager = new AmqpConnectionManager(config, logger) | ||
await amqpConnectionManager.init() | ||
|
||
const publisher = new TestAmqpPublisher( | ||
{ amqpConnectionManager }, | ||
{ | ||
// other amqp options | ||
}) | ||
await publisher.init() | ||
|
||
const consumer = new TestAmqpConsumer( | ||
{ amqpConnectionManager }, | ||
{ | ||
// other amqp options | ||
}) | ||
await consumer.start() | ||
|
||
// break connection, to simulate unexpected disconnection in production | ||
await (await amqpConnectionManager.getConnection()).close() | ||
|
||
const message = { | ||
// some test message | ||
} | ||
|
||
// This will fail, but will trigger reconnection within amqpConnectionManager | ||
publisher.publish(message) | ||
|
||
// eventually connection is reestablished and propagated across all the AMQP services that use same amqpConnectionManager | ||
|
||
// This will succeed and consumer, which also received new connection, will be able to consume it | ||
publisher.publish(message) | ||
``` |