@droidsolutions-oss/amqp-ts 2.5.0 → 2.6.1

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.
Files changed (60) hide show
  1. package/README.md +23 -16
  2. package/lib/AmqpProperties.d.ts +81 -0
  3. package/lib/AmqpProperties.js +3 -0
  4. package/lib/AmqpProperties.js.map +1 -0
  5. package/lib/Binding.d.ts +18 -0
  6. package/lib/Binding.js +112 -0
  7. package/lib/Binding.js.map +1 -0
  8. package/lib/Connection/Connection.d.ts +109 -0
  9. package/lib/Connection/Connection.js +346 -0
  10. package/lib/Connection/Connection.js.map +1 -0
  11. package/lib/Connection/ConnectionMetrics.d.ts +7 -0
  12. package/lib/Connection/ConnectionMetrics.js +3 -0
  13. package/lib/Connection/ConnectionMetrics.js.map +1 -0
  14. package/lib/Connection/ReconnectStrategy.d.ts +4 -0
  15. package/lib/Connection/ReconnectStrategy.js +3 -0
  16. package/lib/Connection/ReconnectStrategy.js.map +1 -0
  17. package/lib/Connection/Topology.d.ts +19 -0
  18. package/lib/Connection/Topology.js +3 -0
  19. package/lib/Connection/Topology.js.map +1 -0
  20. package/lib/Exchange/DeclarationOptions.d.ts +20 -0
  21. package/lib/Exchange/DeclarationOptions.js +3 -0
  22. package/lib/Exchange/DeclarationOptions.js.map +1 -0
  23. package/lib/Exchange/Exchange.d.ts +94 -0
  24. package/lib/Exchange/Exchange.js +279 -0
  25. package/lib/Exchange/Exchange.js.map +1 -0
  26. package/lib/Exchange/ExchangeType.d.ts +6 -0
  27. package/lib/Exchange/ExchangeType.js +3 -0
  28. package/lib/Exchange/ExchangeType.js.map +1 -0
  29. package/lib/Exchange/InitializeResult.d.ts +3 -0
  30. package/lib/Exchange/InitializeResult.js +3 -0
  31. package/lib/Exchange/InitializeResult.js.map +1 -0
  32. package/lib/LoggerFactory.d.ts +48 -0
  33. package/lib/LoggerFactory.js +13 -0
  34. package/lib/LoggerFactory.js.map +1 -0
  35. package/lib/Message.d.ts +52 -0
  36. package/lib/Message.js +125 -0
  37. package/lib/Message.js.map +1 -0
  38. package/lib/Queue/DeclarationOptions.d.ts +18 -0
  39. package/lib/Queue/DeclarationOptions.js +3 -0
  40. package/lib/Queue/DeclarationOptions.js.map +1 -0
  41. package/lib/Queue/DeleteResult.d.ts +3 -0
  42. package/lib/Queue/DeleteResult.js +3 -0
  43. package/lib/Queue/DeleteResult.js.map +1 -0
  44. package/lib/Queue/InitializeResult.d.ts +5 -0
  45. package/lib/Queue/InitializeResult.js +3 -0
  46. package/lib/Queue/InitializeResult.js.map +1 -0
  47. package/lib/Queue/Queue.d.ts +107 -0
  48. package/lib/Queue/Queue.js +339 -0
  49. package/lib/Queue/Queue.js.map +1 -0
  50. package/lib/Queue/StartConsumerResult.d.ts +5 -0
  51. package/lib/Queue/StartConsumerResult.js +3 -0
  52. package/lib/Queue/StartConsumerResult.js.map +1 -0
  53. package/lib/amqp-ts.d.ts +9 -0
  54. package/lib/amqp-ts.js +21 -0
  55. package/lib/amqp-ts.js.map +1 -0
  56. package/lib/index.d.ts +14 -0
  57. package/lib/index.js +14 -0
  58. package/lib/index.js.map +1 -0
  59. package/package.json +36 -28
  60. package/CHANGELOG.md +0 -159
package/README.md CHANGED
@@ -6,16 +6,16 @@
6
6
 
