{"id":24558116,"url":"https://github.com/rse/ipc-pubsub","last_synced_at":"2025-04-19T09:58:51.699Z","repository":{"id":57276527,"uuid":"91134404","full_name":"rse/ipc-pubsub","owner":"rse","description":"Inter-Process-Communication (IPC) Publish-Subscribe (PubSub) Abstraction Layer","archived":false,"fork":false,"pushed_at":"2025-03-11T20:52:45.000Z","size":57,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T21:55:48.106Z","etag":null,"topics":["abstraction","ipc","layer","publish","pubsub","subscribe"],"latest_commit_sha":null,"homepage":null,"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/rse.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":"2017-05-12T22:35:07.000Z","updated_at":"2024-06-27T18:17:44.000Z","dependencies_parsed_at":"2022-09-13T04:54:09.985Z","dependency_job_id":null,"html_url":"https://github.com/rse/ipc-pubsub","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fipc-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fipc-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fipc-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fipc-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rse","download_url":"https://codeload.github.com/rse/ipc-pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249670023,"owners_count":21308669,"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":["abstraction","ipc","layer","publish","pubsub","subscribe"],"created_at":"2025-01-23T05:47:25.547Z","updated_at":"2025-04-19T09:58:51.679Z","avatar_url":"https://github.com/rse.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nIPC-PubSub\n==========\n\nInter-Process-Communication (IPC) Publish-Subscribe (PubSub) Communication Abstraction Layer\n\n\u003cp/\u003e\n\u003cimg src=\"https://nodei.co/npm/ipc-pubsub.png?downloads=true\u0026stars=true\" alt=\"\"/\u003e\n\n\u003cp/\u003e\n\u003cimg src=\"https://david-dm.org/rse/ipc-pubsub.png\" alt=\"\"/\u003e\n\nAbout\n-----\n\nThis [Node.js](https://nodejs.org) module provides an\nabstraction layer for [Inter-Process-Communication\n(IPC)](https://en.wikipedia.org/wiki/Inter-process_communication)\nthrough Publish-Subscribe communication. It supports the following modes\n(in order of increasing process scope and overall complexity):\n\n- **Single-Process-Model (SPM):**\u003cbr/\u003e\n  This is for Node applications NOT using the Node.js\n  [`cluster`](https://nodejs.org/api/cluster.html) module.\n  The communication is performed with an in-memory\n  [`PatternEmitter`](http://npmjs.com/pattern-emitter). No external\n  resource is needed.\n\n- **Multi-Process-Model (MPM):**\u003cbr/\u003e\n  This is for Node applications using the Node.js\n  [`cluster`](https://nodejs.org/api/cluster.html) module. Hence, it is\n  for Node applications split into distinct (related) processes, running\n  on the same machine. The communication is performed with an in-memory\n  [`PatternEmitter`](http://npmjs.com/pattern-emitter) in each process\n  and an IPC message exchange between the processes with the help of the\n  Node.js [`cluster`](https://nodejs.org/api/cluster.html) module. No\n  external resource is needed.\n\n- **Remote-Process-Model (RPM):**\u003cbr/\u003e\n  This is for Node applications split into (unrelated)\n  distinct processes, usually running on distinct machines.\n  The communication is performed with the help of an\n  external broker. Currently a [NATS](https://nats.io/)\n  broker (e.g. [gNATSd](https://github.com/nats-io/gnatsd)),\n  a [MQTT](http://mqtt.org/) broker (e.g.\n  [Mosquitto](https://mosquitto.org/)), [Redis](https://redis.io/)\n  [Pub/Sub](https://redis.io/topics/pubsub)\n  or [PostgreSQL](https://www.postgresql.org/)\n  [LISTEN](https://www.postgresql.org/docs/current/static/sql-listen.html) /\n  [NOTIFY](https://www.postgresql.org/docs/current/static/sql-notify.html)\n  is supported.\n\nInstallation\n------------\n\n```shell\n$ npm install ipc-pubsub --save-dev\n```\n\nUsage\n-----\n\n```js\n(async () =\u003e {\n    const PubSub = require(\"ipc-pubsub\")\n\n    /*  open connection  */\n    let pubsub = new PubSub(\"spm\")\n    await pubsub.open()\n\n    /*  subscribe for messages  */\n    await pubsub.subscribe(\"foo/#\", (value, channel) =\u003e {\n        console.log(value, channel) // -\u003e \"quux\" \"foo/bar\"\n    })\n\n    /*  publish message  */\n    await pubsub.publish(\"foo/bar\", \"quux\")\n\n    /*  close connection  */\n    await pubsub.close()\n})()\n```\n\nThe following URLs are supported on `new PubSub(url)`:\n\n- `spm:\u003cid\u003e`\n- `mpm:\u003cid\u003e`\n- `rpm+redis://[xxx:\u003csecret\u003e@]\u003chost\u003e[:\u003cport\u003e][/\u003cid\u003e]`\n- `rpm+mqtt://[\u003cusername\u003e:\u003cpassword\u003e@]\u003chost\u003e[:\u003cport\u003e][/\u003cid\u003e][?tls=true[\u0026\u0026key=\u003cfile\u003e\u0026\u0026crt=\u003cfile\u003e\u0026\u0026ca=\u003cfile\u003e]]`\n- `rpm+nats://[\u003cusername\u003e:\u003cpassword\u003e@]\u003chost\u003e[:\u003cport\u003e][/\u003cid\u003e][?tls=true[\u0026\u0026key=\u003cfile\u003e\u0026\u0026crt=\u003cfile\u003e\u0026\u0026ca=\u003cfile\u003e]]`\n- `rpm+pgsql://[\u003cusername\u003e:\u003cpassword\u003e@]\u003chost\u003e[:\u003cport\u003e][/\u003cid\u003e][?tls=true[\u0026\u0026key=\u003cfile\u003e\u0026\u0026crt=\u003cfile\u003e\u0026\u0026ca=\u003cfile\u003e]]`\n\nThe `\u003cid\u003e` is an arbitrary unique identifier matching the regular expression `^[a-zA-Z][a-zA-Z0-9-]*$`.\n\nThe channel names are MQTT-style topic names, i.e., slash-separated strings\nlike `foo/bar/quux`. The channel argument of `subscribe(channel, ...)`\nis actually an MQTT-style topic pattern, i.e., it can contain `*` for single\nelement and `#` for remaining elements. For example: `foo/bar/*/quux/#`\nwill match `foo/bar/baz/quux/foo`. The only exception is the PostgreSQL\nmechanism: it does not support any MQTT-style wildcards at all.\n\nRecommendation: As Redis does not support TLS and PostgreSQL does not support\nMQTT-style wildcards, we prefer to use IPC-PubSub primarily with MQTT and\n[Mosquitto](https://mosquitto.org/) or NATS and [gNATSd](https://github.com/nats-io/gnatsd).\n\nApplication Programming Interface (API)\n---------------------------------------\n\n```ts\ninterface PubSubSubscription {\n    unsubscribe(): Promise\u003cvoid\u003e;\n}\n\ndeclare class PubSub {\n    constructor(url: string);\n\n    open(): Promise\u003cvoid\u003e;\n\n    publish(\n        channel: string,\n        message: any\n    ): Promise\u003cvoid\u003e;\n\n    subscribe(\n        channelPattern: string,\n        onMessage: (message: any, channel: string) =\u003e void\n    ): Promise\u003cPubSubSubscription\u003e;\n\n    close(): Promise\u003cvoid\u003e;\n}\n```\n\nLicense\n-------\n\nCopyright (c) 2017-2019 Dr. Ralf S. Engelschall (http://engelschall.com/)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fipc-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frse%2Fipc-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fipc-pubsub/lists"}