@simpleview/sv-pubsub 1.0.21 → 1.0.22
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.
|
@@ -34,14 +34,18 @@ class PubSubClient {
|
|
|
34
34
|
throw error;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
async publishMessage(
|
|
38
|
-
const
|
|
37
|
+
async publishMessage(topic, message) {
|
|
38
|
+
const topicName = typeof topic === "string" ? topic : topic.name;
|
|
39
|
+
if (typeof topicName !== "string") {
|
|
40
|
+
throw new Error("Topic name must be specified.");
|
|
41
|
+
}
|
|
42
|
+
const existingTopic = this.pubsub.topic(topicName);
|
|
39
43
|
try {
|
|
40
|
-
return await
|
|
44
|
+
return await existingTopic.publishMessage(message);
|
|
41
45
|
}
|
|
42
46
|
catch (e) {
|
|
43
47
|
if (e.code === 5) { // NOT_FOUND
|
|
44
|
-
const [newTopic] = await this.pubsub.createTopic(
|
|
48
|
+
const [newTopic] = await this.pubsub.createTopic(topic);
|
|
45
49
|
return await newTopic.publishMessage(message);
|
|
46
50
|
}
|
|
47
51
|
throw e;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PubSub, Subscription } from "@google-cloud/pubsub";
|
|
2
|
-
import { MessageOptions } from "@google-cloud/pubsub/build/src/topic";
|
|
2
|
+
import { MessageOptions, TopicMetadata } from "@google-cloud/pubsub/build/src/topic";
|
|
3
3
|
export type PubSubClientOptions = {
|
|
4
4
|
projectId: string;
|
|
5
5
|
credentials: {
|
|
@@ -12,6 +12,6 @@ export default class PubSubClient {
|
|
|
12
12
|
constructor(options: PubSubClientOptions);
|
|
13
13
|
createTopic(topicName: string): Promise<import("@google-cloud/pubsub").Topic>;
|
|
14
14
|
createSubscription(topicName: string, subscriptionName: string, retentionDuration?: number): Promise<Subscription>;
|
|
15
|
-
publishMessage(
|
|
15
|
+
publishMessage(topic: string | TopicMetadata, message: MessageOptions): Promise<string>;
|
|
16
16
|
close(): Promise<void>;
|
|
17
17
|
}
|