{"id":18405864,"url":"https://github.com/superbalist/js-pubsub","last_synced_at":"2025-04-07T08:32:12.493Z","repository":{"id":20470232,"uuid":"89999183","full_name":"Superbalist/js-pubsub","owner":"Superbalist","description":"A JS abstraction for the pub-sub pattern","archived":false,"fork":false,"pushed_at":"2022-06-07T09:33:28.000Z","size":65,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-01T15:11:53.621Z","etag":null,"topics":["javascript","js-pubsub","node","node-js","node-module","nodejs","nodejs-modules","pubsub","superbalist"],"latest_commit_sha":null,"homepage":null,"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/Superbalist.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2017-05-02T06:29:03.000Z","updated_at":"2022-06-03T08:29:08.000Z","dependencies_parsed_at":"2022-08-27T13:20:16.458Z","dependency_job_id":null,"html_url":"https://github.com/Superbalist/js-pubsub","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Fjs-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Fjs-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Fjs-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Fjs-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Superbalist","download_url":"https://codeload.github.com/Superbalist/js-pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247620286,"owners_count":20968179,"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":["javascript","js-pubsub","node","node-js","node-module","nodejs","nodejs-modules","pubsub","superbalist"],"created_at":"2024-11-06T03:05:17.828Z","updated_at":"2025-04-07T08:32:12.112Z","avatar_url":"https://github.com/Superbalist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @superbalist/js-pubsub\n\nA JS abstraction for the pub-sub pattern\n\n[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist)\n[![Build Status](https://img.shields.io/travis/Superbalist/js-pubsub/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/js-pubsub)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![NPM Version](https://img.shields.io/npm/v/@superbalist/js-pubsub.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub)\n[![NPM Downloads](https://img.shields.io/npm/dt/@superbalist/js-pubsub.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub)\n\n## Installation\n\n```bash\nnpm install @superbalist/js-pubsub\n```\n\n## Adapters\n\n* Local (bundled)\n* /dev/null (bundled)\n* Redis - https://github.com/Superbalist/js-pubsub-redis\n* Google Cloud - https://github.com/Superbalist/js-pubsub-google-cloud\n* HTTP - https://github.com/Superbalist/js-pubsub-http\n\n## Integrations\n\nWant to get started quickly? Check out some of these integrations:\n\n* [js-pubsub-manager](https://github.com/Superbalist/js-pubsub-manager) - A factory and manager with multi adapter support.\n\n## Usage\n\n```node\n\"use strict\";\n\nlet LocalPubSubAdapter = require('@superbalist/js-pubsub').LocalPubSubAdapter;\n\nlet adapter = new LocalPubSubAdapter();\n\n// consume messages\nadapter.subscribe('my_channel', (message) =\u003e {\n  console.log('channel: my_channel');\n  console.log(message);\n});\n\n// publish messages\nadapter.publish('my_channel', 'Hello World!');\n\n// publish multiple messages\nlet messages = [\n  'message 1',\n  'message 2',\n];\nadapter.publishBatch('my_channel', messages);\n```\n\n## Writing an Adapter\n\nYou can easily write your own custom adapter by implementing the [PubSubAdapterInterface](src/PubSubAdapterInterface.js) interface.\n\n```node\nclass CustomAdapter {\n  /**\n   * Subscribe a handler to a channel.\n   *\n   * @param {string} channel\n   * @param {subscriberCallback} handler - The callback to run when a message is received\n   * @example\n   * adapter.subscribe('my_channel', (message) =\u003e {\n   *   console.log(message);\n   * });\n   */\n  subscribe(channel, handler) {\n\n  }\n\n  /**\n   * Publish a message to a channel.\n   *\n   * @param {string} channel\n   * @param {*} message - The message payload\n   * @return {Promise\u003c*\u003e}\n   * @example\n   * // publish a string\n   * adapter.publish('my_channel', 'Hello World');\n   *\n   * // publish an object\n   * adapter.publish('my_channel', {\n   *   'id': 1234,\n   *   'first_name': 'Matthew',\n   * });\n   */\n  publish(channel, message) {\n\n  }\n\n  /**\n   * Publish multiple messages to a channel.\n   *\n   * @param {string} channel\n   * @param {*[]} messages\n   * @return {Promise\u003c*\u003e}\n   * @example\n   * let messages = [\n   *   'message 1',\n   *   'message 2',\n   * ];\n   * adapter.publishBatch('my_channel', messages);\n   */\n  publishBatch(channel, messages) {\n\n  }\n}\n```\n\n## Examples\n\nThe library comes with [examples](examples) for all adapters and a [Dockerfile](Dockerfile) for\nrunning the example scripts.\n\nRun `make up`.\n\nYou will start at a `bash` prompt in the `/usr/src/app` directory.\n\nIf you need another shell to publish a message to a blocking consumer, you can run `docker-compose run js-pubsub /bin/bash`\n\nTo run the examples:\n```bash\n$ node examples/LocalExample.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperbalist%2Fjs-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperbalist%2Fjs-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperbalist%2Fjs-pubsub/lists"}