amqp-extension 3.1.0 → 3.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # [3.2.0](https://github.com/Tada5hi/amqp-extension/compare/v3.1.1...v3.2.0) (2024-03-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove unnecessary alias option ([8027d0a](https://github.com/Tada5hi/amqp-extension/commit/8027d0afb2063e5d0387dacf26cd77444dc933e4))
7
+
8
+
9
+ ### Features
10
+
11
+ * allways close channel after publishing ([a9b300f](https://github.com/Tada5hi/amqp-extension/commit/a9b300f6ab64d176a656cf9fc485f31a36168a7f))
12
+
13
+ ## [3.1.1](https://github.com/Tada5hi/amqp-extension/compare/v3.1.0...v3.1.1) (2024-03-07)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * don't register consumer multiple times ([b45defa](https://github.com/Tada5hi/amqp-extension/commit/b45defa4dbd5a7abf6d2568586e2ff5bf2e62d16))
19
+
1
20
  # [3.1.0](https://github.com/Tada5hi/amqp-extension/compare/v3.0.0...v3.1.0) (2024-03-06)
2
21
 
3
22
 
@@ -4,7 +4,6 @@ exports.buildDriverConsumeOptions = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  function buildDriverConsumeOptions(options) {
6
6
  return (0, utils_1.removeKeysFromOptions)({ ...options }, [
7
- 'alias',
8
7
  'exchange',
9
8
  'queueName',
10
9
  'requeueOnFailure',
package/dist/module.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Connection } from 'amqplib';
1
+ import type { Channel, Connection } from 'amqplib';
2
2
  import type { Config, ConfigInput } from './config';
3
3
  import type { ConsumeHandlers } from './consume';
4
4
  import type { PublishOptionsExtended } from './publish';
@@ -16,6 +16,7 @@ export declare class Client {
16
16
  protected createConnection(): Promise<Connection>;
17
17
  useConnection(): Promise<Connection>;
18
18
  protected recreateConsumers(): Promise<void>;
19
+ protected createConsumer(options: ConsumeOptions, handlers: ConsumeHandlers): Promise<Channel>;
19
20
  consume(options: ConsumeOptions, handlers: ConsumeHandlers): Promise<void>;
20
21
  publish(options: PublishOptionsExtended): Promise<boolean>;
21
22
  }
package/dist/module.js CHANGED
@@ -64,10 +64,10 @@ class Client {
64
64
  }
65
65
  async recreateConsumers() {
66
66
  for (let i = 0; i < this.consumers.length; i++) {
67
- await this.consume(this.consumers[i].options, this.consumers[i].handlers);
67
+ await this.createConsumer(this.consumers[i].options, this.consumers[i].handlers);
68
68
  }
69
69
  }
70
- async consume(options, handlers) {
70
+ async createConsumer(options, handlers) {
71
71
  const connection = await this.useConnection();
72
72
  const channel = await connection.createChannel();
73
73
  options = (0, smob_1.merge)(options, this.config.consume);
@@ -120,6 +120,10 @@ class Client {
120
120
  }
121
121
  };
122
122
  await channel.consume(queueName, (message) => handleMessage(message), (0, consume_1.buildDriverConsumeOptions)(options));
123
+ return channel;
124
+ }
125
+ async consume(options, handlers) {
126
+ await this.createConsumer(options, handlers);
123
127
  this.consumers.push({
124
128
  options,
125
129
  handlers,
@@ -153,10 +157,12 @@ class Client {
153
157
  if (typeof exchangeOptions.routingKey === 'undefined') {
154
158
  throw new Error('The routingKey can not be empty if a non default exchange is selected.');
155
159
  }
156
- return channel.publish(this.config.exchange.name, exchangeOptions.routingKey, buffer, (0, publish_1.buildDriverPublishOptions)({
160
+ const published = channel.publish(this.config.exchange.name, exchangeOptions.routingKey, buffer, (0, publish_1.buildDriverPublishOptions)({
157
161
  persistent: true,
158
162
  ...options,
159
163
  }));
164
+ await channel.close();
165
+ return published;
160
166
  }
161
167
  // publish to default exchange
162
168
  const queueName = options.queueName ||
@@ -167,10 +173,12 @@ class Client {
167
173
  await channel.assertQueue(queueName, {
168
174
  durable: true,
169
175
  });
170
- return channel.sendToQueue(queueName, buffer, (0, publish_1.buildDriverPublishOptions)({
176
+ const published = channel.sendToQueue(queueName, buffer, (0, publish_1.buildDriverPublishOptions)({
171
177
  persistent: true,
172
178
  ...options,
173
179
  }));
180
+ await channel.close();
181
+ return published;
174
182
  }
175
183
  }
176
184
  exports.Client = Client;
@@ -4,7 +4,6 @@ exports.buildDriverPublishOptions = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  function buildDriverPublishOptions(options) {
6
6
  return (0, utils_1.removeKeysFromOptions)({ ...options }, [
7
- 'alias',
8
7
  'exchange',
9
8
  'queueName',
10
9
  'content',
package/dist/type.d.ts CHANGED
@@ -1,11 +1,6 @@
1
1
  import type { Options } from 'amqplib';
2
- import type { ConfigInput } from './config';
3
2
  import type { ExchangeOptions } from './exchange';
4
3
  type CommonOptions = {
5
- /**
6
- * Config key or object.
7
- */
8
- alias?: string | ConfigInput;
9
4
  /**
10
5
  * Exchange
11
6
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amqp-extension",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "An amqp extension with functions and utility functions to consume and publish queue messages.",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "dist/index.d.ts",