@nestjstools/messaging-google-pubsub-extension 1.0.1 → 1.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/README.md CHANGED
@@ -109,6 +109,28 @@ export class CreateUserHandler implements IMessageHandler<CreateUser>{
109
109
  * Easily configure projectId, topicName, and subscriptionName for full control over Pub/Sub setup.
110
110
  ---
111
111
 
112
+ ## 📨 Communicating Beyond a NestJS Application (Cross-Language Messaging)
113
+
114
+ ### To enable communication with a Handler from services written in other languages, follow these steps:
115
+
116
+ 1. **Publish a Message to the Topic**
117
+
118
+ 2. **Include the Routing Key Header**
119
+ Your message **must** include a header attribute named `messaging-routing-key`.
120
+ The value should correspond to the routing key defined in your NestJS message handler:
121
+
122
+ ```ts
123
+ @MessageHandler('my_app_command.create_user') // <-- Use this value as the routing key
124
+ ```
125
+
126
+ ---
127
+ ## 🔧 Send additional attributes into your message
128
+
129
+ ```ts
130
+ this.pubSubMessageBus.dispatch(new RoutingMessage(new CreateUser('id'), 'my_app_command.create_user', new GooglePubSubMessageOptions({YourAttribute: 'value'})));
131
+ ```
132
+ ---
133
+
112
134
  ## Configuration options
113
135
 
114
136
  ### GooglePubSubChannel
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,KAAK,CAAC,IAA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