{"id":13749521,"url":"https://github.com/strongloop/strong-pubsub","last_synced_at":"2025-08-01T07:14:01.426Z","repository":{"id":27835695,"uuid":"31325694","full_name":"strongloop/strong-pubsub","owner":"strongloop","description":"PubSub for Node.js, Browser, Mobile and IoT","archived":false,"fork":false,"pushed_at":"2020-02-06T13:58:28.000Z","size":339,"stargazers_count":128,"open_issues_count":0,"forks_count":17,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-06-10T16:13:01.501Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/strongloop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2015-02-25T17:15:34.000Z","updated_at":"2024-11-06T10:25:37.000Z","dependencies_parsed_at":"2022-09-02T15:51:17.855Z","dependency_job_id":null,"html_url":"https://github.com/strongloop/strong-pubsub","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/strongloop/strong-pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strongloop","download_url":"https://codeload.github.com/strongloop/strong-pubsub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-pubsub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268185222,"owners_count":24209382,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08-03T07:01:04.179Z","updated_at":"2025-08-01T07:14:01.398Z","avatar_url":"https://github.com/strongloop.png","language":"JavaScript","readme":"## Installation\n\n```\n$ npm install strong-pubsub\n```\n\n## Use\n\n**NOTE: until version `1.0.0` the API may change!**\n\n```js\nvar Client = require('strong-pubsub');\nvar Adapter = require('strong-pubsub-mqtt');\n\n// two clients connecting to the same broker\nvar siskel = new Client({host: 'my.message-broker.com', port: 3000}, Adapter);\nvar ebert = new Client({host: 'my.message-broker.com', port: 3000}, Adapter);\n\nsiskel.subscribe('movies');\nsiskel.on('message', function(topic, msg) {\n console.log(topic, msg.toString()); // =\u003e movies birdman\n});\n\nebert.publish('movies', 'birdman');\n```\n\n## Client (strong-pubsub)\n\nThe `Client` class provides a unified pubsub client in Node.js and browsers. It supports subscribing\nto topics or topic patterns (topics and wildcards). Clients can connect to brokers or bridges that support\nthe `client.adapter`’s protocol.\n\n## Bridge ([strong-pubsub-bridge](https://github.com/strongloop/strong-pubsub-bridge))\n\nIn some cases, clients should not connect directly to a message broker. The Bridge class allows you to create a bridge between a client connecting to your **node.js** server and a broker. It supports hooks for injecting logic before the bridge performs an action on behalf of the client. Hooks allow you to implement client authentication and client action (publish, subscribe)\nauthorization using vanilla node.js (usually in place of broker specific access controls and authentication).\n\nBridges also allow clients to connect to brokers over a protocol that the broker may not support. For example, a client can connect to the bridge using one protocol (eg. MQTT) and the bridge will connect\nto the broker using another (eg. **Redis** or **STOMP**).\n\n![Bridge](https://raw.githubusercontent.com/strongloop/strong-pubsub/master/assets/bridge.png \"Pubsub Bridge\")\n\n**Note:** It is not possible to guarantee all features when bridging connections of one protocol to a broker that speaks another protocol. For example MQTT quality of service (`options.qos`) will be not be guaranteed when a bridge is accepting MQTT protocol connections and bridging to a redis broker.\n\n### Creating a bridge\n\nHere is an example setting up a bridge. This would bridge messages between MQTT clients and a RabbitMQ server.\n\n```js\n// my-bridge-server.js\nvar server = require('./my-existing-server');\n\nvar Adapter = require('strong-pubsub-mqtt');\nvar client = new Client('mqtt://my.mosquitto.org', Adapter);\nvar Connection = require('strong-pubsub-connection-mqtt');\n\nserver.on('connection', function(connection) {\n  mqttConnection = new Connection(connection);\n  var bridge = new Bridge(mqttConnection, client);\n});\n```\n\nThis example shows how to connect a `Client` to a `Bridge` and then a `Bridge` to a broker (using another `Client`).\n\n```js\nserver.on('connection', function(connection) {\n  var bridge = new Bridge(\n    new MqttConnection(connection),\n    new Client({port: MOSQUITTO_PORT}, Adapter)\n  );\n\n  bridge.connect();\n});\n```\n\n## Message broker\n\nTo distribute a message published to a topic, a client connects to a message broker.\nClient adapters allow pubsub clients to connect to various brokers. Clients can connect directly\nto brokers or indirectly using a bridge.\n\n## Adapter\n\nClient adapters implement the `Client` API in a broker protocol-specific way.\n\nSpecify the adapter specific options using the name as the key.\n\n```js\n{\n  mqtt: {\n    clientId: 'foobar'\n  }\n}\n```\n\n###Protocols\n\nStrong-pubsub supports these two protocols:\n\n- [MQTT](http://mqtt.org/)\n- [STOMP](https://stomp.github.io/)\n\nIt is possible to extend **strong-pubsub** to support other protocols, but that is beyond the scope of this README.\n\n###Transports\n\nAdapters / Clients require a tranpsort to create a connection and read / write data to / from.\n\nA module (or object) that implements `net.createConnection()`.\n\n- The standard TCP protocol: `require('net')`\n- Transport Layer Security (TLS), a secure cryptographic protocol: `require('tls')`\n- [Primus](https://github.com/primus/primus) (in development): `require('strong-pubsub-transport-primus')`\n\n## Transport swapping\n\nThis example shows how to switch betweenn different transports on the client.\n\n```js\n//\n// client side transport switching\n//\nvar Adapter = require('strong-pubsub-mqtt');\n\n// default\nvar TcpTransport = require('net'); // tcp (the default)\nvar client = new Client({host: 'localhost', port: 3000}, Adapter, TcpTransport);\n\n// primus\nvar PrimusTransport = require('strong-pubsub-primus');\nvar client = new Client({host: 'localhost', port: 3000}, Adapter, PrimusTransport);\n\n// tls\nvar TlsTransport = require('tls');\nvar client = new Client({host: 'localhost', port: 3000}, Adapter, TlsTransport);\n\n//\n// bridge transport swapping\n//\nvar primusServer = PrimusTransport.createServer();\nvar tlsServer = TlsTransport.createServer();\nvar tcpServer = TcpTransport.createServer();\n\nprimusServer.on('connection', bridgeConnection);\ntlsServer.on('connection', bridgeConnection);\ntcpServer.on('connection', bridgeConnection);\n\nfunction bridgeConnection(connection) {\n  var bridge = new Bridge(\n    new MqttConnection(connection),\n    new Client({port: MOSQUITTO_PORT}, Adapter)\n  );\n\n  bridge.connect();\n}\n```\n\n## Connection\n\nA Protocol connection implements a specific pubsub protocol in Node.js for use by strong-pubsub-bridge.\n\n## Architecture\n\nThis diagram illustrates how messages flow between clients, bridges, servers and brokers.\nThe blue arrows represent a message published to a topic. The green arrow represents the message\nbeing sent to a subscriber.\n\n![Pubsub Architecture](https://github.com/strongloop/strong-pubsub/raw/master/assets/pubsub-arch.png?v2 \"Pubsub Architecture\")\n\n## Modules / Plugins\n\n- [strong-pubsub-bridge](http://github.com/strongloop/strong-pubsub-bridge)\n- [strong-pubsub-mqtt](http://github.com/strongloop/strong-pubsub-mqtt)\n- [strong-pubsub-redis](http://github.com/strongloop/strong-pubsub-redis)\n- [strong-pubsub-connection-mqtt](http://github.com/strongloop/strong-pubsub-connection-mqtt)\n\n## Examples\n\n[See the strong-pubsub-example repo.](http://github.com/strongloop/strong-pubsub-example)\n","funding_links":[],"categories":["JavaScript","Protocol Library"],"sub_categories":["MQTT"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrongloop%2Fstrong-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrongloop%2Fstrong-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrongloop%2Fstrong-pubsub/lists"}