rxjs-rabbitmq 2.0.2 → 2.0.3

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/dist/enums.d.ts CHANGED
@@ -3,6 +3,12 @@ export declare enum ContentTypes {
3
3
  TEXT = "text/plain",
4
4
  STREAM = "application/octet-stream"
5
5
  }
6
+ export declare enum ExchangeTypes {
7
+ DIRECT = "direct",
8
+ TOPIC = "topic",
9
+ HEADERS = "headers",
10
+ FANOUT = "fanout"
11
+ }
6
12
  export declare enum MimeTypes {
7
13
  AAC = "audio/aac",
8
14
  ABW = "application/x-abiword",
package/dist/enums.js CHANGED
@@ -4,6 +4,13 @@ export var ContentTypes;
4
4
  ContentTypes["TEXT"] = "text/plain";
5
5
  ContentTypes["STREAM"] = "application/octet-stream";
6
6
  })(ContentTypes || (ContentTypes = {}));
7
+ export var ExchangeTypes;
8
+ (function (ExchangeTypes) {
9
+ ExchangeTypes["DIRECT"] = "direct";
10
+ ExchangeTypes["TOPIC"] = "topic";
11
+ ExchangeTypes["HEADERS"] = "headers";
12
+ ExchangeTypes["FANOUT"] = "fanout";
13
+ })(ExchangeTypes || (ExchangeTypes = {}));
7
14
  export var MimeTypes;
