Node-RED AMQP Ack/Prefetch Nodes
The `node-red-contrib-amqp-ack` package provides Node-RED users with robust input and output nodes for interacting with AMQP message brokers like RabbitMQ. Its core functionality includes subscribing to (input) and publishing to (output) AMQP exchanges or queues, with explicit support for message acknowledgment and prefetch count control, ensuring more reliable message processing within Node-RED flows. The package, currently at stable version 1.1.2, has a slow release cadence for new features, with the last significant update dating back four years. A key differentiator is its focus on reliable message delivery through configurable ack and prefetch mechanisms, which are crucial for preventing message loss or excessive load on Node-RED instances. It bundles the `amqp-ts` library for underlying AMQP connectivity, which itself is built upon `amqplib`. However, the `amqp-ts` dependency is largely unmaintained, presenting significant compatibility issues with modern Node.js versions.
Common errors
-
Failed to load flow: Error: Cannot find module 'amqplib/lib/connection'.
cause The underlying `amqp-ts` library uses an old version of `amqplib` which is incompatible with newer Node.js versions or has module resolution issues in certain environments.fixUpgrade your Node-RED instance to use a different AMQP package like `@meowwolf/node-red-contrib-amqp` which supports modern Node.js. If you must use this package, downgrade your Node.js runtime to version 8 or older (not recommended). -
Error: read ECONNRESET / Connection closed. No error event. / Amqp rabbit disconnected issue.
cause The connection to the AMQP broker (e.g., RabbitMQ) was unexpectedly closed, often due to network instability, broker restart, or incorrect broker configuration.fixVerify network connectivity between Node-RED and the AMQP broker. Check RabbitMQ server logs for client disconnect reasons. Ensure the AMQP server configuration node has correct hostname, port, and vhost settings. While the node attempts reconnection, persistent issues require external resolution. -
Messages are received by the 'amqp in' node but disappear without being processed by subsequent nodes, or are re-delivered repeatedly.
cause The 'amqp in' node is configured with 'noAck' unchecked, but no 'amqp ack' node is present in the flow to acknowledge messages after processing, leading to the broker re-queueing them.fixEnsure that every 'amqp in' node configured for explicit acknowledgment (`noAck` unchecked) has a corresponding 'amqp ack' node in its processing path to confirm message consumption. Place the 'amqp ack' node after all processing steps have successfully completed.
Warnings
- breaking The underlying `amqp-ts` library is unmaintained and is anchored to `amqplib@0.4.2`, which only supports Node.js versions up to 8. This package is incompatible with modern Node.js runtimes (Node.js 10+).
- deprecated This package is explicitly recommended to be replaced by alternative AMQP Node-RED contributions for environments using modern Node.js versions due to its core dependency's outdated status.
- gotcha Entering invalid credentials (username/password) in the AMQP configuration node can lead to Node-RED malfunctioning or becoming unresponsive, as the connection attempts might consume excessive resources.
- gotcha When `noAck` is unchecked on the 'amqp in' node, messages are not automatically acknowledged. Failure to use an 'amqp ack' node downstream will leave messages unacknowledged in the queue, leading to redelivery upon connection loss or message processing timeout.
Install
-
npm install node-red-contrib-amqp-ack -
yarn add node-red-contrib-amqp-ack -
pnpm add node-red-contrib-amqp-ack
Imports
- Node-RED Node Registration
import { AmqpInNode } from 'node-red-contrib-amqp-ack';RED.nodes.registerType('amqp in', AmqpInNode); RED.nodes.registerType('amqp out', AmqpOutNode); RED.nodes.registerType('amqp ack', AmqpAckNode); RED.nodes.registerType('amqp-server', AmqpServerConfigNode); - Loading Node Definitions (Internal Node-RED)
import AmqpInNode from 'node-red-contrib-amqp-ack/nodes/amqp-in';
const AmqpInNode = require('./nodes/amqp-in.js'); const AmqpOutNode = require('./nodes/amqp-out.js'); const AmqpAckNode = require('./nodes/amqp-ack.js'); const AmqpServerConfigNode = require('./nodes/amqp-server.js');
Quickstart
[{"id":"d16f7e8a.401828","type":"tab","label":"AMQP Ack/Prefetch Example","disabled":false,"info":"Example flow demonstrating AMQP input with acknowledgment and output."},{"id":"28b1e42a.5b512","type":"amqp in","z":"d16f7e8a.401828","name":"Listen to Queue (Ack)","server":"80c32d43.6826c8","exchange":"my-exchange","queue":"my-queue","exchangeType":"topic","routingKey":"#","noAck":false,"prefetch":1,"x":160,"y":120,"wires":[["71a7d6e6.2e47e8","65c3e7b.6f23e48"]]},{"id":"71a7d6e6.2e47e8","type":"debug","z":"d16f7e8a.401828","name":"Received Message","topic":"","property":"payload","x":390,"y":120,"wires":[]},{"id":"65c3e7b.6f23e48","type":"amqp ack","z":"d16f7e8a.401828","name":"Acknowledge Message","server":"80c32d43.6826c8","x":390,"y":180,"wires":[]},{"id":"ae7d5c7b.8f3b28","type":"inject","z":"d16f7e8a.401828","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"my.key","payload":"Hello AMQP","payloadType":"str","x":140,"y":300,"wires":[["69f41b9.5a52868"]]},{"id":"69f41b9.5a52868","type":"amqp out","z":"d16f7e8a.401828","name":"Publish to Exchange","server":"80c32d43.6826c8","exchange":"my-exchange","exchangeType":"topic","routingKey":"my.key","x":390,"y":300,"wires":[]},{"id":"80c32d43.6826c8","type":"amqp-server","name":"RabbitMQ Local","host":"localhost","port":"5672","vhost":"/","clientid":"node-red","heartbeat":"60","topology":"[]","tls":""}]