{"id":23790033,"url":"https://github.com/blackglory/pubsub","last_synced_at":"2025-10-26T10:47:34.081Z","repository":{"id":44964918,"uuid":"302511828","full_name":"BlackGlory/pubsub","owner":"BlackGlory","description":"🌳","archived":false,"fork":false,"pushed_at":"2025-10-15T11:33:45.000Z","size":3085,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T10:47:33.475Z","etag":null,"topics":["docker-image","esm","microservice","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/blackglory/pubsub","language":"TypeScript","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/BlackGlory.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-10-09T02:24:27.000Z","updated_at":"2025-10-15T11:33:49.000Z","dependencies_parsed_at":"2024-02-15T08:45:58.198Z","dependency_job_id":null,"html_url":"https://github.com/BlackGlory/pubsub","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/BlackGlory/pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fpubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fpubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fpubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fpubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlackGlory","download_url":"https://codeload.github.com/BlackGlory/pubsub/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackGlory%2Fpubsub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281092771,"owners_count":26442440,"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-10-26T02:00:06.575Z","response_time":61,"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":["docker-image","esm","microservice","nodejs","typescript"],"created_at":"2025-01-01T17:18:11.280Z","updated_at":"2025-10-26T10:47:34.056Z","avatar_url":"https://github.com/BlackGlory.png","language":"TypeScript","readme":"# PubSub\n提供基于HTTP的PubSub服务,\n受到[patchbay], [smee.io]和[hookbot]启发.\n\n[patchbay]: https://patchbay.pub/\n[smee.io]: https://smee.io/\n[hookbot]: https://github.com/sensiblecodeio/hookbot\n\n## Install\n### 从源代码运行\n```sh\ngit clone https://github.com/BlackGlory/pubsub\ncd pubsub\nyarn install\nyarn build\nyarn bundle\nyarn --silent start\n```\n\n### 从源代码构建\n```sh\ngit clone https://github.com/BlackGlory/pubsub\ncd pubsub\nyarn install\nyarn docker:build\n```\n\n### Recipes\n#### docker-compose.yml\n```yaml\nversion: '3.8'\n\nservices:\n  pubsub:\n    image: 'blackglory/pubsub'\n    restart: always\n    ports:\n      - '8080:8080'\n```\n\n## API\n### publish\n`POST /namespaces/\u003cnamespace\u003e/channels/\u003cchannel\u003e`\n\n往特定频道发布消息, 所有订阅此频道的客户端都会收到消息.\n\n发送JSON:\n```\nJSONValue\n```\n\n#### Example\n##### curl\n```sh\ncurl \\\n  --header \"Content-Type: application/json\" \\\n  --data \"$payload\" \\\n  \"http://localhost:8080/namespaces/$namespace/channels/$channel\"\n```\n\n##### JavaScript\n```js\nfetch(`http://localhost:8080/namespaces/${namespace}/channels/${channel}`, {\n  method: 'POST'\n, headers: {\n    'Content-Type': 'application/json'\n  }\n, body: JSON.stringify(content)\n})\n```\n\n### subscribe\n`GET /namespaces/\u003cnamespace\u003e/channels/\u003cchannel\u003e`\n\n通过Server-Sent Events(SSE)订阅特定频道.\n\n收到的每条JSON:\n```\nJSONValue\n```\n\n#### Example\n##### sse-cat\n```sh\nsse-cat \"http://localhost:8080/namespaces/$namespace/channels/$channel\"\n```\n\n##### JavaScript\n```js\nconst es = new EventSource(\n  `http://localhost:8080/namespaces/${namespace}/channels/${channel}`\n)\nes.addEventListener('message', event =\u003e {\n  const payload = event.data\n  const content = JSON.parse(payload)\n  console.log(content)\n})\n```\n\n## 环境变量\n### `PUBSUB_HOST`, `PUBSUB_PORT`\n通过环境变量`PUBSUB_HOST`和`PUBSUB_PORT`决定服务器监听的地址和端口,\n默认值为`localhost`和`8080`.\n\n### heartbeat\n#### `PUBSUB_SSE_HEARTBEAT_INTERVAL`\n通过环境变量`PUBSUB_SSE_HEARTBEAT_INTERVAL`可以设置SSE心跳包的发送间隔, 单位为毫秒.\n在默认情况下, 服务不会发送SSE心跳包,\n此时半开连接的检测依赖于服务端和客户端的运行平台的TCP Keepalive配置.\n\n当`PUBSUB_SSE_HEARTBEAT_INTERVAL`大于零时,\n服务会通过SSE的heartbeat事件按指定间隔时间发送空白数据.\n客户端若要实现半开连接检测, 则需要自行根据heartbeat事件设定计时器, 以判断连接是否正常.\n\n## 客户端\n- JavaScript/TypeScript(Node.js, Browser): \u003chttps://github.com/BlackGlory/pubsub-js\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackglory%2Fpubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblackglory%2Fpubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackglory%2Fpubsub/lists"}