{"id":22221136,"url":"https://github.com/davesag/amqp-simple-pub-sub","last_synced_at":"2025-07-27T16:31:05.758Z","repository":{"id":30343686,"uuid":"124656831","full_name":"davesag/amqp-simple-pub-sub","owner":"davesag","description":"A simple Pub Sub system that uses AMQP Messaging to exchange data between services","archived":false,"fork":false,"pushed_at":"2024-04-23T05:55:29.000Z","size":3082,"stargazers_count":20,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-05-02T00:12:06.365Z","etag":null,"topics":["amqp","message-queue","pubsub"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/amqp-simple-pub-sub","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/davesag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":["davesag"]}},"created_at":"2018-03-10T13:11:49.000Z","updated_at":"2024-04-23T05:55:32.000Z","dependencies_parsed_at":"2024-02-14T08:22:23.904Z","dependency_job_id":"32e805b3-bfef-49e7-82f8-e10ff009b3fc","html_url":"https://github.com/davesag/amqp-simple-pub-sub","commit_stats":{"total_commits":359,"total_committers":6,"mean_commits":"59.833333333333336","dds":0.1058495821727019,"last_synced_commit":"c2714482aca767d51669244c8947fd5a35e90621"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Famqp-simple-pub-sub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Famqp-simple-pub-sub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Famqp-simple-pub-sub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Famqp-simple-pub-sub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davesag","download_url":"https://codeload.github.com/davesag/amqp-simple-pub-sub/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227817166,"owners_count":17824199,"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","message-queue","pubsub"],"created_at":"2024-12-02T23:12:24.429Z","updated_at":"2024-12-02T23:12:25.042Z","avatar_url":"https://github.com/davesag.png","language":"JavaScript","funding_links":["https://github.com/sponsors/davesag"],"categories":[],"sub_categories":[],"readme":"# AMQP Simple Pub Sub\n\nA Pub Sub system that uses `AMQP` messaging to exchange data between services.\n\n[![NPM](https://nodei.co/npm/amqp-simple-pub-sub.png)](https://nodei.co/npm/amqp-simple-pub-sub/)\n\n## To Use\n\nYou project needs to be using at least Node version 10, and ideally Node 18 (LTS) or later.\n\n```sh\nnpm install amqp-simple-pub-sub\n```\n\n### Create a Publisher\n\n```js\nconst { makePublisher } = require('amqp-simple-pub-sub')\nconst publisher = makePublisher({ exchange: 'testService' })\n```\n\n### Publish a message\n\n```js\nawait publisher.start()\npublisher.publish('test', 'Hello World')\n```\n\n### Create a Subscriber\n\n```js\nconst { makeSubscriber } = require('amqp-simple-pub-sub')\n\nconst subscriber = makeSubscriber({\n  exchange: 'testService',\n  queueName: 'testQueue',\n  routingKeys: ['test']\n})\n```\n\n### Subscribe to a queue and listen for messages\n\n```js\nconst handler = message =\u003e {\n  console.log('Message Received', message)\n  subscriber.ack(message)\n}\n\nsubscriber.start(handler)\n```\n\n#### Publisher\n\nThe full options object is as follows\n\n```js\n{\n  type: 'topic', // the default\n  url: 'amqp://localhost', // the default\n  exchange: 'you must provide this', // it's the name of your service usually\n  onError: err =\u003e { // optional\n    console.error('A connection error happened', err) // or do something clever\n  },\n  onClose: () =\u003e { // optional\n    console.log('The connection has closed.') // or do something clever\n  },\n  ...otherOptions // anything else you pass in gets passed directly to `amqp.connect`\n}\n```\n\n#### Subscriber\n\nThe full options object is as follows\n\n```js\n{\n  type: 'topic', // the default\n  url: 'amqp://localhost', // the default\n  exchange: 'you must provide this', // it's the name of your service usually\n  queueName: 'you must also provide this', // give your queue a name\n  routingKeys: ['an', 'array', 'of', 'routingKeys'], // optional.  Uses [queueName] otherwise.\n  onError: err =\u003e { // optional\n    console.error('A connection error happened', err) // or do something clever\n  },\n  onClose: () =\u003e { // optional\n    console.log('The connection has closed.') // or do something clever\n  },\n  ...otherOptions // anything else you pass in gets passed directly to `amqp.connect`\n}\n```\n\n### Other Options\n\nAs outlined above both `createPublisher` and `createPublisher` also accept other options.\n\nThese are passed straight onto `amqp.connect` under the hood. The options are:\n\n- `clientProperties`: see [`connect.js`](https://github.com/amqp-node/amqplib/blob/main/lib/connect.js#L30)\n- `credentials`\n- `keepAlive`\n- `keepAliveDelay`\n- `noDelay`\n- `servername`\n- `timeout`\n\n#### Examples\n\nSee some examples in the tests, and also:\n\n- [competing-services-example](https://github.com/davesag/competing-services-example)\n- And the associated article: [itnext.io/connecting-competing-microservices-using-rabbitmq](https://itnext.io/connecting-competing-microservices-using-rabbitmq-28e5269861b6)\n\n## Related Projects\n\n- [`amqp-delegate`](https://github.com/davesag/amqp-delegate) — A library that simplifies, to the point of triviality, use of AMQP based remote workers.\n- [`ampq-event-tester`](https://github.com/davesag/amqp-event-tester) — A Dockerised and configurable utility to help integration-test your AMQP services.\n\n## Development\n\n### Branches\n\n\u003c!-- prettier-ignore --\u003e\n| Branch | Tests | Code Coverage | Audit | Comments |\n| ------ | ----- | ------------- | ----- | -------- |\n| `develop` | [![CircleCI](https://circleci.com/gh/davesag/amqp-simple-pub-sub/tree/develop.svg?style=svg)](https://circleci.com/gh/davesag/amqp-simple-pub-sub/tree/develop) | [![codecov](https://codecov.io/gh/davesag/amqp-simple-pub-sub/branch/develop/graph/badge.svg)](https://codecov.io/gh/davesag/amqp-simple-pub-sub) | [![Vulnerabilities](https://snyk.io/test/github/davesag/amqp-simple-pub-sub/develop/badge.svg)](https://snyk.io/test/github/davesag/amqp-simple-pub-sub/develop) | Work in progress |\n| `main` | [![CircleCI](https://circleci.com/gh/davesag/amqp-simple-pub-sub/tree/main.svg?style=svg)](https://circleci.com/gh/davesag/amqp-simple-pub-sub/tree/main) | [![codecov](https://codecov.io/gh/davesag/amqp-simple-pub-sub/branch/main/graph/badge.svg)](https://codecov.io/gh/davesag/amqp-simple-pub-sub) | [![Vulnerabilities](https://snyk.io/test/github/davesag/amqp-simple-pub-sub/main/badge.svg)](https://snyk.io/test/github/davesag/amqp-simple-pub-sub/main) | Latest release |\n\n### Prerequisites\n\n- [NodeJS](https://nodejs.org), 10.0+ (I use [`nvm`](https://github.com/creationix/nvm) to manage Node versions — `brew install nvm`.)\n- [Docker](https://www.docker.com) (Use [Docker for Mac](https://docs.docker.com/docker-for-mac/), not the homebrew version)\n\n### Initialisation\n\n```sh\nnpm install\n```\n\n### To Start the queue server for integration testing\n\n```sh\ndocker compose up -d\n```\n\nRuns Rabbit MQ.\n\n### Test it\n\n- `npm test` — runs the unit tests (quick and does not need `rabbitmq` running)\n- `npm run test:unit:cov` — runs the unit tests with code coverage (does not need `rabbitmq`)\n- `npm run test:integration` — runs the integration tests (needs `rabbitmq`)\n\n### Lint it\n\n```sh\nnpm run lint\n```\n\n## Contributing\n\nPlease see the [contributing notes](CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesag%2Famqp-simple-pub-sub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavesag%2Famqp-simple-pub-sub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesag%2Famqp-simple-pub-sub/lists"}