7
7
  This is a fork of [amqp-ts](https://github.com/abreits/amqp-ts).
8
8
 
9
- ## Table of Contents
9
+ # Table of Contents
10
10
 
11
11
  - [Overview](#overview)
12
12
  - [Usage](#usage)
13
13
 
14
- ## Overview <a name="overview"></a>
14
+ # Overview <a name="overview"></a>
15
15
 
16
16
  Amqp-ts is a library for nodejs that simplifies communication with AMQP message busses written in Typescript. It has been tested on RabbitMQ. It uses the [amqplib](http://www.squaremobius.net/amqp.node/) library by [Michael Bridgen (squaremo)](https://github.com/squaremo).
17
17
 
18
- ### Difference to the original library
18
+ ## Difference to the original library
19
19
 
20
20
  Changes to the [original amqp-ts](https://github.com/abreits/amqp-ts) package:
21
21
 
@@ -24,15 +24,16 @@ Changes to the [original amqp-ts](https://github.com/abreits/amqp-ts) package:
24
24
  - dropped winston as dependency, instead a factory can be provided to the connection constructor which returns any logger.
25
25
  - the deprecated methods like `Exchange.publish`, `Exchange.startConsumer`, `Queue.publish` and `Queue.startConsumer` are removed from this library, since their replacements like `Exchange.send` and `Exchange.activateConsumer` already existed.
26
26
  - fixes for https://github.com/abreits/amqp-ts/pull/46 and https://github.com/abreits/amqp-ts/issues/20 have been implemented
27
+ - add basic metrics
27
28
 
28
- ### Defining Features
29
+ ## Defining Features
29
30
 
30
31
  - [High level non opinioned library], no need to worry about channels etc.
31
32
  - ['Lazy' initialization](#initialization), async AMQP dependencies are resolved automatically
32
33
  - [Automatic reconnection](#reconnect), when the connection with the AMQP server fails, the whole connection and configuration is rebuilt automatically
33
34
  - Written in typescript.
34
35
 
35
- ### Current status
36
+ ## Current status
36
37
 
37
38
  The library is considered production ready.
38
39
 
@@ -40,18 +41,18 @@ It does depend on the following npm libraries:
40
41
 
41
42
  - [amqplib](http://www.squaremobius.net/amqp.node/)
42
43
 
43
- ### Lazy Initialization <a name="initialization"></a>
44
+ ## Lazy Initialization <a name="initialization"></a>
44
45
 
45
46
  No need to nest functionality, just create a connection, declare your exchanges, queues and
46
47
  bindings and send and receive messages. The library takes care of any direct dependencies.
47
48
 
48
49
  If you define an exchange and a queue and bind the queue to the exchange and want to make sure that the queue is connected to the exchange before you send a message to the exchange you can call the `connection.completeConfiguration()` method and act on the promise it returns.
49
50
 
50
- ## Usage <a name="usage"></a>
51
+ # Usage <a name="usage"></a>
51
52
 
52
53
  There are multiple ways to declare your exchanges, queues and bindings. Each of those has an `initialized` property which is a promise that resolves when initialization is complete. You can either await it yourself or call `completeConfiguration` on the connection like explained in [Lazy initialization](#initialization).
53
54
 
54
- ### Async Typescript Example
55
+ ## Async Typescript Example
55
56
 
56
57
  ```ts
57
58
  import { Connection, Message } from "amqp-ts";
@@ -72,7 +73,7 @@ await queue.activateConsumer((message: Message) => {
72
73
  });
73
74
  ```
74
75
 
75
- ### Lazy Typescript Example
76
+ ## Lazy Typescript Example
76
77
 
77
78
  ```ts
78
79
  import { Connection, Message } from "amqp-ts";
@@ -100,7 +101,7 @@ exchange.send(msg2);
100
101
 
101
102
  More examples can be found in the [tutorials directory](https://github.com/abreits/amqp-ts/tree/master/tutorials).
102
103
 
103
- ### Messages
104
+ ## Messages
104
105
 
105
106
  A message consists of the content (the data you want to send) and some optional properties that are defined by AMQP. This metadata offers some ways for consumers and providers to know how to process a message. For example when you provide an object as content then it is converted to a JSON string and the `contentType` property is set to `application/json`. This way the consumer knows, that the message should be parsed from json. For a detailed guide on the properties, you can refer to [the RabbitMQ documentation](https://www.rabbitmq.com/consumers.html#message-properties).
106
107
 
@@ -111,7 +112,7 @@ Properties that are set by this library are:
111
112
  - timestamp - if not set by you it will be set to the current timestamp in UTC
112
113
  - correlationId - if it is specified by the incoming message it will be set to the automatic reply (see below)
113
114
 
114
- ### Logging
115
+ ## Logging
115
116
 
116
117
  The last argument of the `Connection` constructor takes a logger factory function. If you specify it, the function should return a logger that matches the `SimpleLogger` interface. This type is heavily inspired by the style of [Pino](https://github.com/pinojs/pino), but you can write a wrapper for any logger you like. It should support `%s`, `%d` and `%o` string interpolation, as they are used for internal log messages.
117
118
 
@@ -213,11 +214,11 @@ const loggerFactory = (context, meta) => {
213
214
  };
214
215
  ```
215
216
 
216
- ### Connection Status
217
+ ## Connection Status
217
218
 
218
219
  To know the status of the connection: `connection.isConnected`. Returns true if the connection exists and false, otherwise.
219
220
 
220
- ### Events
221
+ ## Events
221
222
 
222
223
  #on('open_connection', function() {...})
223
224
 
@@ -243,15 +244,15 @@ It is emitted when the connection is re-established.
243
244
 
244
245
  It's emitted when a error is registered during the connection.
245
246
 
246
- ### Automatic Reconnection <a name="reconnect"></a>
247
+ ## Automatic Reconnection <a name="reconnect"></a>
247
248
 
248
249
  When the library detects that the connection with the AMQP server is lost, it tries to automatically reconnect to the server.
249
250
 
250
- ### Automatic JSON content
251
+ ## Automatic JSON content
251
252
 
252
253
  If your message content is not a string and not a buffer it is converted automatically to a JSON string. The `contentType` is set to `application/json` and the `contentEncoding` is set to `utf-8`. Vice versa if you call `getContent()` on the message and the `contentType` is set to `application/json` the string will be parsed and the parsed result will be returned. If you want to avoid the `any` type you can use `getJsonContent<T>()` instead. This method throws an error, if the `contentType` is not set to `application/json`.
253
254
 
254
- ### Automatic ReplyTo
255
+ ## Automatic ReplyTo
255
256
 
256
257
  If your message consumer returns a value and the `replyTo` property is set in the message property, the value is send to the queue given in the `replyTo` field. The correlationId is set to the response message if it is set in the request. If you want to set other properties you can specify them when calling `activateConsumer` i nthe options. If you don't return any value (a.k.a return `undefined`) no automatic reply is send. You have manage this by yourself then.
257
258
 
@@ -303,3 +304,9 @@ await queue.activateConsumer((message: Message) => {
303
304
  return { my: "result" };
304
305
  });
305
306
  ```
307
+
308
+ ## Metrics
309
+
310
+ The connection instance offers a method that returns basic metrics of the connection. For the metrics there is a TypeScript interface `ConnectionMetrics` that contains possible metrics of the connection.
311
+
312
+ To receive them you can call `getMetrics()` on the connection instance.
@@ -0,0 +1,81 @@
1
+ import * as AmqpLib from "amqplib";
2
+ /**
3
+ * Represents a set of optional properties that can be set when publishing messages via AMQP.
4
+ *
5
+ * @see https://www.rabbitmq.com/consumers.html#message-properties for more info.
6
+ * Also @see http://www.squaremobius.net/amqp.node/channel_api.html#channel_publish for library defaults.
7
+ */
8
+ export interface AmqpProperties extends AmqpLib.Options.Publish {
9
+ /** The time to live until the message is considered dead in ms. @see https://www.rabbitmq.com/ttl.html */
10
+ expiration?: string | number;
11
+ /**
12
+ * The ID of the AQMP user who published the message. If set it is validated and its value must be equal to the name
13
+ * of the user used to open the connection. @see https://www.rabbitmq.com/validated-user-id.html
14
+ */
15
+ userId?: string;
16
+ /**
17
+ * An array of routing keys as string. Messages will be routed to these routing keys in addition to the given routing
18
+ * key parameter.
19
+ */
20
+ CC?: string | string[];
21
+ /** If true, the message will be returned if it is not routed to a queue. */
22
+ mandatory?: boolean;
23
+ /**
24
+ * Sets the @see deliveryMode to 2. If true the message will survive broker restarts as long as the queue survives.
25
+ *
26
+ * @example true
27
+ */
28
+ persistent?: boolean;
29
+ /**
30
+ * The delivery mode, 2 or true means "persistent", 1 or false "transient". Used by RabbitMQ but not sent to
31
+ * consumers.
32
+ *
33
+ * @example 2
34
+ */
35
+ deliveryMode?: boolean | number;
36
+ /**
37
+ * Like @see CC except that the headers will not be send in the message headers to the consumer.
38
+ */
39
+ BCC?: string | string[];
40
+ /**
41
+ * The content type of the message body, useful for consumer when parsing the message body.
42
+ *
43
+ * @example "application/json"
44
+ */
45
+ contentType?: string;
46
+ /**
47
+ * The encoding of the message body, useful for consumer when parsing the body.
48
+ *
49
+ * @example "utf-8"
50
+ */
51
+ contentEncoding?: string;
52
+ /**
53
+ * Any additional headers of the message. For content-type use @see contentType . Application specific and not used
54
+ * by RabbitMQ.*/
55
+ headers?: any;
56
+ /**
57
+ * A positive integer that sets the priority of the message. @see http://www.rabbitmq.com/priority.html
58
+ */
59
+ priority?: number;
60
+ /** Useful to combine logs of sender and recipient by using a correlation ID. */
61
+ correlationId?: string;
62
+ /** The name of the response queue. */
63
+ replyTo?: string;
64
+ /** Arbitrary message ID. */
65
+ messageId?: string;
66
+ /** A timestamp of the message. */
67
+ timestamp?: number;
68
+ /**
69
+ * Application specific message type. RabbitMQ does nothing with this field but it can help the consumer to know what
70
+ * kind of message this is.
71
+ *
72
+ * @example "audit.log"
73
+ */
74
+ type?: string;
75
+ /**
76
+ * The name of the application.
77
+ *
78
+ * @example "app:audit component:event-consumer"
79
+ */
80
+ appId?: string;
81
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AmqpProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AmqpProperties.js","sourceRoot":"","sources":["../src/AmqpProperties.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { Exchange } from "./Exchange/Exchange";
2
+ import { Queue } from "./Queue/Queue";
3
+ export declare class Binding {
4
+ private pattern;
5
+ private args;
6
+ static id(destination: Exchange | Queue, source: Exchange, pattern?: string): string;
7
+ static removeBindingsContaining(connectionPoint: Exchange | Queue): Promise<any>;
8
+ initialized: Promise<Binding>;
9
+ _source: Exchange;
10
+ _destination: Exchange | Queue;
11
+ private log;
12
+ constructor(destination: Exchange | Queue, source: Exchange, pattern?: string, args?: any);
13
+ _initialize(): void;
14
+ /**
15
+ * Deletes this binding of either a queue or an exchange.
16
+ */
17
+ delete(): Promise<void>;
18
+ }
package/lib/Binding.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Binding = void 0;
4
+ const Queue_1 = require("./Queue/Queue");
5
+ class Binding {
6
+ constructor(destination, source, pattern = "", args = {}) {
7
+ this.pattern = pattern;
8
+ this.args = args;
9
+ this.log = destination.connection.loggerFactory(this.constructor);
10
+ this._source = source;
11
+ this._destination = destination;
12
+ this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)] = this;
13
+ this._initialize();
14
+ }
15
+ static id(destination, source, pattern) {
16
+ pattern = pattern || "";
17
+ return ("[" +
18
+ source.name +
19
+ "]to" +
20
+ (destination instanceof Queue_1.Queue ? "Queue" : "Exchange") +
21
+ "[" +
22
+ destination.name +
23
+ "]" +
24
+ pattern);
25
+ }
26
+ static removeBindingsContaining(connectionPoint) {
27
+ const connection = connectionPoint.connection;
28
+ const promises = [];
29
+ for (const bindingId in connection._bindings) {
30
+ const binding = connection._bindings[bindingId];
31
+ if (binding._source === connectionPoint || binding._destination === connectionPoint) {
32
+ promises.push(binding.delete());
33
+ }
34
+ }
35
+ return Promise.all(promises);
36
+ }
37
+ _initialize() {
38
+ this.initialized = new Promise((resolve, reject) => {
39
+ if (this._destination instanceof Queue_1.Queue) {
40
+ const queue = this._destination;
41
+ queue.initialized.then(() => {
42
+ queue._channel.bindQueue(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
43
+ /* istanbul ignore if */
44
+ if (err) {
45
+ this.log.error({ err }, "Failed to create queue binding (%s->%s)", this._source.name, this._destination.name);
46
+ delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
47
+ reject(err);
48
+ }
49
+ else {
50
+ resolve(this);
51
+ }
52
+ });
53
+ });
54
+ }
55
+ else {
56
+ const exchange = this._destination;
57
+ exchange.initialized.then(() => {
58
+ exchange._channel.bindExchange(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
59
+ /* istanbul ignore if */
60
+ if (err) {
61
+ this.log.error({ err }, "Failed to create exchange binding (%s->%s)", this._source.name, this._destination.name);
62
+ delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
63
+ reject(err);
64
+ }
65
+ else {
66
+ resolve(this);
67
+ }
68
+ });
69
+ });
70
+ }
71
+ });
72
+ }
73
+ /**
74
+ * Deletes this binding of either a queue or an exchange.
75
+ */
76
+ delete() {
77
+ return new Promise((resolve, reject) => {
78
+ if (this._destination instanceof Queue_1.Queue) {
79
+ const queue = this._destination;
80
+ queue.initialized.then(() => {
81
+ queue._channel.unbindQueue(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
82
+ /* istanbul ignore if */
83
+ if (err) {
84
+ reject(err);
85
+ }
86
+ else {
87
+ delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
88
+ resolve(null);
89
+ }
90
+ });
91
+ });
92
+ }
93
+ else {
94
+ const exchange = this._destination;
95
+ exchange.initialized.then(() => {
96
+ exchange._channel.unbindExchange(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
97
+ /* istanbul ignore if */
98
+ if (err) {
99
+ reject(err);
100
+ }
101
+ else {
102
+ delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
103
+ resolve(null);
104
+ }
105
+ });
106
+ });
107
+ }
108
+ });
109
+ }
110
+ }
111
+ exports.Binding = Bin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{ EventEmitter } from "events";
4
+ import { Binding } from "../Binding";
5
+ import { DeclarationOptions as ExchangeDeclarationOptions } from "../Exchange/DeclarationOptions";
6
+ import { Exchange } from "../Exchange/Exchange";
7
+ import { ExchangeType } from "../Exchange/ExchangeType";
8
+ import { LoggerFactory } from "../LoggerFactory";
9
+ import { DeclarationOptions as QueueDeclarationOptions } from "../Queue/DeclarationOptions";
10
+ import { Queue } from "../Queue/Queue";
11
+ import { ConnectionMetrics } from "./ConnectionMetrics";
12
+ import { ReconnectStrategy } from "./ReconnectStrategy";
13
+ import { Topology } from "./Topology";
14
+ export declare class Connection extends EventEmitter {
15
+ loggerFactory?: LoggerFactory;
16
+ initialized: Promise<void>;
17
+ connection: AmqpLib.Connection;
18
+ isConnected: boolean;
19
+ _exchanges: {
20
+ [id: string]: Exchange;
21
+ };
22
+ _queues: {
23
+ [id: string]: Queue;
24
+ };
25
+ _bindings: {
26
+ [id: string]: Binding;
27
+ };
28
+ private url;
29
+ private socketOptions;
30
+ private reconnectStrategy;
31
+ private connectedBefore;
32
+ private _retry;
33
+ private _rebuilding;
34
+ private _isClosing;
35
+ private log;
36
+ private _sentMessagesCounter;
37
+ private _receivedMessagesCounter;
38
+ /**
39
+ *
40
+ * @param url The url to RabbitMQ
41
+ * @param socketOptions Socket options are passed to {@link AmqpLib.connect}.
42
+ * @param reconnectStrategy Options specifying the reconnect strategy.
43
+ * @param loggerFactory A factory function that returns a logger.
44
+ */
45
+ constructor(url?: string, socketOptions?: any, reconnectStrategy?: ReconnectStrategy, loggerFactory?: LoggerFactory);
46
+ tryToConnect(thisConnection: Connection, retry: number, callback: (err: any) => void): void;
47
+ _rebuildAll(err: Error): Promise<void>;
48
+ close(): Promise<void>;
49
+ /**
50
+ * Make sure the whole defined connection topology is configured. Goes through each exchange, queue and binding and
51
+ * waits until all of them are initialized.
52
+ *
53
+ * @return A promise that fulfills after all defined exchanges, queues and bindings are initialized.
54
+ */
55
+ completeConfiguration(): Promise<any>;
56
+ /**
57
+ * Delete the whole defined connection topology:
58
+ * return promise that fulfills after all defined exchanges, queues and bindings have been removed
59
+ */
60
+ deleteConfiguration(): Promise<any>;
61
+ /**
62
+ * Declares a new exchange. Dependent on the options it auto creates the exchange if it does not already exists.
63
+ *
64
+ * @param name The name of the exchange.
65
+ * @param type The type
66
+ * @param options Options that are passed to assertExchange in amqp-lib.
67
+ * @returns The declared queue. You need to await the initialization of the queue.
68
+ */
69
+ declareExchange(name: string, type?: ExchangeType, options?: ExchangeDeclarationOptions): Exchange;
70
+ /**
71
+ * Declares an exchange and waits until it is initialized.
72
+ *
73
+ * @param name The name of the exchange.
74
+ * @param type The exchange type.
75
+ * @param options Any declaration options.
76
+ * @returns A promise that resolves when the exchange is declared and initialized.
77
+ */
78
+ declareExchangeAsync(name: string, type?: ExchangeType, options?: ExchangeDeclarationOptions): Promise<Exchange>;
79
+ /**
80
+ * Declares a new queue.
81
+ *
82
+ * @param name The name of the queue.
83
+ * @param options Any options for the queue declaration.
84
+ * @returns The queue.
85
+ */
86
+ declareQueue(name: string, options?: QueueDeclarationOptions): Queue;
87
+ /**
88
+ * Declares a new queue and waits until it is intitialized.
89
+ *
90
+ * @param name The name of the queue.
91
+ * @param options Any options for the queue declaration.
92
+ * @returns A promise that resolves when the queue is declared and initialized.
93
+ */
94
+ declareQueueAsync(name: string, options?: QueueDeclarationOptions): Promise<Queue>;
95
+ declareTopology(topology: Topology): Promise<any>;
96
+ get getConnection(): AmqpLib.Connection;
97
+ /**
98
+ * Returns an object with metrics about the connection.
99
+ * @returns An object containing metrics about the connection.
100
+ */
101
+ getMetrics(): ConnectionMetrics;
102
+ private rebuildConnection;
103
+ /**
104
+ * Increments an internal counter.
105
+ * @param counter The counter to increase.
106
+ * @param value The increment, default is 1.
107
+ */
108
+ _increaseCounter(counter: "receivedMessages" | "sentMessages", value?: number): void;
109
+ }