Comments (8)
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.
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.
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.
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.
@charlyz RabbitMQ log should be pretty clear about what causes the channel exception.
from amqplib.
@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.
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.
I see. We are not a banking company it should make it. Thanks for your help guys.
from amqplib.
Related Issues (20)
- SDK connecting without errors after RabbitMQ service is shut down HOT 9
- Error emitted before handler is attached causes "Unhandled 'error' event" HOT 3
- consume does not respect promises? HOT 5
- Trailing dot in URL causes TLS failure HOT 2
- docs: channel api github page has broken top links HOT 2
- docs: confusing and inconsistent usage of terms "bork", "splode", "close" HOT 7
- global prefetch become 0 if per-consume prefetch set HOT 2
- ERR_SSL_EMS_NOT_ENABLED HOT 6
- How to determine if channel.ack() is successful? HOT 2
- CPU intensive controller prevents AMQP connection from receiving heartbeat, hence connections gets closed. HOT 2
- How to know if message is published ? HOT 6
- Aborting a Message Processing when RMQ Channel Closes HOT 8
- I'm encountering an "Unexpected close" error HOT 2
- Module not found: Can't resolve 'querystring' HOT 2
- Feature: Add support for AMQP 0.9.1 "update-secret" HOT 11
- 501 (FRAME-ERROR) - after indeterminate amount of large messages HOT 6
- Emits a acknowledge event. HOT 1
- Unable to cancel consumers HOT 4
- Error: Unexpected close at succeed HOT 13
- Typo in the example code HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amqplib.