sb-rabbitmq-provider 1.0.14 → 1.0.19

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/index.d.ts CHANGED
@@ -3,19 +3,34 @@
3
3
  * if all connections are established then ready event will get triggered
4
4
  */
5
5
  import { Connection as RabbitmqClientConnection, Channel as RabbitMQChannel, Options } from 'amqplib';
6
+ interface rabbitMQConfig {
7
+ protocol?: string | undefined;
8
+ hostname?: string | undefined;
9
+ port?: number | undefined;
10
+ username?: string | undefined;
11
+ password?: string | undefined;
12
+ locale?: string | undefined;
13
+ frameMax?: number | undefined;
14
+ heartbeat?: number | undefined;
15
+ vhost?: string | undefined;
16
+ exchangeName?: string;
17
+ exchangeType: string;
18
+ publishOptions?: Record<string, string> | undefined;
19
+ }
6
20
  type MyCallback = (data: any) => any;
7
21
  declare class RabbitMqConnection {
8
- url: string;
22
+ config: rabbitMQConfig;
9
23
  exchange: string;
10
24
  exchangeType: string;
11
25
  connection: any;
26
+ publishOptions: Options.Publish | undefined;
12
27
  /**
13
28
  * constructor for initialising url, exchange name, exchange type
14
29
  * @param url rabbitmq url
15
30
  * @param exchange rabbitmq exchange name
16
31
  * @param exchangeType type of exchange
17
32
  */
18
- constructor(url?: string, exchange?: string, exchangeType?: string);
33
+ constructor(config: rabbitMQConfig);
19
34
  /**
20
35
  * creates the rabbitmq connection
21
36
  * connection must be single, with multiple channel
package/dist/index.js CHANGED
@@ -24,16 +24,17 @@ class RabbitMqConnection {
24
24
  * @param exchange rabbitmq exchange name
25
25
  * @param exchangeType type of exchange
26
26
  */
27
- constructor(url = 'amqp://127.0.0.1:5672', exchange, exchangeType) {
27
+ constructor(config) {
28
28
  this.exchange = 'EXCHANGE';
29
29
  this.exchangeType = 'direct';
30
- this.url = url;
31
- if (exchange && typeof exchange === 'string') {
32
- this.exchange = exchange;
30
+ if (config.exchangeName && typeof config.exchangeName === 'string') {
31
+ this.exchange = config.exchangeName;
33
32
  }
34
- if (exchangeType && typeof exchangeType === 'string') {
35
- this.exchangeType = exchangeType;
33
+ if (config.exchangeType && typeof config.exchangeType === 'string') {
34
+ this.exchangeType = config.exchangeType;
36
35
  }
36
+ this.publishOptions = config.publishOptions || undefined;
37
+ this.config = config;
37
38
  }
38
39
  /**
39
40
  * creates the rabbitmq connection
@@ -43,7 +44,7 @@ class RabbitMqConnection {
43
44
  createConnection() {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
46
  try {
46
- const connection = yield amqplib_1.default.connect(this.url);
47
+ const connection = yield amqplib_1.default.connect(this.config);
47
48
  // console.log('---RabbitMQ Connection Created---')
48
49
  this.connection = connection;
49
50
  return connection;
@@ -80,7 +81,7 @@ class RabbitMqConnection {
80
81
  return __awaiter(this, void 0, void 0, function* () {
81
82
  try {
82
83
  const bufferMessage = Buffer.from(JSON.stringify(message));
83
- channel.publish(this.exchange, queueName, bufferMessage);
84
+ channel.publish(this.exchange, queueName, bufferMessage, this.publishOptions);
84
85
  return { status: true, message: 'Data sent to Queue' };
85
86
  }
86
87
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sb-rabbitmq-provider",
3
- "version": "1.0.14",
3
+ "version": "1.0.19",
4
4
  "description": "Pub/Sub model for RabbitMq",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",