{"id":18022068,"url":"https://github.com/jotaajunior/adonis-rabbit","last_synced_at":"2025-03-26T22:31:03.662Z","repository":{"id":48364945,"uuid":"304938970","full_name":"jotaajunior/adonis-rabbit","owner":"jotaajunior","description":"🐰 AdonisJS RabbitMQ provider","archived":false,"fork":false,"pushed_at":"2023-09-27T17:59:59.000Z","size":147,"stargazers_count":27,"open_issues_count":6,"forks_count":17,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-03-20T01:42:04.276Z","etag":null,"topics":["adonisjs","amqp","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jotaajunior.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-17T18:03:30.000Z","updated_at":"2024-06-18T18:06:48.000Z","dependencies_parsed_at":"2024-06-21T12:56:31.306Z","dependency_job_id":"ec9b9ffd-0e23-4ed3-9afe-69a89433c9e8","html_url":"https://github.com/jotaajunior/adonis-rabbit","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":"0.052631578947368474","last_synced_commit":"63e1f9e7d611e0e080214ed0a0dfbe4eb2fad1ab"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotaajunior%2Fadonis-rabbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotaajunior%2Fadonis-rabbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotaajunior%2Fadonis-rabbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jotaajunior%2Fadonis-rabbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jotaajunior","download_url":"https://codeload.github.com/jotaajunior/adonis-rabbit/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245747540,"owners_count":20665806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adonisjs","amqp","rabbitmq"],"created_at":"2024-10-30T06:11:56.274Z","updated_at":"2025-03-26T22:31:03.201Z","avatar_url":"https://github.com/jotaajunior.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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 adonis-rabbit\n```\n\nThen:\n\n```\nnode ace invoke 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 () =\u003e {\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) =\u003e {\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) =\u003e {\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 \u003ca href=\"#message\"\u003e`Message`\u003c/a\u003e 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) =\u003e {\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjotaajunior%2Fadonis-rabbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjotaajunior%2Fadonis-rabbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjotaajunior%2Fadonis-rabbit/lists"}