{"id":17105373,"url":"https://github.com/kffl/fastify-amqp-async","last_synced_at":"2025-04-13T01:13:33.540Z","repository":{"id":37081235,"uuid":"440891113","full_name":"kffl/fastify-amqp-async","owner":"kffl","description":":zap::rabbit: Fastify AMQP plugin with modern Promise-based API based on amqplib-as-promised","archived":false,"fork":false,"pushed_at":"2023-11-21T17:05:35.000Z","size":135,"stargazers_count":3,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T01:13:27.974Z","etag":null,"topics":["amqp","async-await","fastify","fastify-amqp","fastify-plugin","fastify-plugins","fastify-rabbitmq","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/kffl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-22T14:49:42.000Z","updated_at":"2023-05-02T10:34:40.000Z","dependencies_parsed_at":"2023-02-01T03:30:52.952Z","dependency_job_id":null,"html_url":"https://github.com/kffl/fastify-amqp-async","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kffl%2Ffastify-amqp-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kffl%2Ffastify-amqp-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kffl%2Ffastify-amqp-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kffl%2Ffastify-amqp-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kffl","download_url":"https://codeload.github.com/kffl/fastify-amqp-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650754,"owners_count":21139681,"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":["amqp","async-await","fastify","fastify-amqp","fastify-plugin","fastify-plugins","fastify-rabbitmq","rabbitmq"],"created_at":"2024-10-14T15:41:47.422Z","updated_at":"2025-04-13T01:13:33.522Z","avatar_url":"https://github.com/kffl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify AMQP plugin with a modern, promise-based API\n\n[![CI Workflow](https://github.com/kffl/fastify-amqp-async/actions/workflows/ci.yml/badge.svg)](https://github.com/kffl/fastify-amqp-async/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/fastify-amqp-async.svg?style=flat)](https://www.npmjs.com/package/fastify-amqp-async)\n[![NPM downloads](https://img.shields.io/npm/dm/fastify-amqp-async.svg?style=flat)](https://www.npmjs.com/package/fastify-amqp-async)\n[![Known Vulnerabilities](https://snyk.io/test/github/kffl/fastify-amqp-async/badge.svg)](https://snyk.io/test/github/kffl/fastify-amqp-async)\n\n**fastify-amqp-async** is a Fastify plugin inspired by **fastify-amqp** which allows for interacting with RabbitMQ using a more modern, Promise-based API provided by [amqplib-as-promised](https://github.com/twawszczak/amqplib-as-promised), so that writing publishers doesn't feel like 2013.\n\n## Features\n\n- Supports both channels with publisher confirms and regular channels\n- Decorates the Fastify Instance with `amqp` object exposing RabbitMQ `connection`, `channel` and `confirmChannel` following [amqplib-as-promised API](https://github.com/twawszczak/amqplib-as-promised#api)\n- Has 100% test coverage \n\n## Installation\n\n```\nnpm install fastify-amqp-async\n```\n\nThe underlying `amqplib-as-promised` library exposes some objects of `amqplib` native types such as `Message`. In order to allow for proper typechecks of such objects, it is recommended to install `@types/amqplib` as a development dependency:\n\n```\nnpm install --save-dev @types/amqplib\n```\n\n## Usage\n\n```javascript\nconst fastify = require('fastify');\nconst fastifyAmqpAsync = require('fastify-amqp-async');\n\nconst app = fastify();\n\nconst options = {\n    connectionString: \"amqp://user:password@localhost:5672\",\n    useConfirmChannel: false, // true by default\n    useRegularChannel: true, // false by default\n}\n\napp.register(fastifyAmqpAsync, options);\n\napp.get('/produce', async function (req, res) {\n    const channel = this.amqp.channel;\n\n    await channel.assertQueue('queuename', { durable: true });\n    await channel.sendToQueue('queuename', Buffer.from(\"Sample message\"));\n\n    res.send(\"done\");\n});\n```\n\nYou can find additional usage examples in the `examples` folder.\n\n## Reference\n\nThe config object passed as a second parameter passed to `register()` is optional (since all 4 of its keys have default values) has the following schema:\n\n```typescript\ninterface FastifyAmqpAsyncOptions {\n    /**\n     * AMQP connection string\n     * @default 'amqp://guest:guest@localhost:5672'\n     */\n    connectionString?: string;\n    /**\n     * Spawn a confirm channel (awaiting publisher confirmations) exposed via FastifyInstance.amqp.confirmChannel\n     * @default true\n     */\n    useConfirmChannel?: boolean;\n    /**\n     * Spawn a regular channel (fire-and-forget) exposed via FastifyInstance.amqp.channel\n     * @default false\n     */\n    useRegularChannel?: boolean;\n    /**\n     * Ignore the default onClose handler which closes the connection\n     * If set to true, you have to manage closing the connection yourself\n     * (i.e. after waiting for all in-flight messages to be delivered)\n     * @default false\n     */\n    ignoreOnClose?: boolean;\n}\n```\n\nUpon being registered, fastify-amqp-async decorates the FastifyInstance with `amqp` exposing the following keys:\n\n- `connection` - the underlying amqplib-as-promised connection object ([API reference](https://github.com/twawszczak/amqplib-as-promised#connection))\n- `channel` - a single amqplib-as-promised fire-and-forget channel object ([API reference](https://github.com/twawszczak/amqplib-as-promised#channel)). Bare in mind that it will be undefined by default unless `useRegularChannel` is set to `true` in the config object.\n- `confirmChannel` - a single amqplib-as-promised channel with publisher confirms ([API reference](https://github.com/twawszczak/amqplib-as-promised#confirm-channel)). Will be undefined if `useConfirmChannel` is set to `false` in the config object.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkffl%2Ffastify-amqp-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkffl%2Ffastify-amqp-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkffl%2Ffastify-amqp-async/lists"}