From ab3d06e9cae992b2ff97ebd1ef55b32c4152744c Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 14 Dec 2021 21:26:40 -0500 Subject: [PATCH] fix topic array subscription --- src/moto/broker.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/moto/broker.js b/src/moto/broker.js index ce2e5ea1..118b0a0a 100644 --- a/src/moto/broker.js +++ b/src/moto/broker.js @@ -8,6 +8,12 @@ class Broker { } subscribe(topic, listener) { + if (Array.isArray(topic)) { + for (let t of topic) { + this.subscribe(t, listener); + } + return; + } let topics = this.topics; let channel = topics[topic]; if (!channel) { @@ -36,13 +42,24 @@ class Broker { } publish(topic, message, options = {}) { + if (Array.isArray(topic)) { + for (let t of topic) { + this.publish(t, message, options); + } + return; + } if (topic !== ".topic.publish") { this.publish(".topic.publish", {topic, message, options}); } let channel = this.topics[topic]; if (channel && channel.length) { for (let listener of channel) { - listener(message, topic, options); + try { + listener(message, topic, options); + } catch (e) { + // console.log({listener_error: e, topic, options, listener}); + setTimeout(() => { throw e }, 1); + } } } }