Giter Site home page Giter Site logo

Comments (8)

squaremo avatar squaremo commented on May 20, 2024

You can use a feature of RabbitMQ called "confirmations" to find out if messages have arrived: http://www.rabbitmq.com/confirms.html

amqplib supports confirmations via ConfirmChannels. With a ConfirmChannel, #publish and #sendToQueue return a promise which is resolved when the message is acknowledged by the server (or rejected if it's nacked).

var ok = api.connect('amqp://localhost');
ok = ok.then(function(conn) {
    return conn.createConfirmChannel();
});
ok = ok.then(function(ch) {
    return ch.publish(...).then(function() { console.log("Acknowledged!"); });
});
ok.then(null, console.warn);

(That's in the current release. For future releases I've changed it so that #publish and #sendToQueue take a callback, rather than returning a promise)

from amqplib.

michaelklishin avatar michaelklishin commented on May 20, 2024

No other client has two separate functions for channel creation. Maybe it should be possible to enable confirms on a channel, like all other clients do? E.g. with Bunny

ch = conn.create_channel
ch.confirm_select

from amqplib.

squaremo avatar squaremo commented on May 20, 2024

No other client has two separate functions for channel creation. Maybe it should be possible to enable confirms on a channel, like all other clients do?

My reasoning is that you're either going to want to have confirms on or off from the get-go. The same goes for transactions, though I haven't implemented them.

from amqplib.

charlyz avatar charlyz commented on May 20, 2024

Thanks so much for you quick answer. My main concern is that if the channel is not found (or "cannot be used for whatever reasons") but try to publish something anyway, the channel error handler is triggered. If I understand correctly, I should keep track of all the messages I send. If a message is acknowledged then I can stop worrying about it. And if the channel error handler is triggered, I should re-send all the messages which have not been acknowledged. Am I right?

from amqplib.

michaelklishin avatar michaelklishin commented on May 20, 2024

@charlyz RabbitMQ log should be pretty clear about what causes the channel exception.

from amqplib.

charlyz avatar charlyz commented on May 20, 2024

@michaelklishin I guess :) My point is that it would be easier not to resolve the publish() promise if something goes wrong (channel closed, connection closed, earthquake, etc.) instead of triggering the channel error handler.

from amqplib.

squaremo avatar squaremo commented on May 20, 2024

And if the channel error handler is triggered, I should re-send all the messages which have not been acknowledged. Am I right?

Yes, although not getting an acknowledgment doesn't mean it hasn't been sent: the channel may have broken before the acknowledgment could be received. So it really depends on whether you are happier with the possibility of duplicates, or of missing messages.

from amqplib.

charlyz avatar charlyz commented on May 20, 2024

I see. We are not a banking company it should make it. Thanks for your help guys.

from amqplib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.