{"id":18777478,"url":"https://github.com/alexvanzyl/fastify-rabbit","last_synced_at":"2026-05-05T04:02:36.447Z","repository":{"id":57233352,"uuid":"193869111","full_name":"alexvanzyl/fastify-rabbit","owner":"alexvanzyl","description":"Fastify RabbitMQ connection plugin, this is a convenience wrapper around amqplib library.","archived":false,"fork":false,"pushed_at":"2019-07-08T14:51:56.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-29T10:12:58.083Z","etag":null,"topics":["fasitfy-rabbit","fastify","rabbit","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexvanzyl.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}},"created_at":"2019-06-26T09:03:47.000Z","updated_at":"2020-08-22T18:07:43.000Z","dependencies_parsed_at":"2022-09-04T21:20:37.459Z","dependency_job_id":null,"html_url":"https://github.com/alexvanzyl/fastify-rabbit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexvanzyl%2Ffastify-rabbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexvanzyl%2Ffastify-rabbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexvanzyl%2Ffastify-rabbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexvanzyl%2Ffastify-rabbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexvanzyl","download_url":"https://codeload.github.com/alexvanzyl/fastify-rabbit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239687627,"owners_count":19680766,"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":["fasitfy-rabbit","fastify","rabbit","rabbitmq"],"created_at":"2024-11-07T20:11:17.859Z","updated_at":"2025-12-16T22:30:20.137Z","avatar_url":"https://github.com/alexvanzyl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-rabbit\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\n[![Build Status](https://travis-ci.org/alexvanzyl/fastify-rabbit.svg?branch=master)](https://travis-ci.org/alexvanzyl/fastify-rabbit)\n\nFastify RabbitMQ connection plugin, this is a convenience wrapper around [amqplib](https://github.com/squaremo/amqp.node) library.\n\n## Install\n```\nnpm i fastify-rabbit --save\n```\n\n## Usage\n```js\nconst fastify = require('fastify')()\n\n// Register plugin\nfastify.register(require('fastify-rabbit'), {\n  url: 'amqp://localhost'\n})\n\n// Publish message to queue\nfastify.get('/', async function (req, reply) {\n  const channel = this.rabbit.channel\n\n  // Create queue if it does not exist\n  const ok = await channel.assertQueue('hello')\n  if (!ok) {\n    // handle failed to assert queue\n  }\n\n  // Push message to queue \n  try {\n    await channel.sendToQueue('hello', Buffer.from('The is my message to you...'))\n    reply.send('Message sent!')\n  } catch (err) {\n    reply.log.error(err)\n  }\n})\n\n// Consume messages from queue\nfastify.register(async function(fastify, opts) {\n  const channel = fastify.rabbit.channel\n\n  // Create queue if it does not exist\n  const ok = await channel.assertQueue('hello')\n  if (ok) {\n    // start consuming queue\n     channel.consume('hello', msg =\u003e {\n      fastify.log.info(msg.content.toString())\n      channel.ack(msg)\n    })\n  }\n}) \n```\n\n## Using connection object\nYou can also connect using an object instead of an url, like so:\n```js\nfastify.register(require('fastify-rabbit'), {\n  protocol: 'amqp',\n  hostname: 'localhost',\n  port: 5672,\n  username: 'guest',\n  password: 'guest',\n  locale: 'en_US',\n  frameMax: 0,\n  heartbeat: 0,\n  vhost: '/'\n})\n```\n\n## Reference\nThis plugin decorates the `fastify` instance with a `rabbit` object. That object has the\nfollowing properties:\n\n- `conn` - reference to the [amqplib connection object](http://www.squaremobius.net/amqp.node/channel_api.html#models)\n- `channel` - reference to the [amqplib channel](http://www.squaremobius.net/amqp.node/channel_api.html#channel)\n\n## Running tests\nTo run tests RabbitMQ is required. You can either install it via a package manager or if you have docker installed you can spin up a RabbitMQ container with:\n```\nnpm run rabbit\n```\nUnder the hood this runs `docker run -p 5672:5672 -p 15672:15672 rabbitmq:management`.\n\nYou can now run the tests with:\n```\nnpm test\n```\n\n## License\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexvanzyl%2Ffastify-rabbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexvanzyl%2Ffastify-rabbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexvanzyl%2Ffastify-rabbit/lists"}