{"id":28000414,"url":"https://github.com/nitely/nim-hyps","last_synced_at":"2025-05-08T23:52:42.267Z","repository":{"id":288488771,"uuid":"964827870","full_name":"nitely/nim-hyps","owner":"nitely","description":"Async pub/sub client and server","archived":false,"fork":false,"pushed_at":"2025-05-05T23:50:16.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-08T23:52:35.225Z","etag":null,"topics":["nim","pubsub"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/nitely.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2025-04-11T21:21:34.000Z","updated_at":"2025-05-06T20:49:43.000Z","dependencies_parsed_at":"2025-04-18T10:44:14.272Z","dependency_job_id":"15c83ae6-a5f3-44f0-80c2-c35cc476ac7e","html_url":"https://github.com/nitely/nim-hyps","commit_stats":null,"previous_names":["nitely/nim-hyps"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitely%2Fnim-hyps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitely%2Fnim-hyps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitely%2Fnim-hyps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitely%2Fnim-hyps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nitely","download_url":"https://codeload.github.com/nitely/nim-hyps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166482,"owners_count":21864470,"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":["nim","pubsub"],"created_at":"2025-05-08T23:52:41.718Z","updated_at":"2025-05-08T23:52:42.251Z","avatar_url":"https://github.com/nitely.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hyps\n\nHyps is an async pub/sub client and server.\n\n\u003e [!WARNING]\n\u003e This is Work In Progress; APIs are not stable and will change in patch versions without deprecation.\n\n## What\n\nThis pub/sub offers:\n\n- Concurrent subscriptions, publishing, and message delivery over a single connection through multiplexing.\n- Support for multiple subscribers using a single client instance (socket).\n- Support for dynamic subscriptions.\n- Automatic batching and pipelining for all operations.\n- At-most-once delivery: messages may be lost if they are produced significantly faster than they are consumed, as the buffer will eventually fill up and start dropping messages.\n- ACKs for both subscriptions and published messages.\n- Messages are received in the order they were published.\n- No persistence: messages are delivered only to subscribers who are actively connected at the time of publication.\n- No message delivery retries: messages are real-time only.\n\nIf you care about receving all messages, you may store them in a persistent storage on your own before publish, detect when there is a gap in the received messages, and fetch them from storage. Alternatively use a *log/stream* (kafka, redis streams, etc) instead of a pub/sub, which makes other trade-offs.\n\n## Refc only\n\nFor now this only supports refc and so it requires compiling with `--mm:refc`. The `--mm:orc` cycle collector is not supported for now. Pls, do not open issues related to orc.\n\n## Message format\n\nThe messages are batched/concatenated in `len(msg) \u0026 \"channel_name\\n\" \u0026 \"message\\n\"` format. The first 4 bytes contain the rest of the message length. This detail can be used for performance reasons.\n\n## Usage\n\nServer:\n\n```nim\nimport std/asyncdispatch\nimport hyps/server\n\nproc main {.async.} =\n  echo \"Serving forever\"\n  await serve(\"127.0.0.1\", Port 8787)\n\nwaitFor main()\n```\n\n^make sure not to start more than one server instance; which is allowed at the moment but it should not.\n\nClient:\n\n```nim\nimport std/sequtils\nimport std/asyncdispatch\nimport hyps/client\n\nproc main {.async.} =\n  let pb = newPubsub(\"127.0.0.1\", Port 8787)\n  with pb:\n    let sub = newSubscriber()\n    await pb.subscribe(sub, @[\"foo_ch\"])\n    await pb.publish(\"foo_ch\", \"foo_msg\")\n    await pb.readMessages(sub)\n    doAssert sub.messages == \"\\x00\\x00\\x00\\x0Ffoo_ch\\nfoo_msg\\n\"\n    doAssert toSeq(sub.messages.records) == @[(\"foo_ch\", \"foo_msg\")]\n    sub.messages.setLen 0  # clear buffer\n\nwaitFor main()\n```\n\nUse `await pf.connect()` and `await pf.shutdown()` instead of `with` for unstructured programming.\n\n## Proper usage\n\nFor servers using this library:\n\n- Create one pub/sub client instance per server instance.\n- Create one subscription per user connecting (usually through SSE or WS) to the server.\n- Use the subscription for subscribing to channels and receiving messages.\n- Use the pub/sub client instance to send messages.\n\nThis way you can have a massive amount of subscribers (users) all sharing the same client instance (socket) per server. A fleet of servers all connected to one single hyps instance. This scales decently well out of the box, without the need of extra proxies in order to support more users.\n\n## Prolog, httpx, etc\n\nThese web frameworks (AFAIK) don't play nice with structured programming. The way you would use this library is probably using a `{.threadvar.}` to store the `newPubsub` result and `connect/shutdown` on first usage initialization. Then use a single pub/sub connection per server instance, which is fine. Do not use a global var, since that get shared per server instance (thread); yes, prolog/httpx starts an event-loop per CPU by default.\n\nI'll try to provide examples later, but PRs are welcome.\n\n## Sync usage\n\nUsing `waitFor` to make this library API (subscribe, publish, etc) synchronous won't work as expected. This is not supported, and it won't be supported either.\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitely%2Fnim-hyps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitely%2Fnim-hyps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitely%2Fnim-hyps/lists"}