@nestjstools/messaging-google-pubsub-extension 1.1.0 → 1.3.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/README.md CHANGED
@@ -6,6 +6,14 @@
6
6
 
7
7
  A NestJS library for managing asynchronous and synchronous messages with support for buses, handlers, channels, and consumers. This library simplifies building scalable and decoupled applications by facilitating robust message handling pipelines while ensuring flexibility and reliability.
8
8
 
9
+ ---
10
+
11
+ ## Documentation
12
+
13
+ https://nestjstools.gitbook.io/nestjstools-messaging-docs
14
+
15
+ ---
16
+
9
17
  ## Installation
10
18
 
11
19
  ```bash
@@ -123,8 +131,12 @@ export class CreateUserHandler implements IMessageHandler<CreateUser>{
123
131
  @MessageHandler('my_app_command.create_user') // <-- Use this value as the routing key
124
132
  ```
125
133
 
126
- 3. **You're Done!**
127
- Once the message is published with the correct routing key, it will be automatically routed to the appropriate handler within the NestJS application.
134
+ ---
135
+ ## 🔧 Send additional attributes into your message
136
+
137
+ ```ts
138
+ this.pubSubMessageBus.dispatch(new RoutingMessage(new CreateUser('id'), 'my_app_command.create_user', new GooglePubSubMessageOptions({YourAttribute: 'value'})));
139
+ ```
128
140
  ---
129
141
 
130
142
  ## Configuration options
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './messaging-google-pub-sub-extension.module';
2
2
  export * from './channel/google-pub-sub.channel-config';
3
3
  export * from './message-bus/google-pub-sub-message.bus';
4
+ export * from './message/google-pub-sub-message-options';
package/lib/index.js CHANGED
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./messaging-google-pub-sub-extension.module"), exports);
18
18
  __exportStar(require("./channel/google-pub-sub.channel-config"), exports);
19
19
  __exportStar(require("./message-bus/google-pub-sub-message.bus"), exports);
20
+ __exportStar(require("./message/google-pub-sub-message-options"), exports);
20
21
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA2D;AAC3D,0EAAuD;AACvD,2EAAwD"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8EAA2D;AAC3D,0EAAuD;AACvD,2EAAwD;AACxD,2EAAwD"}
@@ -0,0 +1,11 @@
1
+ import { MessageOptions } from '@nestjstools/messaging';
2
+ export declare class GooglePubSubMessageOptions implements MessageOptions {
3
+ readonly attributes: {
4
+ [key: string]: string;
5
+ };
6
+ readonly middlewares: any[];
7
+ readonly avoidErrorsWhenNotExistedHandler: boolean;
8
+ constructor(attributes?: {
9
+ [key: string]: string;
10
+ });
11
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GooglePubSubMessageOptions = void 0;
4
+ class GooglePubSubMessageOptions {
5
+ attributes;
6
+ middlewares = [];
7
+ avoidErrorsWhenNotExistedHandler = false;
8
+ constructor(attributes = {}) {
9
+ this.attributes = attributes;
10
+ }
11
+ }
12
+ exports.GooglePubSubMessageOptions = GooglePubSubMessageOptions;
13
+ //# sourceMappingURL=google-pub-sub-message-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-pub-sub-message-options.js","sourceRoot":"","sources":["../../src/message/google-pub-sub-message-options.ts"],"names":[],"mappings":";;;AAEA,MAAa,0BAA0B;IAKnB;IAJF,WAAW,GAAU,EAAE,CAAC;IACxB,gCAAgC,GAAY,KAAK,CAAC;IAElE,YACkB,aAAwC,EAAE;QAA1C,eAAU,GAAV,UAAU,CAAgC;IAE5D,CAAC;CACF;AARD,gEAQC"}
@@ -14,15 +14,26 @@ const common_1 = require("@nestjs/common");
14
14
  const google_pub_sub_channel_1 = require("../channel/google-pub-sub.channel");
15
15
  const buffer_1 = require("buffer");
16
16
  const const_1 = require("../const");
17
+ const google_pub_sub_message_options_1 = require("../message/google-pub-sub-message-options");
17
18
  let GooglePubSubMessageBus = class GooglePubSubMessageBus {
18
19
  channel;
19
20
  constructor(channel) {
20
21
  this.channel = channel;
21
22
  }
22
23
  async dispatch(message) {
24
+ const messageOptions = message.messageOptions;
25
+ if (messageOptions !== undefined && !(messageOptions instanceof google_pub_sub_message_options_1.GooglePubSubMessageOptions)) {
26
+ throw new Error(`Message options must be a ${google_pub_sub_message_options_1.GooglePubSubMessageOptions.name} object`);
27
+ }
23
28
  const topic = this.channel.pubSubManager.topic(this.channel.config.topicName);
24
29
  const serializedMessage = JSON.stringify(message.message);
25
- await topic.publishMessage({ data: buffer_1.Buffer.from(serializedMessage), attributes: { [const_1.ROUTING_KEY_ATTRIBUTE_NAME]: message.messageRoutingKey } });
30
+ const data = buffer_1.Buffer.from(serializedMessage);
31
+ if (messageOptions instanceof google_pub_sub_message_options_1.GooglePubSubMessageOptions) {
32
+ const attributes = { [const_1.ROUTING_KEY_ATTRIBUTE_NAME]: message.messageRoutingKey, ...messageOptions.attributes };
33
+ await topic.publishMessage({ data, attributes });
34
+ return;
35
+ }
36
+ await topic.publishMessage({ data, attributes: { [const_1.ROUTING_KEY_ATTRIBUTE_NAME]: message.messageRoutingKey } });
26
37
  }
27
38
  };
28
39
  exports.GooglePubSubMessageBus = GooglePubSubMessageBus;
@@ -1 +1 @@
1
- {"version":3,"file":"google-pub-sub-message.bus.js","sourceRoot":"","sources":["../../src/message-bus/google-pub-sub-message.bus.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,2CAA4C;AAC5C,8EAAwE;AACxE,mCAAgC;AAChC,oCAAsD;AAG/C,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAEd;IADnB,YACmB,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;IAE/C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuB;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAA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