golevelup / nestjs

A collection of badass modules and utilities to help you level up your NestJS applications 🚀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Publish on AmqpConnection not returning boolean?

irarayjenkins opened this issue · comments

When I call the publish() method on the default amqpConnection, using version 5.0.0, I don't get a boolean value from the promise...

@Injectable
export class Service {
constructor(... private readonly amqpConnection: AmqpConnection) { ... }

public async doStuff() {
    let success: boolean;

    try {
        success = await this.amqpConnection.publish(exchange, routingKey, data);

        if(!success) throw new Error('Failed to publish message to queue');
    } catch (error) {
        // handle error condition
    }
}

I see 'Error: Failed to publish message to queue.' despite the message successfully making it into the local Rabbit MQ correctly. The variable success is undefined upon return from the publish() method.

If I replace this publish() call with the underlying publish() on the channel, I do successfully get a boolean as the promise return value.

@Injectable
export class Service {
constructor(... private readonly amqpConnection: AmqpConnection) { ... }

public async doStuff() {
    let success: boolean;

    try {
        success = await this.amqpConnection.managedChannel.publish(exchange, routingKey, data);

        if(!success) throw new Error('Failed to publish message to queue');
    } catch (error) {
        // handle error condition
    }
}

I'm confused because the library has AmqpConnection.publish() defined to return this._managedChannel.publish()...

Any thoughts on what I'm doing wrong, or how I might troubleshoot this? Should I not be depending on the return of publish to determine if a message was successfully published to a queue?

Closing this as resolved. The underlying problem was in my dependencies...

I have a nestjs application that depends on a nestjs monorepo. The monorepo was updated with RabbitMQ 5.0.0, and a new version released. The new version of the nestjs monorepo was linked to the nestjs application; however, the old dependencies (RabbitMQ 4.0.1) for the old monorepo never got updated with npm i. Thus the publish() method wasn't returning what I expected.