{"_id":"@appinventiv/rabbit-mq","_rev":"8-f49ed5a4214c645c87159357bc6cccf0","name":"@appinventiv/rabbit-mq","dist-tags":{"latest":"1.0.6"},"versions":{"1.0.0":{"name":"@appinventiv/rabbit-mq","version":"1.0.0","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/rabbit-mq@1.0.0","maintainers":[{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"4f3678ccbf2c25e251c431c3537e35167021106b","tarball":"https://registry.npmjs.org/@appinventiv/rabbit-mq/-/rabbit-mq-1.0.0.tgz","fileCount":32,"integrity":"sha512-jCclTmkBsOxh1FZ8dUKRxB7Q4xQgn1CJxXUFgUQRueSbA6uKGZOoM1dpKJBXP1QN6UjcihwaKoFUnzEP9tLG2g==","signatures":[{"sig":"MEUCIEVGotzLuq4JsgjUCnPlKxvtBT3/JodBvvIJfhNU2VlbAiEAmGkqmakJAWfXrvHsFm2ZQxw8QdlO00TKOKjcATX5bv8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":124679},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"A comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"amqplib":"^0.10.9"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9","@types/amqplib":"^0.10.8"},"_npmOperationalInternal":{"tmp":"tmp/rabbit-mq_1.0.0_1769313916742_0.9606039621397326","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@appinventiv/rabbit-mq","version":"1.0.2","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/rabbit-mq@1.0.2","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"60be0ae1f83093c14079462c3f36e9b50b30ddf4","tarball":"https://registry.npmjs.org/@appinventiv/rabbit-mq/-/rabbit-mq-1.0.2.tgz","fileCount":32,"integrity":"sha512-GD+uBu+JHbeJ8+/ZX2ivdu375eBMSI9pNzjiddDUT7q0oE/9yhZtPCL1529L9Q6xbpepLHijhHLYjVeQllu4uA==","signatures":[{"sig":"MEQCIGpqjfOXhYX4yN7b4t8HKxlrWTEg3CRO6268gi6Cf5A/AiAcIPzfc7JCOADQf1cHYZfMz901SECGcIo7KC5GYE8AmQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":124679},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"A comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"amqplib":"^0.10.9"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9","@types/amqplib":"^0.10.8"},"_npmOperationalInternal":{"tmp":"tmp/rabbit-mq_1.0.2_1779273496692_0.4492011041062265","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@appinventiv/rabbit-mq","version":"1.0.4","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/rabbit-mq@1.0.4","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"06a599ab9ca4eb4c4009e84fb8121299b4b71963","tarball":"https://registry.npmjs.org/@appinventiv/rabbit-mq/-/rabbit-mq-1.0.4.tgz","fileCount":36,"integrity":"sha512-tQzWhARW3s9CJ2ByH4m2E5mzSfKg3TIPYo7oX763JPPu+PRz3gmeF5F1SSqosx5hbK/tMFIR7pVv9Spoot+1vA==","signatures":[{"sig":"MEYCIQCc8J//oyvwKZAi//v/YAnyNAEHyhDnzl9Ykns6D2xlYQIhAOJ+/EPx+f6ersOAbRbuk/mvVStFX5AwwbCDon7rd3gR","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":144935},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"A comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"amqplib":"^0.10.9"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9","@types/amqplib":"^0.10.8"},"_npmOperationalInternal":{"tmp":"tmp/rabbit-mq_1.0.4_1779276397296_0.4535109114872775","host":"s3://npm-registry-packages-npm-production"}},"1.0.5":{"name":"@appinventiv/rabbit-mq","version":"1.0.5","keywords":[],"author":"","license":"ISC","_id":"@appinventiv/rabbit-mq@1.0.5","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"dist":{"shasum":"705445a839def3dc736457df2a9219975a4061d3","tarball":"https://registry.npmjs.org/@appinventiv/rabbit-mq/-/rabbit-mq-1.0.5.tgz","fileCount":36,"integrity":"sha512-Y+l5xgCnx7pDmQ+wuAB32U6Vz8gxESMo+xKDAtP0igbbuJel1AYjinpTVQNUS9F0AxxBwjsNYnZtUTvkz0umHg==","signatures":[{"sig":"MEUCIQChpG+NdFgHKK6TpZOHjmX9BZufOa1hbLnK2XIi2txr1wIgF+Ne1+OfkMBrQH2lCSZD/UidbkwQbsqW0WwmGpe5nK0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":147114},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc"},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"_npmVersion":"10.9.3","description":"A comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"amqplib":"^0.10.9"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.3","@types/node":"^25.0.9","@types/amqplib":"^0.10.8"},"_npmOperationalInternal":{"tmp":"tmp/rabbit-mq_1.0.5_1779527903438_0.8808911432392132","host":"s3://npm-registry-packages-npm-production"}},"1.0.6":{"name":"@appinventiv/rabbit-mq","version":"1.0.6","description":"A comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"echo \"Error: no test specified\" && exit 1"},"keywords":[],"author":"","license":"ISC","dependencies":{"amqplib":"^0.10.9"},"devDependencies":{"@types/amqplib":"^0.10.8","@types/node":"^25.0.9","typescript":"^5.9.3"},"_id":"@appinventiv/rabbit-mq@1.0.6","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-FauJztlGVVQioCZJxGFKJk9qJ6LqLhxY24Kpv62YLkM0beo6bOx50A0ENqdXdTIuvuhxJoXTnvIylbs8ohRcZQ==","shasum":"70ef6d4af3f301823a5d721959705fac518e1869","tarball":"https://registry.npmjs.org/@appinventiv/rabbit-mq/-/rabbit-mq-1.0.6.tgz","fileCount":36,"unpackedSize":147110,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDdZOrp3cwGZHfkW8iNONqldvlwQVdPW0skadY7JX1UsAIhAM9FfWXayQu76AjPzIpim3fjM9YmY2e5H1F0WxkN+QFg"}]},"_npmUser":{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"},"directories":{},"maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rabbit-mq_1.0.6_1779528568828_0.8000483352003931"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-25T04:05:16.617Z","modified":"2026-05-23T09:29:29.113Z","1.0.0":"2026-01-25T04:05:16.898Z","1.0.1":"2026-05-20T10:14:28.671Z","1.0.2":"2026-05-20T10:38:16.832Z","1.0.4":"2026-05-20T11:26:37.448Z","1.0.5":"2026-05-23T09:18:23.575Z","1.0.6":"2026-05-23T09:29:28.965Z"},"license":"ISC","keywords":[],"description":"A comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.","maintainers":[{"name":"developer-at","email":"abhishektyagi199816@gmail.com"},{"name":"abhishek.tyagi1","email":"abhishek.tyagi1@appinventiv.com"}],"readme":"# @developer-at/rabbit-mq\n\nA comprehensive RabbitMQ client package for Node.js applications. Provides easy-to-use producer and consumer services with connection management, queue/exchange handling, and automatic reconnection.\n\n## Installation\n\n```bash\nnpm install @developer-at/rabbit-mq\n```\n\n## Features\n\n- Producer service for publishing messages\n- Consumer service for consuming messages\n- Default `rabbitMQ` singleton with optional custom `RabbitMQManager` instances\n- Automatic connection management\n- Queue and exchange creation\n- Message acknowledgment handling\n- Prefetch count configuration\n- TypeScript support\n\n## Prerequisites\n\n- RabbitMQ server running and accessible\n- Connection URL (e.g., `amqp://localhost:5672`)\n\n## Usage\n\n### Basic Setup\n\nConfigure RabbitMQ **once** at startup. All producers and consumers use this config automatically.\n\n```typescript\nimport { rabbitMQ, producer, consumer } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({\n  url: 'amqp://localhost:5672',\n  connectionOptions: {\n    // Optional connection options\n  }\n});\n\nawait producer.produce('my-queue', { event: 'created' });\n\nawait consumer.consume({\n  queue: 'my-queue',\n  onMessage: async (message) => {\n    console.log('Received:', message);\n  }\n});\n```\n\nFor queue/exchange setup with a dedicated manager instance:\n\n```typescript\nimport { rabbitMQ } from '@developer-at/rabbit-mq';\n\nawait rabbitMQ.connect();\nawait rabbitMQ.createQueue({ name: 'user-events', durable: true });\n```\n\n### Alternate broker (optional)\n\nPass a custom `RabbitMQManager` when you need a different URL:\n\n```typescript\nimport { rabbitMQ, producer } from '@developer-at/rabbit-mq';\n\nconst analyticsMq = new RabbitMQManager();\nanalyticsMq.setConfig({ url: process.env.ANALYTICS_RABBIT_URL! });\n\nawait producer.produce('events', { id: 1 }, undefined, undefined, analyticsMq);\n```\n\nOr pass `rabbitMq` on consumer options: `consumer.consume({ queue: 'events', onMessage, rabbitMq: analyticsMq })`.\n\n### Shutdown\n\n`producer.disconnectAll()` and `consumer.disconnectConsumers()` do **not** close the default `rabbitMQ` connection. On app shutdown:\n\n```typescript\nawait producer.disconnectAll();\nawait consumer.disconnectConsumers();\nawait rabbitMQ.disconnect();\n```\n\n### Queue and Exchange Management\n\n#### Creating Queues\n\nUse the `createQueue` method from `RabbitMQManager` to create queues before using them:\n\n```typescript\nimport { rabbitMQ } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create a durable queue (survives broker restart)\nawait rabbitMQ.createQueue({\n  name: 'user-events',\n  durable: true,        // Queue persists after broker restart\n  exclusive: false,     // Queue can be accessed by multiple connections\n  autoDelete: false     // Queue is not deleted when unused\n});\n\n// Create a temporary queue (deleted when connection closes)\nawait rabbitMQ.createQueue({\n  name: 'temp-queue',\n  durable: false,\n  exclusive: true,      // Queue is exclusive to this connection\n  autoDelete: true      // Queue is deleted when unused\n});\n```\n\n#### Creating Exchanges\n\nUse the `createExchange` method to create exchanges for message routing:\n\n```typescript\nimport { rabbitMQ } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create a direct exchange (routes messages based on exact routing key match)\nawait rabbitMQ.createExchange({\n  name: 'user-exchange',\n  type: 'direct',       // Options: 'direct', 'topic', 'fanout', 'headers'\n  durable: true,         // Exchange persists after broker restart\n  autoDelete: false      // Exchange is not deleted when unused\n});\n\n// Create a topic exchange (routes messages based on pattern matching)\nawait rabbitMQ.createExchange({\n  name: 'notifications',\n  type: 'topic',\n  durable: true\n});\n\n// Create a fanout exchange (broadcasts to all bound queues)\nawait rabbitMQ.createExchange({\n  name: 'broadcast',\n  type: 'fanout',\n  durable: true\n});\n```\n\n#### Binding Queues to Exchanges\n\nUse `bindQueue` to connect queues to exchanges with routing keys. The routing key determines which messages from the exchange are delivered to the queue:\n\n```typescript\nimport { rabbitMQ } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create exchange and queue first\nawait rabbitMQ.createExchange({\n  name: 'user-exchange',\n  type: 'direct',\n  durable: true\n});\n\nawait rabbitMQ.createQueue({\n  name: 'user-created-queue',\n  durable: true\n});\n\n// Bind queue to exchange with routing key\n// Messages published to 'user-exchange' with routing key 'user.created' \n// will be routed to 'user-created-queue'\nawait rabbitMQ.bindQueue('user-created-queue', 'user-exchange', 'user.created');\n\n// You can bind the same queue to multiple routing keys\nawait rabbitMQ.bindQueue('user-created-queue', 'user-exchange', 'user.updated');\n\n// For fanout exchanges, routing key is ignored (all messages go to all bound queues)\nawait rabbitMQ.createExchange({ name: 'broadcast', type: 'fanout', durable: true });\nawait rabbitMQ.bindQueue('queue1', 'broadcast', ''); // routing key ignored for fanout\nawait rabbitMQ.bindQueue('queue2', 'broadcast', ''); // routing key ignored for fanout\n```\n\n**How Routing Works:**\n\n- **Direct Exchange**: Routes messages where routing key exactly matches the binding key\n\n  - Example: Binding key `'user.created'` receives messages with routing key `'user.created'` only\n- **Topic Exchange**: Routes messages using pattern matching (wildcards: `*` for single word, `#` for multiple words)\n\n  - Example: Binding key `'user.*'` receives `'user.created'`, `'user.updated'`, etc.\n  - Example: Binding key `'user.#'` receives `'user.created'`, `'user.profile.updated'`, etc.\n- **Fanout Exchange**: Routes all messages to all bound queues (routing key is ignored)\n- **Headers Exchange**: Routes based on message headers (not routing key)\n\n### Producer Usage\n\n#### Simple Queue Producer (Without Exchange)\n\nWhen you don't specify an exchange, messages are sent directly to the queue:\n\n```typescript\nimport { rabbitMQ, producer } from '@developer-at/rabbit-mq';\n\n// Setup connection\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create queue first (optional, but recommended)\nawait rabbitMQ.createQueue({\n  name: 'user-events',\n  durable: true\n});\n\n// Publish message directly to queue (no exchange, no routing key)\nawait producer.produce('user-events', {\n  userId: '123',\n  action: 'user.created',\n  data: { name: 'John Doe', email: 'john@example.com' }\n});\n```\n\n#### Producer with Exchange and Routing Key\n\nWhen using an exchange, you must specify both the exchange name and routing key. The routing key determines which bound queues receive the message:\n\n```typescript\nimport { rabbitMQ, producer } from '@developer-at/rabbit-mq';\n\n// Setup connection\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create exchange\nawait rabbitMQ.createExchange({\n  name: 'user-exchange',\n  type: 'direct',\n  durable: true\n});\n\n// Create queues\nawait rabbitMQ.createQueue({ name: 'user-created-queue', durable: true });\nawait rabbitMQ.createQueue({ name: 'user-updated-queue', durable: true });\n\n// Bind queues to exchange with different routing keys\nawait rabbitMQ.bindQueue('user-created-queue', 'user-exchange', 'user.created');\nawait rabbitMQ.bindQueue('user-updated-queue', 'user-exchange', 'user.updated');\n\n// Publish message to exchange with routing key 'user.created'\n// This message will be routed to 'user-created-queue' only\nawait producer.produce(\n  'user-created-queue',  // Queue name (used for binding reference)\n  { userId: '123', action: 'created', name: 'John Doe' },\n  'user-exchange',       // Exchange name\n  'user.created'         // Routing key - determines which queue receives the message\n);\n\n// Publish message with routing key 'user.updated'\n// This message will be routed to 'user-updated-queue' only\nawait producer.produce(\n  'user-updated-queue',\n  { userId: '123', action: 'updated', email: 'newemail@example.com' },\n  'user-exchange',\n  'user.updated'\n);\n```\n\n#### Topic Exchange Example with Pattern Matching\n\n```typescript\nimport { rabbitMQ, producer } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create topic exchange\nawait rabbitMQ.createExchange({\n  name: 'notifications',\n  type: 'topic',\n  durable: true\n});\n\n// Create queues\nawait rabbitMQ.createQueue({ name: 'email-queue', durable: true });\nawait rabbitMQ.createQueue({ name: 'sms-queue', durable: true });\nawait rabbitMQ.createQueue({ name: 'all-notifications-queue', durable: true });\n\n// Bind with pattern matching\nawait rabbitMQ.bindQueue('email-queue', 'notifications', 'notification.email.*');\nawait rabbitMQ.bindQueue('sms-queue', 'notifications', 'notification.sms.*');\nawait rabbitMQ.bindQueue('all-notifications-queue', 'notifications', 'notification.#');\n\n// Publish to 'notification.email.user' - goes to email-queue and all-notifications-queue\nawait producer.produce(\n  'email-queue',\n  { type: 'email', to: 'user@example.com', subject: 'Welcome' },\n  'notifications',\n  'notification.email.user'\n);\n\n// Publish to 'notification.sms.user' - goes to sms-queue and all-notifications-queue\nawait producer.produce(\n  'sms-queue',\n  { type: 'sms', to: '+1234567890', message: 'Hello' },\n  'notifications',\n  'notification.sms.user'\n);\n```\n\n#### Fanout Exchange Example (Broadcast)\n\n```typescript\nimport { rabbitMQ, producer } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create fanout exchange\nawait rabbitMQ.createExchange({\n  name: 'broadcast',\n  type: 'fanout',\n  durable: true\n});\n\n// Create multiple queues\nawait rabbitMQ.createQueue({ name: 'queue1', durable: true });\nawait rabbitMQ.createQueue({ name: 'queue2', durable: true });\nawait rabbitMQ.createQueue({ name: 'queue3', durable: true });\n\n// Bind all queues to fanout exchange (routing key is ignored)\nawait rabbitMQ.bindQueue('queue1', 'broadcast', '');\nawait rabbitMQ.bindQueue('queue2', 'broadcast', '');\nawait rabbitMQ.bindQueue('queue3', 'broadcast', '');\n\n// Publish message - ALL queues receive it (routing key is ignored for fanout)\nawait producer.produce(\n  'queue1',  // Any queue name works, all bound queues receive the message\n  { message: 'Broadcast to all queues' },\n  'broadcast',\n  ''  // Routing key is ignored for fanout exchanges\n);\n```\n\n### Consumer Usage\n\n#### Basic Consumer (Without Exchange)\n\nWhen consuming from a queue without an exchange, messages are consumed directly from the queue:\n\n```typescript\nimport { rabbitMQ, consumer } from '@developer-at/rabbit-mq';\n\n// Setup connection\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create queue first (optional, but recommended)\nawait rabbitMQ.createQueue({\n  name: 'user-events',\n  durable: true\n});\n\n// Start consuming messages directly from queue\n// No exchange or routing key needed\nawait consumer.consume({\n  queue: 'user-events',\n  onMessage: async (message) => {\n    console.log('Received message:', message);\n  \n    // Process the message\n    await processMessage(message);\n  \n    // Message is automatically acknowledged on success\n    // Automatically nacked on error (not requeued)\n  }\n});\n```\n\n#### Consumer with Exchange and Routing Key\n\nWhen consuming from an exchange-based setup, you need to specify the exchange and routing key that the queue is bound to:\n\n```typescript\nimport { rabbitMQ, consumer } from '@developer-at/rabbit-mq';\n\n// Setup connection\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create exchange\nawait rabbitMQ.createExchange({\n  name: 'user-exchange',\n  type: 'direct',\n  durable: true\n});\n\n// Create queue\nawait rabbitMQ.createQueue({\n  name: 'user-created-queue',\n  durable: true\n});\n\n// Bind queue to exchange with routing key\nawait rabbitMQ.bindQueue('user-created-queue', 'user-exchange', 'user.created');\n\n// Consume from queue that's bound to exchange\n// You must specify the exchange and routing key that the queue is bound to\nawait consumer.consume({\n  queue: 'user-created-queue',\n  exchange: 'user-exchange',      // Exchange name the queue is bound to\n  routingKey: 'user.created',      // Routing key used in the binding\n  prefetchCount: 10,               // Process up to 10 messages at a time\n  durable: true,\n  onMessage: async (message) => {\n    console.log('Received user created event:', message);\n    await handleUserCreated(message);\n  }\n});\n```\n\n#### Multiple Consumers with Different Routing Keys\n\n```typescript\nimport { rabbitMQ, consumer } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Setup exchange\nawait rabbitMQ.createExchange({\n  name: 'user-exchange',\n  type: 'direct',\n  durable: true\n});\n\n// Create queues for different events\nawait rabbitMQ.createQueue({ name: 'user-created-queue', durable: true });\nawait rabbitMQ.createQueue({ name: 'user-updated-queue', durable: true });\nawait rabbitMQ.createQueue({ name: 'user-deleted-queue', durable: true });\n\n// Bind queues with different routing keys\nawait rabbitMQ.bindQueue('user-created-queue', 'user-exchange', 'user.created');\nawait rabbitMQ.bindQueue('user-updated-queue', 'user-exchange', 'user.updated');\nawait rabbitMQ.bindQueue('user-deleted-queue', 'user-exchange', 'user.deleted');\n\n// Consumer for user.created events\nawait consumer.consume({\n  queue: 'user-created-queue',\n  exchange: 'user-exchange',\n  routingKey: 'user.created',\n  onMessage: async (message) => {\n    console.log('User created:', message);\n  }\n});\n\n// Consumer for user.updated events\nawait consumer.consume({\n  queue: 'user-updated-queue',\n  exchange: 'user-exchange',\n  routingKey: 'user.updated',\n  onMessage: async (message) => {\n    console.log('User updated:', message);\n  }\n});\n\n// Consumer for user.deleted events\nawait consumer.consume({\n  queue: 'user-deleted-queue',\n  exchange: 'user-exchange',\n  routingKey: 'user.deleted',\n  onMessage: async (message) => {\n    console.log('User deleted:', message);\n  }\n});\n```\n\n#### Topic Exchange Consumer with Pattern Matching\n\n```typescript\nimport { rabbitMQ, consumer } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\nawait rabbitMQ.connect();\n\n// Create topic exchange\nawait rabbitMQ.createExchange({\n  name: 'notifications',\n  type: 'topic',\n  durable: true\n});\n\n// Create queue for email notifications\nawait rabbitMQ.createQueue({ name: 'email-notifications', durable: true });\n\n// Bind with pattern - receives all email.* notifications\nawait rabbitMQ.bindQueue('email-notifications', 'notifications', 'notification.email.*');\n\n// Consumer receives messages matching the pattern\nawait consumer.consume({\n  queue: 'email-notifications',\n  exchange: 'notifications',\n  routingKey: 'notification.email.*',  // Pattern used in binding\n  onMessage: async (message) => {\n    console.log('Email notification:', message);\n    // Receives: notification.email.user, notification.email.admin, etc.\n  }\n});\n```\n\n### Complete Examples\n\n#### Example 1: Simple Queue (No Exchange)\n\n```typescript\nimport { rabbitMQ, producer, consumer } from '@developer-at/rabbit-mq';\n\nasync function setupSimpleQueue() {\n  rabbitMQ.setConfig({\n    url: process.env.RABBITMQ_URL || 'amqp://localhost:5672'\n  });\n\n  await rabbitMQ.connect();\n  \n  // Create queue\n  await rabbitMQ.createQueue({\n    name: 'user-events',\n    durable: true\n  });\n  \n  // Producer - send directly to queue (no exchange, no routing key)\n  await producer.produce('user-events', {\n    type: 'user.created',\n    userId: '123',\n    name: 'John Doe'\n  });\n  \n  // Consumer - consume directly from queue (no exchange, no routing key)\n  await consumer.consume({\n    queue: 'user-events',\n    prefetchCount: 5,\n    onMessage: async (message) => {\n      try {\n        console.log('Processing:', message);\n        await processUserEvent(message);\n      } catch (error) {\n        console.error('Error processing message:', error);\n      }\n    }\n  });\n}\n```\n\n#### Example 2: Exchange-Based with Routing Keys\n\n```typescript\nimport { rabbitMQ, producer, consumer } from '@developer-at/rabbit-mq';\n\nasync function setupExchangeBased() {\n  rabbitMQ.setConfig({\n    url: process.env.RABBITMQ_URL || 'amqp://localhost:5672'\n  });\n\n  await rabbitMQ.connect();\n  \n  // Create exchange\n  await rabbitMQ.createExchange({\n    name: 'user-exchange',\n    type: 'direct',\n    durable: true\n  });\n  \n  // Create queues\n  await rabbitMQ.createQueue({ name: 'user-created-queue', durable: true });\n  await rabbitMQ.createQueue({ name: 'user-updated-queue', durable: true });\n  \n  // Bind queues to exchange with routing keys\n  await rabbitMQ.bindQueue('user-created-queue', 'user-exchange', 'user.created');\n  await rabbitMQ.bindQueue('user-updated-queue', 'user-exchange', 'user.updated');\n  \n  // Producer - publish to exchange with routing key\n  await producer.produce(\n    'user-created-queue',\n    { userId: '123', action: 'created', name: 'John Doe' },\n    'user-exchange',    // Exchange name\n    'user.created'      // Routing key - routes to user-created-queue\n  );\n  \n  // Consumer - consume from queue bound to exchange\n  await consumer.consume({\n    queue: 'user-created-queue',\n    exchange: 'user-exchange',      // Exchange name\n    routingKey: 'user.created',      // Routing key used in binding\n    prefetchCount: 5,\n    onMessage: async (message) => {\n      try {\n        console.log('User created event:', message);\n        await handleUserCreated(message);\n      } catch (error) {\n        console.error('Error processing message:', error);\n      }\n    }\n  });\n}\n\n// Graceful shutdown\nprocess.on('SIGTERM', async () => {\n  await producer.disconnectAll();\n  await consumer.disconnectConsumers();\n  await rabbitMQ.disconnect();\n  process.exit(0);\n});\n```\n\n## API Reference\n\n### `rabbitMQ` (singleton)\n\nDefault shared `RabbitMQManager` instance. Configure once:\n\n```typescript\nimport { rabbitMQ } from '@developer-at/rabbit-mq';\n\nrabbitMQ.setConfig({ url: 'amqp://localhost:5672' });\n```\n\nProducer and consumer services use `rabbitMQ` unless you pass another manager.\n\n### RabbitMQManager\n\nConnection and channel management. Use `new RabbitMQManager()` for additional brokers.\n\n#### `setConfig(config: IRabbitMQConfig)`\n\nSets connection configuration on **this** instance.\n\n**Parameters:**\n\n- `config.url` (string): RabbitMQ connection URL\n- `config.connectionOptions` (any, optional): Additional connection options\n\n#### `isConfigured(): boolean`\n\nReturns whether `setConfig` has been called on this instance.\n\n#### `getUrl(): string | undefined`\n\nReturns the configured URL (useful for debugging).\n\n#### `connect()`\n\nEstablishes connection to RabbitMQ.\n\n#### `disconnect()`\n\nCloses the RabbitMQ connection.\n\n#### `createQueue(queueConfig: IQueueConfig)`\n\nCreates a queue if it doesn't exist. This method should be called after connecting to RabbitMQ.\n\n**Parameters:**\n\n- `queueConfig.name` (string): Queue name\n- `queueConfig.durable` (boolean, optional): Queue survives broker restart (default: true)\n- `queueConfig.exclusive` (boolean, optional): Queue is exclusive to connection (default: false)\n- `queueConfig.autoDelete` (boolean, optional): Queue is deleted when unused (default: false)\n- `queueConfig.arguments` (any, optional): Additional queue arguments\n\n**Example:**\n\n```typescript\nawait rabbitMQ.createQueue({\n  name: 'my-queue',\n  durable: true,\n  exclusive: false,\n  autoDelete: false\n});\n```\n\n#### `createExchange(exchangeConfig: IExchangeConfig)`\n\nCreates an exchange if it doesn't exist. This method should be called after connecting to RabbitMQ.\n\n**Parameters:**\n\n- `exchangeConfig.name` (string): Exchange name\n- `exchangeConfig.type` ('direct' | 'topic' | 'fanout' | 'headers'): Exchange type\n  - `direct`: Routes messages where routing key exactly matches binding key\n  - `topic`: Routes messages using pattern matching (wildcards: `*`, `#`)\n  - `fanout`: Broadcasts all messages to all bound queues (routing key ignored)\n  - `headers`: Routes based on message headers\n- `exchangeConfig.durable` (boolean, optional): Exchange survives broker restart (default: true)\n- `exchangeConfig.autoDelete` (boolean, optional): Exchange is deleted when unused (default: false)\n- `exchangeConfig.arguments` (any, optional): Additional exchange arguments\n\n**Example:**\n\n```typescript\nawait rabbitMQ.createExchange({\n  name: 'my-exchange',\n  type: 'direct',\n  durable: true\n});\n```\n\n#### `bindQueue(queueName: string, exchangeName: string, routingKey?: string)`\n\nBinds a queue to an exchange with an optional routing key. The routing key determines which messages from the exchange are delivered to the queue.\n\n**Parameters:**\n\n- `queueName` (string): Name of the queue to bind\n- `exchangeName` (string): Name of the exchange to bind to\n- `routingKey` (string, optional): Routing key for message filtering (default: '')\n\n**How Routing Works:**\n\n- **Direct Exchange**: Routing key must exactly match the binding key\n- **Topic Exchange**: Routing key can use wildcards (`*` for single word, `#` for multiple words)\n- **Fanout Exchange**: Routing key is ignored, all messages go to all bound queues\n- **Headers Exchange**: Routing key is ignored, routing is based on message headers\n\n**Example:**\n\n```typescript\n// Direct exchange - exact match\nawait rabbitMQ.bindQueue('queue1', 'exchange1', 'user.created');\n\n// Topic exchange - pattern matching\nawait rabbitMQ.bindQueue('queue2', 'exchange2', 'user.*');  // Matches user.created, user.updated, etc.\nawait rabbitMQ.bindQueue('queue3', 'exchange2', 'user.#');  // Matches user.created, user.profile.updated, etc.\n\n// Fanout exchange - routing key ignored\nawait rabbitMQ.bindQueue('queue4', 'exchange3', '');  // All messages received\n```\n\n### Producer Service\n\n#### `produce(queue: string, message: any, exchange?: string, routingKey?: string)`\n\nPublishes a message to a queue or exchange.\n\n**Parameters:**\n\n- `queue` (string): Queue name (used as reference, actual routing depends on exchange/routing key)\n- `message` (any): Message payload (will be JSON stringified)\n- `exchange` (string, optional): Exchange name. If provided, message is published to exchange with routing key\n- `routingKey` (string, optional): Routing key for exchange. Required when using exchange\n\n**Usage Patterns:**\n\n1. **Direct Queue (No Exchange):**\n\n   ```typescript\n   // Message sent directly to queue\n   await producer.produce('my-queue', { data: 'value' });\n   ```\n2. **With Exchange and Routing Key:**\n\n   ```typescript\n   // Message published to exchange, routed to queues based on routing key\n   await producer.produce('my-queue', { data: 'value' }, 'my-exchange', 'routing.key');\n   ```\n\n**Important Notes:**\n\n- When using an exchange, the routing key determines which bound queues receive the message\n- The queue parameter is used as a reference but doesn't affect routing when using an exchange\n- For fanout exchanges, routing key is ignored and all bound queues receive the message\n\n#### `disconnectAll()`\n\nDisconnects all active producers.\n\n#### `getProducerCount(): number`\n\nReturns the number of active producers.\n\n#### `getProducerKeys(): string[]`\n\nReturns all producer keys.\n\n### Consumer Service\n\n#### `consume(options: IRabbitMQConsumerOptions)`\n\nStarts consuming messages from a queue. If the queue is bound to an exchange, you must specify the exchange and routing key that was used in the binding.\n\n**Parameters:**\n\n- `options.queue` (string): Queue name to consume from\n- `options.exchange` (string, optional): Exchange name the queue is bound to. Required if queue is bound to an exchange\n- `options.routingKey` (string, optional): Routing key used in the queue binding. Required if queue is bound to an exchange\n- `options.onMessage` (function): Async function to handle messages. Receives parsed message object\n- `options.prefetchCount` (number, optional): Number of unacknowledged messages to process concurrently (default: 1)\n- `options.durable` (boolean, optional): Queue durability (default: true)\n- `options.exclusive` (boolean, optional): Queue exclusivity (default: false)\n- `options.autoDelete` (boolean, optional): Auto-delete queue when unused (default: false)\n\n**Usage Patterns:**\n\n1. **Direct Queue (No Exchange):**\n\n   ```typescript\n   await consumer.consume({\n     queue: 'my-queue',\n     onMessage: async (message) => {\n       // Process message\n     }\n   });\n   ```\n2. **Queue Bound to Exchange:**\n\n   ```typescript\n   await consumer.consume({\n     queue: 'my-queue',\n     exchange: 'my-exchange',      // Must match the exchange used in binding\n     routingKey: 'routing.key',    // Must match the routing key used in binding\n     onMessage: async (message) => {\n       // Process message\n     }\n   });\n   ```\n\n**Important Notes:**\n\n- If a queue is bound to an exchange, you MUST specify both `exchange` and `routingKey` in the consume options\n- The `exchange` and `routingKey` must match the values used when binding the queue to the exchange\n- For queues not bound to an exchange, omit `exchange` and `routingKey` parameters\n\n#### `disconnectConsumers()`\n\nDisconnects all active consumers.\n\n#### `getConsumerCount(): number`\n\nReturns the number of active consumers.\n\n#### `getConsumerTags(): string[]`\n\nReturns all consumer tags.\n\n## Message Handling\n\n- Messages are automatically acknowledged on successful processing\n- Messages are automatically nacked (not requeued) on error\n- Use `prefetchCount` to control concurrency\n- Messages are JSON stringified when publishing and parsed when consuming\n\n## Error Handling\n\nThe package includes automatic error handling:\n\n- Connection errors are logged\n- Failed messages are nacked (not requeued)\n- Automatic reconnection on connection loss\n\n## TypeScript Support\n\nFull TypeScript definitions are included. Import interfaces for type safety:\n\n```typescript\nimport {\n  IRabbitMQConfig,\n  IRabbitMQConsumerOptions,\n  IRabbitMQProducerOptions,\n  IRabbitMQMessage\n} from '@developer-at/rabbit-mq';\n```\n\n## Dependencies\n\n- `amqplib`: ^0.10.9\n\n## License\n\nISC\n","readmeFilename":"README.md"}