8
15
  (function (MimeTypes) {
9
16
  MimeTypes["AAC"] = "audio/aac";
package/dist/enums.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,yCAAyB,CAAA;IACzB,mCAAmB,CAAA;IACnB,mDAAmC,CAAA;AACrC,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,MAAM,CAAN,IAAY,SAyEX;AAzED,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,0CAA6B,CAAA;IAC7B,0CAA6B,CAAA;IAC7B,oCAAuB,CAAA;IACvB,iDAAoC,CAAA;IACpC,6CAAgC,CA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,gCAAmB,CAAA;IACnB,yDAA4C,CAAA;IAC5C,oEAAuD,CAAA;IACvD,mEAAsD,CAAA;IACtD,4DAA+C,CAAA;IAC/C,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;IACjB,oCAAuB,CAAA;IACvB,gCAAmB,CAAA;IACnB,6BAAgB,CAAA;IAChB,8BAAiB,CAAA;IACjB,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,kDAAqC,CAAA;IACrC,+FAAkF,CAAA;IAClF,wCAA2B,CAAA;IAC3B,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,kCAAqB,CAAA;IACrB,kDAAqC,CAAA;IACrC,sCAAyB,CAAA;IACzB,+BAAkB,CAAA;IAClB,gCAAmB,CAAA;IACnB,8BAAiB,CAAA;IACjB,6BAAgB,CAAA;IAChB,+BAAkB,CAAA;IAClB,0CAA6B,CAAA;IAC7B,8BAAiB,CAAA;IACjB,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,+BAAkB,CAAA;IAClB,iCAAoB,CAAA;IACpB,4CAA+B,CAAA;IAC/B,6CAAgC,CAAA;IAChC,uFAA0E,CAAA;IAC1E,wBAAW,CAAA;IACX,oDAAuC,CAAA;IACvC,oCAAuB,CAAA;IACvB,qCAAwB,CAAA;IACxB,sCAAyB,CAAA;IACzB,wDAA2C,CAAA;AAC7C,CAAC,EAzEW,SAAS,KAAT,SAAS,QAyEpB"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { Options, ConsumeMessage, Message } from "amqplib";
2
+ /**
3
+
4
+ */
2
5
  export type MapType<T = any> = {
3
6
  [key: string]: T;
4
7
  };
@@ -8,19 +11,72 @@ export type RmqHandleMessageTypeConfig = {
8
11
  callbackHandler: RmqMessageTypeHandler;
9
12
  };
10
13
  export type RmqHandleMessageTypeConfigs = string[] | RmqHandleMessageTypeConfig[];
14
+ export type ExchangeType = 'direct' | 'topic' | 'headers' | 'fanout';
11
15
  export interface QueueConfig {
16
+ /**
17
+ The name of the queue you want to consume messages from
18
+ */
12
19
  name: string;
20
+ /**
21
+ the events to handle on the queue via the message.properties.type value.
22
+ This event name approach is a custom logic, not an official use or convention of message brokers.
23
+ For example, there could be a `USERS` queue with messages of different events
24
+ such as `DELETE_USER` or `CREATE_USER`.
25
+
26
+ This approach is if you want to consolidate different events into a single queue; it is possible to
27
+ have a dedicated queue for specific events such as a `CREATE_USER` queue, hence why this property is optional.
28
+ */
13
29
  handleMessageTypes?: RmqHandleMessageTypeConfigs;
14
30
  options?: Options.AssertQueue;
15
31
  }
32
+ /**
33
+ The exchange config.
34
+ An exchange is the means of delivering a message from a producer to a queue for consumers.
35
+ In other words, the post man that delivers mail.
36
+
37
+ This is usually defined for a producer to publish event messages
38
+ and how queues are allowed to receive messages from the exchange (based on the exchange type).
39
+ */
16
40
  export interface ExchangeConfig {
41
+ /**
42
+ The name of the exchange
43
+ */
17
44
  name: string;
18
- type: string;
45
+ /**
46
+ The exchange type.
47
+
48
+ - `direct`: deliver to queue(s) based on EXACT matching routing key
49
+ - `topic`: deliver to queue(s) based on PATTERN matching routing key
50
+ - `headers`: deliver to queue(s) based on HEADERS
51
+ - `direct`: deliver to queue(s); ignore routing
52
+
53
+ The `topic` type is the most flexible because it can function as both a `direct` and `fanout`,
54
+ giving consumers more ways to filter the messages from an exchange.
55
+ */
56
+ type: ExchangeType;
57
+ /**
58
+ Other options for exchange
59
+ */
19
60
  options?: Options.AssertExchange;
20
61
  }
62
+ /**
63
+ The exchange to queue binding.
64
+ This config determines what queues an exchange will forward messages to.
65
+
66
+ It is usually defined for a consumer to request messages from an exchange to a queue they are consuming/listening on
67
+ */
21
68
  export interface QueueExchangeBindingConfig {
69
+ /**
70
+ The queue for the consumer to receive messages in
71
+ */
22
72
  queue: string;
73
+ /**
74
+ The exchange for the consumer to request messages from
75
+ */
23
76
  exchange: string;
77
+ /**
78
+ The key for the consumer to filter the messages on
79
+ */
24
80
  routingKey: string;
25
81
  }
26
82
  export type RmqEventRequestResponse<T = any> = Promise<RmqEventMessage<T>>;
@@ -49,7 +105,14 @@ export type RmqEventMessage<T = any> = {
49
105
  sendRequest: <T = any>(options: RmqSendRequestParams) => Promise<RmqEventMessage<T>>;
50
106
  };
51
107
  export type AckFn = (message: Message) => void;
108
+ /**
109
+
110
+ */
52
111
  export type RabbitMqInitConfig = {
112
+ /**
113
+ Stop the constructor from automatically initializing the setup process.
114
+ Allows for manually initializing later.
115
+ */
53
116
  stopAutoInit?: boolean;
54
117
  dontSendToReplyQueueOnPublish?: boolean;
55
118
  autoAckUnhandledMessageTypes?: boolean;
@@ -60,10 +123,16 @@ export type RabbitMqInitConfig = {
60
123
  retryDelay: number;
61
124
  prefetch?: number;
62
125
  /**
63
- The queues you want to consume on this client
126
+ The queues to assert on this client
64
127
  */
65
128
  queues: Array<QueueConfig>;
129
+ /**
130
+ The exchanges to assert on this client
131
+ */
66
132
  exchanges: Array<ExchangeConfig>;
133
+ /**
134
+ The bindings to assert on this client
135
+ */
67
136
  bindings: Array<QueueExchangeBindingConfig>;
68
137
  pre_init_promises?: (Promise<any> | (() => Promise<any>))[];
69
138
  post_init_promises?: (Promise<any> | (() => Promise<any>))[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rxjs-rabbitmq",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "RxJS powered RabbitMQ event handling",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/enums.ts CHANGED
@@ -4,6 +4,13 @@ export enum ContentTypes {
4
4
  STREAM = 'application/octet-stream'
5
5
  }
6
6
 
7
+ export enum ExchangeTypes {
8
+ DIRECT = 'direct',
9
+ TOPIC = 'topic',
10
+ HEADERS = 'headers',
11
+ FANOUT = 'fanout',
12
+ }
13
+
7
14
  export enum MimeTypes {
8
15
  AAC = "audio/aac",
9
16
  ABW = "application/x-abiword",
package/src/types.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  Message
5
5
  } from "amqplib";
6
6
 
7
- /*
7
+ /**
8
8
 
9
9
  */
10
10
 
@@ -14,33 +14,87 @@ export type MapType<T = any> = { [key:string]: T };
14
14
  export type RmqMessageTypeHandler = (event: RmqEventMessage) => Promise<void>;
15
15
  export type RmqHandleMessageTypeConfig = { messageName: string, callbackHandler: RmqMessageTypeHandler };
16
16
  export type RmqHandleMessageTypeConfigs = string[] | RmqHandleMessageTypeConfig[];
17
+ export type ExchangeType = 'direct' | 'topic' | 'headers' | 'fanout';
18
+
17
19
 
18
20
  export interface QueueConfig {
19
- /*
21
+ /**
20
22
  The name of the queue you want to consume messages from
21
23
  */
22
24
  name: string,
23
25
 
24
- /*
25
- the event names
26
+ /**
27
+ the events to handle on the queue via the message.properties.type value.
28
+ This event name approach is a custom logic, not an official use or convention of message brokers.
29
+ For example, there could be a `USERS` queue with messages of different events
30
+ such as `DELETE_USER` or `CREATE_USER`.
31
+
32
+ This approach is if you want to consolidate different events into a single queue; it is possible to
33
+ have a dedicated queue for specific events such as a `CREATE_USER` queue, hence why this property is optional.
26
34
  */
27
35
  handleMessageTypes?: RmqHandleMessageTypeConfigs,
28
36
 
29
37
  /*
30
-
38
+ Other options for queue
31
39
  */
32
40
  options?: Options.AssertQueue
33
41
  }
34
42
 
43
+
44
+ /**
45
+ The exchange config.
46
+ An exchange is the means of delivering a message from a producer to a queue for consumers.
47
+ In other words, the post man that delivers mail.
48
+
49
+ This is usually defined for a producer to publish event messages
50
+ and how queues are allowed to receive messages from the exchange (based on the exchange type).
51
+ */
35
52
  export interface ExchangeConfig {
53
+ /**
54
+ The name of the exchange
55
+ */
36
56
  name: string,
37
- type: string,
57
+
58
+ /**
59
+ The exchange type.
60
+
61
+ - `direct`: deliver to queue(s) based on EXACT matching routing key
62
+ - `topic`: deliver to queue(s) based on PATTERN matching routing key
63
+ - `headers`: deliver to queue(s) based on HEADERS
64
+ - `direct`: deliver to queue(s); ignore routing
65
+
66
+ The `topic` type is the most flexible because it can function as both a `direct` and `fanout`,
67
+ giving consumers more ways to filter the messages from an exchange.
68
+ */
69
+ type: ExchangeType,
70
+
71
+ /**
72
+ Other options for exchange
73
+ */
38
74
  options?: Options.AssertExchange
39
75
  }
40
76
 
77
+
78
+ /**
79
+ The exchange to queue binding.
80
+ This config determines what queues an exchange will forward messages to.
81
+
82
+ It is usually defined for a consumer to request messages from an exchange to a queue they are consuming/listening on
83
+ */
41
84
  export interface QueueExchangeBindingConfig {
85
+ /**
86
+ The queue for the consumer to receive messages in
87
+ */
42
88
  queue: string,
89
+
90
+ /**
91
+ The exchange for the consumer to request messages from
92
+ */
43
93
  exchange: string,
94
+
95
+ /**
96
+ The key for the consumer to filter the messages on
97
+ */
44
98
  routingKey: string
45
99
  }
46
100
 
@@ -76,7 +130,15 @@ export type RmqEventMessage<T = any> = {
76
130
 
77
131
  export type AckFn = (message: Message) => void;
78
132
 
133
+
134
+ /**
135
+
136
+ */
79
137
  export type RabbitMqInitConfig = {
138
+ /**
139
+ Stop the constructor from automatically initializing the setup process.
140
+ Allows for manually initializing later.
141
+ */
80
142
  stopAutoInit?: boolean,
81
143
  dontSendToReplyQueueOnPublish?: boolean,
82
144
  autoAckUnhandledMessageTypes?: boolean,
@@ -88,10 +150,17 @@ export type RabbitMqInitConfig = {
88
150
  prefetch?: number,
89
151
 
90
152
  /**
91
- The queues you want to consume on this client
153
+ The queues to assert on this client
92
154
  */
93
155
  queues: Array<QueueConfig>,
156
+ /**
157
+ The exchanges to assert on this client
158
+ */
94
159
  exchanges: Array<ExchangeConfig>,
160
+
161
+ /**
162
+ The bindings to assert on this client
163
+ */
95
164
  bindings: Array<QueueExchangeBindingConfig>,
96
165
 
97
166
  pre_init_promises?: (Promise<any> | (() => Promise<any>))[],