Registry / messaging / moleculer-rabbitmq

moleculer-rabbitmq

JSON →
library1.2.0jsnpmunverified

moleculer-rabbitmq is a task queue mixin for Moleculer microservices that integrates RabbitMQ as a message broker. Current stable version is 1.2.0. It provides a simple mixin that enables async queue versions of actions, supports RabbitMQ requeue and delayed message exchange retry strategies, and allows per-queue configuration for AMQP options such as durability and prefetch. Key differentiators include seamless integration with Moleculer's service architecture, automatic async action generation, and built-in retry mechanisms. Release cadence appears to be infrequent.

npm install moleculer-rabbitmq
INSTALL
IMPORT
SIG · MOLECULER-RABBITMQ
M
moleculer-rabbitmq
messagingjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

QueueMixin
import QueueMixin from 'moleculer-rabbitmq'
const { QueueMixin } = require('moleculer-rabbitmq')
Package exports a default function; named import will not work.
QueueMixin (CommonJS)
const QueueMixin = require('moleculer-rabbitmq')
const QueueMixin = require('moleculer-rabbitmq').default
CommonJS require returns the function directly, not an object with default property.
Mixin configuration
const mixin = QueueMixin({ connection: 'amqp://localhost', asyncActions: true })
const mixin = QueueMixin.config({ connection: 'amqp://localhost' })
The mixin is created by calling the exported function with options object.

Demonstrates setting up a Moleculer service with RabbitMQ queue mixin, defining a queued action, and calling its async version via broker.call.

const QueueMixin = require('moleculer-rabbitmq'); const { ServiceBroker } = require('moleculer'); const broker = new ServiceBroker(); const queueMixin = QueueMixin({ connection: 'amqp://localhost', asyncActions: true, }); broker.createService({ name: 'worker', mixins: [queueMixin], actions: { process: { queue: { amqp: { queueAssert: { durable: true }, consume: { noAck: false }, prefetch: 1, }, retry: true, }, async handler(ctx) { this.logger.info(`Processing: ${ctx.params.data}`); return `OK: ${ctx.params.data}`; }, }, }, }); broker.start().then(() => { setInterval(async () => { const res = await broker.call('worker.process.async', { params: { data: 'test' }, options: { timeout: 5000 }, }); console.log('Async result:', res); }, 3000); });
Debug
Known issues
breakingMoleculer major version updates (e.g., 0.14 vs 0.15) may break compatibility; peer dep allows ^0.12 || ^0.13 || ^0.14 only.
fix
Ensure Moleculer version is within the peer dependency range. Use 'npm ls moleculer' to check.
affects: >=1.0.0
gotchaThe async action is generated only if 'asyncActions: true' is set in mixin options AND the action has 'queue' configuration.
fix
Ensure both conditions are met; otherwise, the .async suffix action will not be available and will throw 'Service not found'.
affects: *
gotchaWhen using retry: true with RabbitMQ requeue, messages will be requeued indefinitely; there is no max_retry configuration.
fix
Use rabbitmq-delayed-message-exchange plugin with retryExchangeAssert options for controlled retries.
affects: *
deprecatedThe 'retry' option using RabbitMQ default requeue is simple but can cause infinite loops; the delayed-message approach is recommended for production.
fix
Switch to retryExchangeAssert configuration requiring the delayed message exchange plugin.
affects: *
Errors
Common errors & fixes
Service 'worker.process.async' is not found.
Async action is not auto-generated because asyncActions is false or action lacks 'queue' property.
fix
Set asyncActions: true in mixin options and add queue: {} to action definition.
TypeError: QueueMixin is not a function
Using named import like 'const { QueueMixin } = require(...)' instead of default import.
fix
Use 'import QueueMixin from ...' (ESM) or 'const QueueMixin = require(...)' (CJS).
Channel closed by server: 406 PRECONDITION_FAILED - inequivalent arg 'durable' for queue '...'
Queue declaration with mismatched attributes (e.g., durable true vs false) compared to existing queue.
fix
Delete the existing queue or match the attributes exactly.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
moleculerrequiredPeer dependency; requires Moleculer microservices framework
amqplibrequiredUnderlying RabbitMQ AMQP client
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
moleculer-rabbitmq — npm install moleculer-rabbitmq · libregistry