This commit is contained in:
Erik 2023-07-13 19:25:48 +03:00
parent 279914dddf
commit ee816f3b04
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -255,7 +255,7 @@ class MessageBroker
} }
// Subscribe to exchange, ensures messages aren't lost by binding it to a queue // Subscribe to exchange, ensures messages aren't lost by binding it to a queue
async subscribe<T> (name: string, listener: Subscriber<T | Buffer>) async subscribe<T> (name: string, listener: Subscriber<T>)
{ {
if (!this.#channel) if (!this.#channel)
throw new Error('Channel does not exist'); throw new Error('Channel does not exist');
@ -270,7 +270,7 @@ class MessageBroker
} }
private async _subscribe<T> (name: string, listener: Subscriber<T | Buffer>): Promise<void> private async _subscribe<T> (name: string, listener: Subscriber<T>): Promise<void>
{ {
if (!this.#channel) if (!this.#channel)
return Promise.reject(new Error('Channel doesn\'t exist')); return Promise.reject(new Error('Channel doesn\'t exist'));
@ -283,8 +283,10 @@ class MessageBroker
{ {
if (msg.content && msg.content.toString().startsWith('{')) if (msg.content && msg.content.toString().startsWith('{'))
await listener(JSON.parse(msg.content.toString()), msg); await listener(JSON.parse(msg.content.toString()), msg);
else else
await listener(msg.content, msg); // TODO: Figure out how to do this and remaing logically consistent
throw new Error('Malformed content');
// await listener(msg.content, msg);
this.#channel?.ack(msg); this.#channel?.ack(msg);
}); });
} }