{"id":23141684,"url":"https://github.com/zekrotja/eventbus","last_synced_at":"2025-04-04T11:22:42.982Z","repository":{"id":41145226,"uuid":"508317094","full_name":"zekroTJA/eventbus","owner":"zekroTJA","description":"A go package to send and receive pub-sub messages using channels.","archived":false,"fork":false,"pushed_at":"2022-06-28T21:46:56.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T17:53:29.766Z","etag":null,"topics":["event-driven","eventbus","events","go","go118","gogeneric","hacktoberfest","pubsub"],"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/zekroTJA.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}},"created_at":"2022-06-28T13:45:51.000Z","updated_at":"2022-10-01T16:14:22.000Z","dependencies_parsed_at":"2022-09-13T00:34:15.377Z","dependency_job_id":null,"html_url":"https://github.com/zekroTJA/eventbus","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Feventbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Feventbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Feventbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zekroTJA%2Feventbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zekroTJA","download_url":"https://codeload.github.com/zekroTJA/eventbus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166930,"owners_count":20894821,"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":["event-driven","eventbus","events","go","go118","gogeneric","hacktoberfest","pubsub"],"created_at":"2024-12-17T14:14:11.146Z","updated_at":"2025-04-04T11:22:42.948Z","avatar_url":"https://github.com/zekroTJA.png","language":"Go","readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003e~ eventbus ~\u003c/h1\u003e\n    \u003cstrong\u003eA go package to send and receive pub-sub messages using channels.\u003c/strong\u003e\u003cbr\u003e\u003cbr\u003e\n    \u003ca href=\"https://pkg.go.dev/github.com/zekrotja/eventbus\"\u003e\u003cimg src=\"https://godoc.org/github.com/zekrotja/eventbus?status.svg\" /\u003e\u003c/a\u003e\u0026nbsp;\n    \u003ca href=\"https://github.com/zekrotja/eventbus/actions/workflows/tests.yml\" \u003e\u003cimg src=\"https://github.com/zekroTJA/eventbus/actions/workflows/tests.yml/badge.svg\" /\u003e\u003c/a\u003e\u0026nbsp;\n    \u003ca href=\"https://coveralls.io/github/zekrotja/eventbus\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/zekrotja/eventbus/badge.svg\" /\u003e\u003c/a\u003e\u0026nbsp;\n    \u003ca href=\"https://goreportcard.com/report/github.com/zekrotja/eventbus\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/zekrotja/eventbus\"/\u003e\u003c/a\u003e\n\u003cbr\u003e\n\u003c/div\u003e\n\n---\n\n\u003cdiv align=\"center\"\u003e\n    \u003ccode\u003ego get -u github.com/zekrotja/eventbus\u003c/code\u003e\n\u003c/div\u003e\n\n---\n\n## Intro\n\nThis package provides a very simple, generic pub-sub event bus to simplify sending event \nmessages between services using channels.\n\n### Why using channels over callbacks?\n\nCallback are - in my opinion - not a very clean and performant way to perform event driven\ndevelopment in Go because, in contrast to languages like JavaScript, Go is not an event\ndriven language. This can lead to blocking publisher routines while waiting for the execution\nof callbacks on the side of subscribers. Channels, which are well designed to communicate\nbetween go routines in the first place, are therefore a way better tool to achieve easy, performant\nand intuitive communication of events between publishers and subscribers.\n\n## Basic Example\n\n```go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/zekrotja/eventbus\"\n)\n\nfunc subscriber(name string, bus *eventbus.EventBus[string]) {\n\tc, _ := bus.Subscribe()\n\tfor msg := range c {\n\t\tfmt.Printf(\"[ -\u003e %s ]: %s\\n\", name, msg)\n\t}\n}\n\nfunc main() {\n\ts := bufio.NewScanner(os.Stdin)\n\tbus := eventbus.New[string]()\n\n\tgo subscriber(\"service1\", bus)\n\tgo subscriber(\"service2\", bus)\n\n\tbus.SubscribeFunc(func(s string) {\n\t\tif s == \"exit\" {\n\t\t\tos.Exit(0)\n\t\t}\n\t})\n\n\tfmt.Println(\"Publish messages by writing them to the console.\\nPress CTRL+C or write 'exit' to exit.\")\n\tfor s.Scan() {\n\t\tbus.Publish(s.Text())\n\t}\n}\n```\n\nFurther examples can be found in the [examples](examples/) directory. If you want to take alook at a\npractical example, feel free to explore my project [Yuri69](https://github.com/zekrotja/yuri69) which\nheavily depends on EventBus.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzekrotja%2Feventbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzekrotja%2Feventbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzekrotja%2Feventbus/lists"}