{"id":37133685,"url":"https://github.com/jarvanstack/evbus","last_synced_at":"2026-01-14T15:36:21.440Z","repository":{"id":65732699,"uuid":"596575208","full_name":"jarvanstack/evbus","owner":"jarvanstack","description":"CQRS eventbus golang","archived":false,"fork":false,"pushed_at":"2023-04-08T13:41:17.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-12T05:38:18.469Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/jarvanstack.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}},"created_at":"2023-02-02T13:41:03.000Z","updated_at":"2023-10-08T21:12:41.000Z","dependencies_parsed_at":"2024-06-20T05:48:34.915Z","dependency_job_id":"ae40b82a-70c2-4f6d-9dab-d1aeed47e2fa","html_url":"https://github.com/jarvanstack/evbus","commit_stats":null,"previous_names":["dengjiawen8955/evbus"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jarvanstack/evbus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvanstack%2Fevbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvanstack%2Fevbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvanstack%2Fevbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvanstack%2Fevbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jarvanstack","download_url":"https://codeload.github.com/jarvanstack/evbus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvanstack%2Fevbus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28424374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2026-01-14T15:36:20.641Z","updated_at":"2026-01-14T15:36:21.433Z","avatar_url":"https://github.com/jarvanstack.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# evbus\n\nPackage evbus is the little and lightweight eventbus with async compatibility for GoLang.\n\n## Installation\n\nMake sure that Go is installed on your computer.\nType the following command in your terminal:\n\n\tgo get github.com/jarvanstack/evbus\n\nAfter it the package is ready to use.\n\n## Import package in your project\n\nAdd following line in your `*.go` file:\n\n```go\nimport \"github.com/jarvanstack/evbus\"\n```\n\nIf you unhappy to use long `evbus`, you can do something like this:\n\n```go\nimport (\n\tevbus \"github.com/jarvanstack/evbus\"\n)\n```\n\n## Example\n\n```go\nfunc calculator(a int, b int) {\n\tfmt.Printf(\"%d\\n\", a + b)\n}\n\nfunc main() {\n\tbus := evbus.New();\n\tbus.Subscribe(\"main:calculator\", calculator);\n\tbus.Publish(\"main:calculator\", 20, 40);\n\tbus.Unsubscribe(\"main:calculator\", calculator);\n}\n```\n\n## Implemented methods\n\n* **New()**\n* **Subscribe()**\n* **SubscribeOnce()**\n* **HasCallback()**\n* **Unsubscribe()**\n* **Publish()**\n* **SubscribeAsync()**\n* **SubscribeOnceAsync()**\n* **WaitAsync()**\n\n## New()\n\nNew returns new evbus with empty handlers.\n\n```go\nbus := evbus.New();\n```\n\n## Subscribe(topic string, fn interface{}) error\n\nSubscribe to a topic. Returns error if `fn` is not a function.\n\n```go\nfunc Handler() { ... }\n...\nbus.Subscribe(\"topic:handler\", Handler)\n```\n\n## SubscribeOnce(topic string, fn interface{}) error\n\nSubscribe to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.\n\n```go\nfunc HelloWorld() { ... }\n...\nbus.SubscribeOnce(\"topic:handler\", HelloWorld)\n```\n\n## Unsubscribe(topic string, fn interface{}) error\n\nRemove callback defined for a topic. Returns error if there are no callbacks subscribed to the topic.\n\n```go\nbus.Unsubscribe(\"topic:handler\", HelloWord);\n```\n\n## HasCallback(topic string) bool\n\nReturns true if exists any callback subscribed to the topic.\n\n## Publish(topic string, args ...interface{})\n\nPublish executes callback defined for a topic. Any additional argument will be transferred to the callback.\n\n```go\nfunc Handler(str string) { ... }\n...\nbus.Subscribe(\"topic:handler\", Handler)\n...\nbus.Publish(\"topic:handler\", \"Hello, World!\");\n```\n\n## SubscribeAsync(topic string, fn interface{}, transactional bool)\n\nSubscribe to a topic with an asynchronous callback. Returns error if `fn` is not a function.\n\n```go\nfunc slowCalculator(a, b int) {\n\ttime.Sleep(3 * time.Second)\n\tfmt.Printf(\"%d\\n\", a + b)\n}\n\nbus := evbus.New()\nbus.SubscribeAsync(\"main:slow_calculator\", slowCalculator, false)\n\nbus.Publish(\"main:slow_calculator\", 20, 60)\n\nfmt.Println(\"start: do some stuff while waiting for a result\")\nfmt.Println(\"end: do some stuff while waiting for a result\")\n\nbus.WaitAsync() // wait for all async callbacks to complete\n\nfmt.Println(\"do some stuff after waiting for result\")\n```\n\nTransactional determines whether subsequent callbacks for a topic are run serially (true) or concurrently(false)\n\n## SubscribeOnceAsync(topic string, args ...interface{})\n\nSubscribeOnceAsync works like SubscribeOnce except the callback to executed asynchronously\n\n## WaitAsync()\n\nWaitAsync waits for all async callbacks to complete.\n\n## Cross Process Events\n\nWorks with two rpc services:\n\n* a client service to listen to remotely published events from a server\n* a server service to listen to client subscriptions\n\nserver.go\n\n```go\nvar (\n    netAAddr = \":2050\"\n    netAPath = \"/_net_bus_A\"\n    netBAddr = \":2055\"\n    netBPath = \"/_net_bus_B\"\n)\n\nfmt.Printf(\"Start\\n\")\n\nnetA := NewNetworkBus(netAAddr, netAPath)\nnetA.Start()\nnetB := NewNetworkBus(netBAddr, netBPath)\nnetB.Start()\n\n// netA 推送 netB 消费\nnetB.Subscribe(\"event1\", func(a int) {\n    fmt.Printf(\"[netA 推送 netB 消费] %d \\n\", a)\n}, netAAddr, netAPath)\nnetA.EventBus().Publish(\"event1\", 10)\n\n// netB 推送 netA 消费\nnetA.Subscribe(\"event2\", func(a int) {\n    fmt.Printf(\"[netB 推送 netA 消费] %d \\n\", a)\n}, netBAddr, netBPath)\nnetB.EventBus().Publish(\"event2\", 10)\n\n// netA 推送 netA 本地消费\nnetA.EventBus().Subscribe(\"event3\", func(a int) {\n    fmt.Printf(\"[netA 推送 netA 本地消费] %d \\n\", a)\n})\nnetA.EventBus().Publish(\"event3\", 10)\n\n// netA 推送 netA 本地查询\nnetA.EventBus().Subscribe(\"query1\", func(result *int) {\n    *result = 10\n    return\n})\nvar result int\nnetA.EventBus().Publish(\"query1\", \u0026result)\nfmt.Printf(\"[netA 推送 netA 本地查询] %d \\n\", result)\n\n// netA 推送 netB 查询 (panic)\n// netB.Subscribe(\"query2\", func(result *int) {\n// \t*result = 10\n// \treturn\n// }, netAAddr, netAPath)\n// var result2 int\n// netA.EventBus().Publish(\"query2\", \u0026result2)\n// fmt.Printf(\"[netA 推送 netB 查询] %d \\n\", result2)\n\nnetA.Stop()\nnetB.Stop()\n```\n\nclient.go\n\n```go\nfunc main() {\n    client := NewClient(\":2015\", \"/_client_bus_\", New())\n    client.Start()\n    client.Subscribe(\"main:calculator\", calculator, \":2010\", \"/_server_bus_\")\n    // ...\n    client.Stop()\n}\n```\n\n## Notes\n\nDocumentation is available here: [godoc.org](https://godoc.org/github.com/jarvanstack/evbus).\nFull information about code coverage is also available here: [evbus on gocover.io](http://gocover.io/github.com/jarvanstack/evbus).\n\n## Support\n\nIf you do have a contribution for the package feel free to put up a Pull Request or open Issue.\n\n## Special thanks to [contributors](https://github.com/jarvanstack/evbus/graphs/contributors)\n\n* [Brian Downs](https://github.com/briandowns)\n* [Dominik Schulz](https://github.com/gittex)\n* [bennAH](https://github.com/bennAH)\n* [John Noble] (\u003chttps://github.com/gaxunil\u003e)\n* [Evan Borgstrom] (\u003chttps://github.com/borgstrom\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarvanstack%2Fevbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjarvanstack%2Fevbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarvanstack%2Fevbus/lists"}