{"id":20277857,"url":"https://github.com/bunnysakura/cppzmq-ipc","last_synced_at":"2025-09-22T14:30:56.768Z","repository":{"id":170495746,"uuid":"635302828","full_name":"BunnySakura/cppzmq-ipc","owner":"BunnySakura","description":"一个基于ZeroMQ实现的订阅发布机制IPC通信库。","archived":false,"fork":false,"pushed_at":"2024-03-14T02:34:38.000Z","size":65,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-14T13:20:29.569Z","etag":null,"topics":["cppzmq","ipc","middleware","zeromq","zmq"],"latest_commit_sha":null,"homepage":"","language":"C++","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/BunnySakura.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-02T12:07:30.000Z","updated_at":"2024-10-24T06:24:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"ea296f95-6690-44b0-927b-6b35bb98dbe0","html_url":"https://github.com/BunnySakura/cppzmq-ipc","commit_stats":null,"previous_names":["bunnysakura/zmq_ipc","bunnysakura/cppzmq-ipc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Fcppzmq-ipc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Fcppzmq-ipc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Fcppzmq-ipc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BunnySakura%2Fcppzmq-ipc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BunnySakura","download_url":"https://codeload.github.com/BunnySakura/cppzmq-ipc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233856624,"owners_count":18740988,"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":["cppzmq","ipc","middleware","zeromq","zmq"],"created_at":"2024-11-14T13:20:01.764Z","updated_at":"2025-09-22T14:30:56.606Z","avatar_url":"https://github.com/BunnySakura.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cppzmq-ipc\n\n一个基于[ZeroMQ]实现的订阅发布机制**IPC**通信库。\n\n## 开始\n\n### 1. zmq_ipc\n\n```c++\n#include \"zmq_ipc.h\"\n\nint main(){\n  ZmqIpc zipc;\n  auto callback = [](const std::string \u0026topic, const std::vector\u003cuint8_t\u003e \u0026message) {\n    std::cout \u003c\u003c topic \u003c\u003c std::endl;\n    for (auto \u0026byte : message) {\n      // 处理消息\n    }\n  };\n  zipc.Init(callback, 8, \"tcp://localhost:5556\", \"tcp://localhost:5555\");\n  zipc.Subscribe(\"hello\"); // 订阅主题为“hello”的消息\n  zipc.Publish(\"hello\", {'w', 'o', 'r', 'l', 'd'}); // 发送主题为“hello”的消息，消息内容为“world\"\n  zipc.Unsubscribe(\"hello\"); // 取消订阅主题为“hello”的消息\n}\n```\n\n### 2. zmq_proxy\n\n**消息发布订阅的中继代理。**\n\n```shell\nA relay agent for subscriptions and publications\nUsage:\n  zmq_proxy [OPTION...]\n\n  -h, --help            Print usage\n  -d, --debug           Enable debugging\n  -v, --version         Print version information and then exit\n  -t, --tcp             Use TCP as the channel\n  -i, --ipc             Use IPC as the channel\n  -s, --subscriber arg  Subscriber, such as \"ipc:///tmp/zmq_proxy_pub\" or \n                        \"tcp://*:5555\"\n  -p, --publisher arg   Publisher, such as \"ipc:///tmp/zmq_proxy_sub\" or \n                        \"tcp://*:5556\"\n```\n\n## 设计\n\n初始的`Pub-sub`通信方式实现了一个发布者，多个订阅者的通信模型，但是如果存在多个发布者和多个订阅者时，就会让链路变复杂。\n\n于是设置中继代理，让所有服务发布消息到代理的订阅端口；同时所有服务也从代理的发布端口接收广播。\n\n而代理的功能就是把所有来自订阅端口的消息转发到发布端口。\n\n```mermaid\ngraph LR\n    subgraph Proxy\n    ProxySub --\u003e ProxyPub\n    end\n\n    subgraph Publisher\n        A(Service A) --\u003e ProxySub\n        B(Service B) --\u003e ProxySub\n        C(Service C) --\u003e ProxySub\n    end\n\n    subgraph Subscriber\n    ProxyPub --\u003e D(Service A)\n    ProxyPub --\u003e E(Service B)\n    ProxyPub --\u003e F(Service C)\n    end\n```\n\n[ZeroMQ]: https://zeromq.org/ \"ZeroMQ\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunnysakura%2Fcppzmq-ipc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbunnysakura%2Fcppzmq-ipc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbunnysakura%2Fcppzmq-ipc/lists"}