node-amqp-connection-manager icon indicating copy to clipboard operation
node-amqp-connection-manager copied to clipboard

Feature Request - timeout for publish and sendToQueue

Open ozomer opened this issue 7 years ago • 3 comments

I've noticed that if the client cannot connect, calling to sendToQueue from the channel wrapper creates a promise that never resolves or rejects. This is an acceptable behavior in a "callbacks-api", but not in a "promises-api": calling await channel.sendToQueue(...) is dangerous for memory...

I wish this feature would exist in the original amqplib package, but their github page seems to be overloaded with issues and I don't think they will add such feature soon.

p-timeout could be helpful here. Is it possible to force "canceling" of the message being sent after sendToQueue was called (i.e. when the timeout is reached)? I guess I could call "disconnect" and destroy the whole connection instance.

Thanks!

ozomer avatar Jul 25 '18 14:07 ozomer

A better approach is to create a timer that calls channel.close(). This call will make the pending sendToQueue promise reject with Error: Channel closed.

ozomer avatar Jul 25 '18 14:07 ozomer

We just discovered a different use case for a timeout feature: When used in conjunction with an HTTP-API, we would like to have the HTTP request be responded with 2XX once rabbitmq confirms a message and with 503 if rabbitmq did not confirm for X seconds. Having a timeout for publish / sendToQueue, or having a possibility to cancel is required for such a usecase too. Would you accept a PR for this?

designtesbrot avatar Jan 23 '19 10:01 designtesbrot

@designtesbrot i have the same requirement

kasvith avatar Jul 27 '21 13:07 kasvith