{"id":16981959,"url":"https://github.com/1602/transport-rabbit","last_synced_at":"2025-04-12T02:20:59.533Z","repository":{"id":57379244,"uuid":"61395868","full_name":"1602/transport-rabbit","owner":"1602","description":"Rabbitmq Transport for microservices","archived":false,"fork":false,"pushed_at":"2017-07-27T13:26:11.000Z","size":178,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-26T07:45:27.490Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/1602.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":"2016-06-17T18:57:21.000Z","updated_at":"2018-01-22T18:47:21.000Z","dependencies_parsed_at":"2022-09-02T20:41:32.867Z","dependency_job_id":null,"html_url":"https://github.com/1602/transport-rabbit","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Ftransport-rabbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Ftransport-rabbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Ftransport-rabbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1602%2Ftransport-rabbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1602","download_url":"https://codeload.github.com/1602/transport-rabbit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505921,"owners_count":21115354,"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":[],"created_at":"2024-10-14T02:06:56.916Z","updated_at":"2025-04-12T02:20:59.514Z","avatar_url":"https://github.com/1602.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Build status][build-image]][build-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![Dependency Status][dependencies-image]][dependencies-url]\n\n# Usage\n\nThis is an example of low-level API implemented by this library\n\n```\nconst transport = queueTransport({ url: 'amqp://localhost:5672/' });\n\n// on server\ntransport.server({\n    consume: {\n        queue: {\n            exchange: 'log',\n            routes: [ 'warn', 'info', 'error' ],\n            options: {\n                durable: true\n            }\n        }\n    },\n    handler: {\n        warn: msg =\u003e console.warn(msg),\n        info: msg =\u003e console.info(msg),\n        error: msg =\u003e console.error(msg)\n    }\n});\n\n// on client\nconst send = transport.client({\n    produce: {\n        queue: {\n            exchange: 'log',\n            routes: [ 'warn', 'info', 'error' ],\n            options: {\n                durable: true\n            }\n        }\n    }\n});\n\ntransport.getReady()\n    .then(() =\u003e {\n        send('Hello World', 'warn');\n    });\n```\n\nBut low level API only good for understanding how things actually work under\nthe hood. It is recommended to use higher level API which predefine some\nmessaging patterns such as pubsub, RPC or basic producer-consumer queues.\n\nAn example of higher-level API\n\n```\nconst transport = queueTransport({ url: 'amqp://localhost:5672' });\n\n// A: producer\nconst send = transport.createCommandSender('multiply-by-2');\ntransport.getReady().then(() =\u003e send(10));\n\n// B: consumer\ntransport.createCommandServer('multiply-by-2', param =\u003e {\n    return param * 2;\n});\n\n// C: consumer of results produced by consumer (B)\ntransport.createCommandResultRecipient('task', {\n    result: num =\u003e console.log('got result %d', num),\n    error: err =\u003e console.log('got error', err)\n});\n```\n\nHigher level API [implements](./domains/command.js) most common scenarios of\nmessaging between nodes and use lower level API internally.\n\n# Why not just use amqplib?\n\nWhat problem this library is trying to solve? API provided by amqplib is\nawesome, but it requires some boilerplate code to be written every time we want\nto connect to the queue server. Usual workflow looks like that:\n\n1. open connection\n2. create channel\n3. set prefetch for channel (if we're going to consume some queues)\n4. assert exchanges\n5. assert queues\n6. bind exchanges to queues\n7. start consuming / producing messages from asserted queues / exchanges\n\nIn applications we usually interested only in messaging and not in all\naccidental complexity coming along with amqp protocol. Even if this is\nnecessary to be able to use multiple channels, configure prefetch and handle\nlogic of reconnecting in case of disconnects this should not be concern of our\ncode, because if should be written every time in every node we want to connect\nto the queue.\n\n# Tests\n\n```\nnpm run docker-test\n```\n\ncheck [./test/README.md](./test/README.md) for more details on testing\n\n[coveralls-url]: https://coveralls.io/github/1602/transport-rabbit\n[coveralls-image]: https://coveralls.io/repos/github/1602/transport-rabbit/badge.svg\n[build-url]: https://circleci.com/gh/1602/transport-rabbit\n[build-image]: https://circleci.com/gh/1602/transport-rabbit.svg?style=shield\n[npm-image]: https://img.shields.io/npm/v/transport-rabbit.svg\n[npm-url]: https://npmjs.org/package/transport-rabbit\n[downloads-image]: https://img.shields.io/npm/dm/transport-rabbit.svg\n[downloads-url]: https://npmjs.org/package/transport-rabbit\n[dependencies-image]: https://david-dm.org/1602/transport-rabbit.svg\n[dependencies-url]: https://david-dm.org/1602/transport-rabbit\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1602%2Ftransport-rabbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1602%2Ftransport-rabbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1602%2Ftransport-rabbit/lists"}