Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizable reply routing in consumer #36

Closed
sashahohloma opened this issue Dec 2, 2023 · 2 comments
Closed

Customizable reply routing in consumer #36

sashahohloma opened this issue Dec 2, 2023 · 2 comments

Comments

@sashahohloma
Copy link

Hey there!
First of all, big thanks for you work! We really like your library, especially higher-level Consumer/Publisher API.

I want suggest an enhancement for Consumer API: in our application we need to route replies in specific exchanges and this is not possible due the order of Envelope properties in destructuring at line 200 of Consumer. For now we're use monkey patch from example which allow us to config reply function like Publisher.send method and kept default behaviour from documentation.

Do you think this change would be useful for the library?

const { Connection } = require('rabbitmq-client');
const { Consumer } = require('rabbitmq-client/lib/Consumer');

class ProcessingConsumer extends Consumer {
    _makeReplyfn(req) {
        return (body, envelope) => {
            if (!req.replyTo) {
                throw new Error('attempted to reply to a non-RPC message');
            }
            return this._ch.basicPublish({
                exchange: '',
                routingKey: req.replyTo,
                correlationId: req.correlationId,
                ...envelope,
            }, body);
        };
    }
}

class ProcessingConnection extends Connection {
    createConsumer(props, cb) {
        return new ProcessingConsumer(this, props, cb);
    }
}

exports.ProcessingConsumer = ProcessingConsumer;
exports.ProcessingConnection = ProcessingConnection;
@cody-greene
Copy link
Owner

cody-greene commented Dec 2, 2023 via email

@cody-greene
Copy link
Owner

Fixed in 4.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants