{"_id":"easy-message-broker","_rev":"31-5ab9eb6e7ab780bd58f51296ffbb65f9","name":"easy-message-broker","dist-tags":{"latest":"1.2.0"},"versions":{"1.1.0":{"name":"easy-message-broker","version":"1.1.0","author":{"name":"Felipe","email":"fcalldas@gmail.com"},"license":"MIT","_id":"easy-message-broker@1.1.0","maintainers":[{"name":"felipecal","email":"fcalldas@gmail.com"}],"homepage":"https://github.com/felipecal/easy-message-broker#readme","bugs":{"url":"https://github.com/felipecal/easy-message-broker/issues"},"dist":{"shasum":"99b8d66cd3db0dcfc9b13331148261b850ea7203","tarball":"https://registry.npmjs.org/easy-message-broker/-/easy-message-broker-1.1.0.tgz","fileCount":12,"integrity":"sha512-exi9wIDBLR1GjRRZ+lyFvKkg3V6IIIGK/HJ7LdBAU9hY76mtyZ2JXCmHPx6dq3iJzvo1NShsZ0j9bShSrcw7yQ==","signatures":[{"sig":"MEUCIQCuqI9D4aqjj+BwOCg12+KCPp9rHa/UX12C7NCqGg/vCgIgFfXtnC5lA7fpWob1pa+HT4PDcFQUjBW2WeLRviO3/DM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":11060},"main":"dist/main_api.js","types":"./dist/main_api.d.ts","gitHead":"d8029dd47e9170c4bf6a8068e2f0f2aa99d63db9","scripts":{"build":"tsc"},"_npmUser":{"name":"felipecal","email":"fcalldas@gmail.com"},"repository":{"url":"git+https://github.com/felipecal/easy-message-broker.git","type":"git"},"_npmVersion":"8.19.4","description":"An easier way to use message broker.","directories":{},"_nodeVersion":"16.20.2","dependencies":{"amqplib":"^0.10.4","typescript":"^5.4.5"},"_hasShrinkwrap":false,"devDependencies":{"@types/amqplib":"^0.10.5"},"_npmOperationalInternal":{"tmp":"tmp/easy-message-broker_1.1.0_1716070433007_0.5972705745248388","host":"s3://npm-registry-packages"}},"1.2.0":{"name":"easy-message-broker","version":"1.2.0","description":"An easier way to use message broker.","repository":{"type":"git","url":"git+https://github.com/felipecal/easy-message-broker.git"},"main":"dist/main_api.js","author":{"name":"Felipe","email":"fcalldas@gmail.com"},"license":"MIT","scripts":{"build":"tsc"},"dependencies":{"amqplib":"^0.10.4","typescript":"^5.4.5"},"devDependencies":{"@types/amqplib":"^0.10.5"},"types":"./dist/main_api.d.ts","gitHead":"2e3c8c206945f0c0c251d5299637c351df95aef0","bugs":{"url":"https://github.com/felipecal/easy-message-broker/issues"},"homepage":"https://github.com/felipecal/easy-message-broker#readme","_id":"easy-message-broker@1.2.0","_nodeVersion":"16.20.2","_npmVersion":"8.19.4","dist":{"integrity":"sha512-RRz7KQjcMH2UooDYOQtmbb+59oMv/k02sc82ucmWYudsCnbALbvyWuB4TPHAZP0mmpSReprsCh5iFqGHmADExg==","shasum":"de6092a28afc5616c220a7f8500bc384cc171397","tarball":"https://registry.npmjs.org/easy-message-broker/-/easy-message-broker-1.2.0.tgz","fileCount":10,"unpackedSize":30412,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEMCIEsvO46JLG1izxTP428egRKWE/CrNluwIxOZaR8VetGkAh8G/XcKeFfGFg913bcLaDEZneJ0649E4iu2iW8YmEoy"}]},"_npmUser":{"name":"felipecal","email":"fcalldas@gmail.com"},"directories":{},"maintainers":[{"name":"felipecal","email":"fcalldas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/easy-message-broker_1.2.0_1744929643346_0.9305581547766422"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-18T22:13:53.006Z","modified":"2025-04-17T22:40:43.726Z","1.0.0":"2024-05-16T19:06:58.635Z","1.0.1":"2024-05-16T19:10:41.917Z","1.0.2":"2024-05-16T19:16:30.359Z","1.0.3":"2024-05-16T19:31:40.719Z","1.0.4":"2024-05-16T19:48:31.617Z","1.0.5":"2024-05-17T01:12:05.425Z","1.0.6":"2024-05-17T01:12:16.812Z","1.0.7":"2024-05-17T01:12:52.141Z","1.0.8":"2024-05-17T01:13:04.054Z","1.0.9":"2024-05-17T01:14:23.902Z","1.0.10":"2024-05-17T01:14:53.939Z","1.0.11":"2024-05-17T01:15:09.914Z","1.0.12":"2024-05-17T01:15:25.325Z","1.0.13":"2024-05-17T01:15:58.536Z","1.0.14":"2024-05-17T01:16:18.255Z","1.0.15":"2024-05-17T01:18:48.893Z","1.0.17":"2024-05-17T01:30:41.289Z","1.0.18":"2024-05-17T01:30:56.306Z","1.0.19":"2024-05-17T01:30:59.568Z","1.0.20":"2024-05-17T01:31:15.044Z","1.0.21":"2024-05-17T01:31:26.577Z","1.0.22":"2024-05-17T01:38:33.792Z","1.0.23":"2024-05-17T01:38:55.596Z","1.0.24":"2024-05-17T01:39:10.804Z","1.0.25":"2024-05-17T01:42:14.751Z","1.0.26":"2024-05-17T01:42:41.208Z","1.0.27":"2024-05-17T01:43:01.596Z","1.0.28":"2024-05-17T01:43:29.745Z","1.1.0":"2024-05-18T22:13:53.165Z","1.2.0":"2025-04-17T22:40:43.562Z"},"bugs":{"url":"https://github.com/felipecal/easy-message-broker/issues"},"author":{"name":"Felipe","email":"fcalldas@gmail.com"},"license":"MIT","homepage":"https://github.com/felipecal/easy-message-broker#readme","repository":{"type":"git","url":"git+https://github.com/felipecal/easy-message-broker.git"},"description":"An easier way to use message broker.","maintainers":[{"name":"felipecal","email":"fcalldas@gmail.com"}],"readme":"#  Easy Queue \n\n- The easy-message-broker library is an HTTP messaging solution designed to simplify and expedite the message exchange process, offering a straightforward and user-friendly approach for users. With the aim of making messaging integration an accessible and efficient task, the easy-message-broker library employs the AMQP (Advanced Message Queuing Protocol) protocol to provide a robust and reliable infrastructure.\n\n- Access the library in NPM: [Easy-Message-Broker](https://www.npmjs.com/package/easy-message-broker).\n\n## Installation\n\n- Install the lib:\n\n```bash\n  npm install easy-message-broker\n```\n\n## Usage\n\n- #### How to Import:\n\n```typescript\nimport { MessageBroker } from 'easy-message-broker';\n```\n\n- #### How to import and use:\n\n```typescript\n  const queue = new MessageBroker();\n```\n\n- #### Example creating queue, exchange, bind and publish message:\n\n```typescript\nasync function examplePublishMessage() {\n  const queue = new MessageBroker();\n\n  await queue.connect('localhost');\n  await queue.createQueue('testeQueue')\n  await queue.createExchange('testExchange');\n  await queue.bindQueueToExchange('testeQueue', 'testExchange');\n  await queue.publishMessage('testExchange', '', 'textMessage')\n}\n```\n\n\n- #### Example consuming queue:\n```typescript\nasync function exampleConsumeQueue() {\n  const queue = new MessageBroker();\n  await queue.connect('localhost');\n  await queue.consumeQueue('testeQueue', (message) => {\n    console.log('Received message:', message);\n  });\n}\n```\n\n## Advanced Features\n\n- #### Connection Options:\n\n```typescript\nimport { MessageBroker, ConnectionOptions } from 'easy-message-broker';\n\nconst connectionOptions: ConnectionOptions = {\n  username: 'guest',\n  password: 'guest',\n  heartbeat: 30,\n  vhost: '/',\n  tls: false,\n  timeout: 30000,\n  retry: {\n    maxAttempts: 5,\n    initialDelay: 1000\n  }\n};\n\nasync function connect() {\n  const broker = new MessageBroker();\n  await broker.connect('localhost', connectionOptions);\n  // ...\n}\n```\n\n- #### Queue Options:\n\n```typescript\nimport { MessageBroker, QueueOptions } from 'easy-message-broker';\n\nconst queueOptions: QueueOptions = {\n  durable: true,\n  exclusive: false,\n  autoDelete: false,\n  arguments: {\n    'x-message-ttl': 60000 // 60 seconds TTL\n  }\n};\n\nasync function createQueue() {\n  const broker = new MessageBroker();\n  await broker.connect('localhost');\n  await broker.createQueue('my-queue', queueOptions);\n}\n```\n\n- #### Exchange Options:\n\n```typescript\nimport { MessageBroker, ExchangeOptions } from 'easy-message-broker';\n\nconst exchangeOptions: ExchangeOptions = {\n  type: 'topic', // direct, fanout, topic, headers\n  durable: true,\n  autoDelete: false\n};\n\nasync function createExchange() {\n  const broker = new MessageBroker();\n  await broker.connect('localhost');\n  await broker.createExchange('my-exchange', exchangeOptions);\n}\n```\n\n- #### Publishing with Options:\n\n```typescript\nimport { MessageBroker, PublishOptions } from 'easy-message-broker';\n\nconst publishOptions: PublishOptions = {\n  contentType: 'application/json',\n  persistent: true,\n  expiration: '60000', // 60 seconds\n  headers: {\n    priority: 'high'\n  }\n};\n\nasync function publishMessage() {\n  const broker = new MessageBroker();\n  await broker.connect('localhost');\n  \n  const message = { id: 123, name: 'Test Message' };\n  \n  await broker.publishMessage('my-exchange', 'routing.key', message, publishOptions);\n}\n```\n\n- #### Request-Reply Pattern:\n\n```typescript\nasync function requestResponse() {\n  const broker = new MessageBroker();\n  await broker.connect('localhost');\n  \n  // Setup server to respond to requests\n  await broker.createExchange('request-exchange');\n  await broker.createQueue('request-queue');\n  await broker.bindQueueToExchange('request-queue', 'request-exchange', 'requests');\n  \n  // Consumer that processes requests and sends responses\n  await broker.consumeQueue('request-queue', async (message, originalMessage) => {\n    console.log('Received request:', message);\n    \n    // Process request and prepare response\n    const response = { result: 'Request processed successfully' };\n    \n    // Publish to the reply queue provided in the original message\n    await broker.publishMessage('', originalMessage.properties.replyTo, response, {\n      correlationId: originalMessage.properties.correlationId\n    });\n  });\n  \n  // Client making a request\n  const request = { action: 'doSomething' };\n  const response = await broker.request('request-exchange', 'requests', request, {\n    timeout: 5000 // 5 seconds\n  });\n  \n  console.log('Received response:', response);\n}\n```\n\n- #### Direct Queue Sending:\n\n```typescript\nasync function sendToQueue() {\n  const broker = new MessageBroker();\n  await broker.connect('localhost');\n  \n  await broker.createQueue('direct-queue');\n  \n  // Send message directly to queue without using exchange\n  await broker.sendToQueue('direct-queue', { data: 'Direct message' });\n}\n```\n\n- #### Error Handling and Closing Connections:\n\n```typescript\nasync function errorHandlingAndClose() {\n  const broker = new MessageBroker();\n  \n  try {\n    await broker.connect('localhost');\n    // Perform operations...\n  } catch (error) {\n    console.error('Error:', error);\n  } finally {\n    // Always close connection when done\n    await broker.close();\n  }\n}\n```\n\n## Best Practices\n\n1. **Always close connections**: Use `broker.close()` when done to release resources.\n2. **Use error handling**: Wrap operations in try/catch blocks.\n3. **Configure persistence**: For important messages, set `persistent: true` in publish options.\n4. **Use durable queues**: For queues that should survive server restarts, set `durable: true`.\n5. **Configure auto-reconnection**: Use retry options for automatic reconnection attempts.\n\n## Author\n\n- [@felipecal](https://www.github.com/felipecal)\n\n## License\n\n- [MIT](https://choosealicense.com/licenses/mit/)","readmeFilename":"README.MD"}