{"_id":"@alldebug/adonis-rabbit","_rev":"2-3eadf262ef6ea40736124e3db2b4ac6a","name":"@alldebug/adonis-rabbit","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.1":{"name":"@alldebug/adonis-rabbit","description":"AdonisJS RabbitMQ provider","version":"0.1.1","author":{"name":"Jota Júnior","email":"jjunior@protonmail.ch"},"types":"build/adonis-typings/index.d.ts","main":"build/providers/RabbitProvider.js","license":"MIT","scripts":{"build":"npm run copyfiles && tsc","copyfiles":"copyfiles \"templates/**/*.txt\" build","publish":"npm publish --access public","lint":"eslint . --ext=.ts --fix"},"devDependencies":{"@adonisjs/core":"^5.1.8","adonis-preset-ts":"^1.0.4","copyfiles":"^2.4.0","eslint":"^7.11.0","eslint-plugin-adonis":"^1.0.15","eslint-plugin-prettier":"^3.4.0","np":"^7.5.0","prettier":"^2.3.1","typescript":"^4.0.3"},"dependencies":{"@types/amqplib":"^0.5.14","amqplib":"^0.10.3","fast-safe-stringify":"^2.1.1"},"adonisjs":{"templates":{"config":{"src":"rabbit.txt","dest":"rabbit"}},"env":{"RABBITMQ_HOSTNAME":"localhost","RABBITMQ_USER":"","RABBITMQ_PASSWORD":"","RABBITMQ_PORT":"","RABIITMQ_PROTOCOL":"ampq://"},"types":"adonis-rabbit","providers":["adonis-rabbit"]},"np":{"message":"Releases v%s"},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"https://github.com/alldebug/adonis-rabbit.git"},"_id":"@alldebug/adonis-rabbit@0.1.1","dist":{"shasum":"199f8d3b322f3fc8c77ed2597aaeb36b7ad23e73","integrity":"sha512-3Xreeayy55d1pJvt4mqV4VE2tcJyQvPHPyh9FJdyQ1r1NyipCTY61fTB6p5DnLmaEhHXDS9XvVRB09NW53NNSQ==","tarball":"https://registry.npmjs.org/@alldebug/adonis-rabbit/-/adonis-rabbit-0.1.1.tgz","fileCount":43,"unpackedSize":32100,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDCN6j9SKEzGjBCFdvX9AaqOWBP2sx4/T4IgjGQu2/c0wIhALR+u86WzdvAHMzmYBudePBWCTyd4xOSF0+MkMEwzFlB"}]},"_npmUser":{"name":"alldebug","email":"alldebug@hotmail.com"},"directories":{},"maintainers":[{"name":"alldebug","email":"alldebug@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/adonis-rabbit_0.1.1_1692225850274_0.5712779645001698"},"_hasShrinkwrap":false},"0.1.2":{"name":"@alldebug/adonis-rabbit","description":"AdonisJS RabbitMQ provider","version":"0.1.2","author":{"name":"Jota Júnior","email":"jjunior@protonmail.ch"},"types":"build/adonis-typings/index.d.ts","main":"build/providers/RabbitProvider.js","license":"MIT","scripts":{"build":"npm run copyfiles && tsc","copyfiles":"copyfiles \"templates/**/*.txt\" build","publish":"npm publish --access public","lint":"eslint . --ext=.ts --fix"},"devDependencies":{"@adonisjs/core":"^5.1.8","adonis-preset-ts":"^1.0.4","copyfiles":"^2.4.0","eslint":"^7.11.0","eslint-plugin-adonis":"^1.0.15","eslint-plugin-prettier":"^3.4.0","np":"^7.5.0","prettier":"^2.3.1","typescript":"^4.0.3"},"dependencies":{"@types/amqplib":"^0.5.14","amqplib":"^0.10.3","fast-safe-stringify":"^2.1.1"},"adonisjs":{"templates":{"config":{"src":"rabbit.txt","dest":"rabbit"}},"env":{"RABBITMQ_HOSTNAME":"localhost","RABBITMQ_USER":"","RABBITMQ_PASSWORD":"","RABBITMQ_PORT":"","RABIITMQ_PROTOCOL":"ampq://"},"types":"@alldebug/adonis-rabbit","providers":["@alldebug/adonis-rabbit"]},"np":{"message":"Releases v%s"},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"https://github.com/alldebug/adonis-rabbit.git"},"_id":"@alldebug/adonis-rabbit@0.1.2","dist":{"shasum":"e65b402fb8c365799e92fdbe3bda173d8f42be1c","integrity":"sha512-vQH8PnZsHOGuTqCzjJY2Kg0Il8nQsnKZpJG4iqRHQbGb+24c98TQyOMG9tKZCJswEEuJahvcXZpkgsutDcxGEA==","tarball":"https://registry.npmjs.org/@alldebug/adonis-rabbit/-/adonis-rabbit-0.1.2.tgz","fileCount":43,"unpackedSize":32121,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQChYnzsoSliqzAn5fYA6JIzYskxRAr2wLDtOwr677uoWwIhAOer+ZftJOHAGVX5wi8ekdarX2IDc0IUf8j7vTM01/wz"}]},"_npmUser":{"name":"alldebug","email":"alldebug@hotmail.com"},"directories":{},"maintainers":[{"name":"alldebug","email":"alldebug@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/adonis-rabbit_0.1.2_1692226838540_0.13963336395283465"},"_hasShrinkwrap":false},"0.1.3":{"name":"@alldebug/adonis-rabbit","description":"AdonisJS RabbitMQ provider","version":"0.1.3","author":{"name":"Jota Júnior","email":"jjunior@protonmail.ch"},"types":"build/adonis-typings/index.d.ts","main":"build/providers/RabbitProvider.js","license":"MIT","scripts":{"build":"npm run copyfiles && tsc","copyfiles":"copyfiles \"templates/**/*.txt\" build","publish":"npm publish --access public","lint":"eslint . --ext=.ts --fix"},"devDependencies":{"@adonisjs/core":"^5.1.8","adonis-preset-ts":"^1.0.4","copyfiles":"^2.4.0","eslint":"^7.11.0","eslint-plugin-adonis":"^1.0.15","eslint-plugin-prettier":"^3.4.0","np":"^7.5.0","prettier":"^2.3.1","typescript":"^4.0.3"},"dependencies":{"@types/amqplib":"^0.5.14","amqplib":"^0.10.3","fast-safe-stringify":"^2.1.1"},"adonisjs":{"templates":{"config":{"src":"rabbit.txt","dest":"rabbit"}},"env":{"RABBITMQ_HOSTNAME":"localhost","RABBITMQ_USER":"","RABBITMQ_PASSWORD":"","RABBITMQ_PORT":"","RABIITMQ_PROTOCOL":"ampq://"},"types":"@alldebug/adonis-rabbit","providers":["@alldebug/adonis-rabbit"]},"np":{"message":"Releases v%s"},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"https://github.com/alldebug/adonis-rabbit.git"},"_id":"@alldebug/adonis-rabbit@0.1.3","dist":{"shasum":"ee7742ecc4b192a6461980355344042e755df681","integrity":"sha512-ALRnemEozNXQ37AF8mGAS748UCABVizXHkqGM3YkwnGG3VgJ/cZUrIrERSwEJb96vX53q9IxLzIzybIQ37cjvg==","tarball":"https://registry.npmjs.org/@alldebug/adonis-rabbit/-/adonis-rabbit-0.1.3.tgz","fileCount":43,"unpackedSize":32168,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCw5+jXyKNYiBhLklh9xeCObFFlnabt2clbFj90aejvLQIhANh/HiuMZ8bZVnzE2sb9ScoPQ7qg054XRZRXdALryNr9"}]},"_npmUser":{"name":"alldebug","email":"alldebug@hotmail.com"},"directories":{},"maintainers":[{"name":"alldebug","email":"alldebug@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/adonis-rabbit_0.1.3_1692227399915_0.22115373633598367"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-16T22:44:10.187Z","0.1.1":"2023-08-16T22:44:10.586Z","modified":"2023-08-16T23:10:00.299Z","0.1.2":"2023-08-16T23:00:38.861Z","0.1.3":"2023-08-16T23:10:00.099Z"},"maintainers":[{"name":"alldebug","email":"alldebug@hotmail.com"}],"description":"AdonisJS RabbitMQ provider","repository":{"type":"git","url":"https://github.com/alldebug/adonis-rabbit.git"},"author":{"name":"Jota Júnior","email":"jjunior@protonmail.ch"},"license":"MIT","readme":"# adonis-rabbit\n\n> RabbitMQ provider Fork from [adonis-rabbit](https://www.npmjs.com/package/adonis-rabbit)\n\n`adonis-rabbit` is a RabbitMQ provider for [Adonis](https://github.com/adonisjs/core).\n\n## Getting Started\n\nInstal `adonis-rabbit`:\n\n```\nyarn add @alldebug/adonis-rabbit\n```\n\nThen:\n\n```\nnode ace invoke @alldebug/adonis-rabbit\n```\n\nThis will create `config/rabbit.ts` and add the following fields to your `.env`:\n\n```\nRABBITMQ_HOSTNAME=\nRABBITMQ_USER=\nRABBOTMQ_PASSWORD=\nRABBITMQ_PORT=\nRABBITMQ_PROTOCOL= \"amqp://\" //or ampqs \n```\n\nMake sure to set the correct values to the enviroment variables so `adonis-rabbit` can connect.\n\n## Basic Usage\n\n### Sending messages to an queue\n\n```ts\nimport Rabbit from '@ioc:Adonis/Addons/Rabbit'\nimport Route from '@ioc:Adonis/Core/Route'\n\nRoute.get('/', async () => {\n  // Ensures the queue exists\n  await Rabbit.assertQueue('my_queue')\n\n  // Sends a message to the queue\n  await Rabbit.sendToQueue('my_queue', 'This message was sent by adonis-rabbit')\n})\n```\n\n### Subscribing\n\nNotice doesn't really makes sense to subscribe to an queue inside a controller, usually this is done through a preload file.\n\n### Creating a preload file\n\n1. In the CLI, type: `node ace make:prldfile rabbit`\n2. Select `( ) During HTTP server`\n\nThis is will create `start/rabbit.ts`.\n\n### Listening to an queue\n\nInside `start/rabbit.ts`:\n\n```ts\nimport Rabbit from '@ioc:Adonis/Addons/Rabbit'\n\nasync function listen() {\n  await Rabbit.assertQueue('my_queue')\n\n  await Rabbit.consumeFrom('my_queue', (message) => {\n    console.log(message.content)\n  })\n}\n\nlisten()\n```\n\nThis will log every message sent to my queue `my_queue`.\n\n## Documentation\n\n### RabbitMQ Manager\n\n#### Import\n\n```ts\nimport Rabbit from '@ioc:Adonis/Addons/Rabbit'\n```\n\n#### `assertQueue()`\n\n```ts\nawait Rabbit.assertQueue('myQueue')\n```\n\nAssert the queue is created.\n\nParameters:\n\n1. `queueName`: the name of the queue\n2. `options?`: the queue options\n\n#### `assertExchange()`\n\n```ts\nawait Rabbit.assertExchange('myQueue', 'type')\n```\n\nAssert the exchange is created.\n\nParameters:\n\n1. `queueName`: the name of the queue\n2. `type`: the type of the exchange\n3. `options?`: the queue options\n\n#### `bindQueue()`\n\n```ts\nawait Rabbit.bindQueue('myQueue', 'myExchange', '')\n```\n\nBinds a queue and an exchange\n.\n\n1. `queueName`: the name of the queue\n2. `exchangeName`: the name of the exchange\n3. `pattern?`: the pattern (default to `''`)\n\n#### `sendToQueue()`\n\n```ts\nawait Rabbit.sendToQueue('myQueue', 'content')\n```\n\nParameters:\n\n1. `queueName`: the name of the queue\n2. `content`: the content to be send to the queue\n3. `options`: the options\n\nNotice that the `content` parameter don't need to be a Buffer, Adonis RabbitMQ will automatically convert it to a Buffer if it isn't already.\n\nYou also don't have to `JSON.stringify` an object, Adonis RabbitMQ will also do that for you (it'll be transformed to JSON then to Buffer).\n\n#### `sendToExchange()`\n\n```ts\nawait Rabbit.sendToExchange('myExchange', 'myRoutingKey', 'content')\n```\n\nParameters:\n\n1. `exchangeName`: the name of the exchange\n2. `routingKey`: the routing key\n3. `content`: the content to send to the exchange\n4. `options`: the options\n\nNotice that the `content` parameter doesn't need to be a Buffer, Adonis RabbitMQ will automatically convert it to a Buffer if it is'nt already.\n\nYou also don't have to `JSON.stringify` an object, Adonis RabbitMQ will also do that for you (it'll be transformed to JSON then to Buffer).\n\n#### `consumeFrom()`\n\n```ts\nawait Rabbit.consumeFrom('myQueue', (message) => {\n  console.log(message.content)\n  message.ack()\n})\n```\n\nConsumes a message from a queue.\n\n1. `queueName`: the name of the queue\n2. `onMessage` the callback which will be executed on the message receive.\n\nThe `onMessage` callback receives a <a href=\"#message\">`Message`</a> instance as parameter.\n\n#### `await ackAll()`\n\n```ts\nawait Rabbit.ackAll()\n```\n\nAcknowledges all the messages.\n\n#### `await nackAll()`\n\n```ts\nawait Rabbit.nackAll()\n```\n\nRejects all the messages.\n\nParameters:\n\n1. `requeue?` adds the rejected messages to queue again.\n\n#### `getConnection()`\n\nRetrieves the amqplib's Connection instance. If there`s not a connection, it'll be created.\n\n```ts\nawait Rabbit.getConnection()\n```\n\n#### `getConnection()`\n\nRetrieves the amqplib's Connection instance. If there`s not a connection, it'll be created.\n\n```ts\nawait Rabbit.getConnection()\n```\n\n#### `getChannel()`\n\nRetrieves the amqplib's Channel instance. If there's not a connection, it'll be created. If there`s not a channel, it'll be created too.\n\n```ts\nawait Rabbit.getChannel()\n```\n\n#### `closeChannel()`\n\nCloses the channel.\n\n#### `closeConnection()`\n\nCloses the connection.\n\n---\n\n### Message\n\nWhen consuming messages through [`consumeFrom`](https://github.com/jotaajunior/adonis-rabbit#consumefrom), you'll receive in the callback a Message instance.\n\nThis slightly different from amqplib approach. For example:\n\n```ts\nRabbit.consumeFrom('queue', (message) => {\n  // Acknowledges the message\n  message.ack()\n\n  // Rejects the message\n  message.reject()\n\n  // The message content\n  console.log(message.content)\n\n  // If you're expecting a JSON, this will return the parsed message\n  console.log(message.jsonContent)\n})\n```\n\n#### `content`\n\n```ts\nmessage.content\n```\n\nReturns the message content.\n\n#### `jsonContent`\n\n```ts\nmessage.jsonContent\n```\n\nIf the message is expected to be in JSON format, then you can use `message.jsonContent` to get the message parsed as an object.\n\n#### `fields`\n\n```ts\nmessage.fields\n```\n\nThe message fields.\n\n#### `properties`\n\n```ts\nmessage.properties\n```\n\nThe message properties.\n\n#### `ack()`\n\n```ts\nmessage.ack()\n```\n\nAcknowledges the message.\n\n1. `allUpTo?` acknowledges all the messages up to this.\n\n#### `nack()`\n\n```ts\nmessage.nack()\n```\n\nRejects the message.\n\nParameters:\n\n1. `allUpTo?` rejects all the messages up to this.\n1. `requeue?` adds the rejected messages to Queue again.\n\n#### `reject()`\n\n```ts\nmessage.nack()\n```\n\nRejects the message, equivalent to `nack`, but works in older versions of RabbitMQ where `nack` does not.\n\nParameters:\n\n1. `requeue?` adds the rejected messages to Queue again.\n\n## Roadmap\n\n- [ ] Add SSL options in `config/rabbit.ts`\n- [ ] Tests\n","readmeFilename":"README.md"}