{"id":13413397,"url":"https://github.com/stanipetrosyan/go-eventbus","last_synced_at":"2026-06-12T05:31:16.484Z","repository":{"id":65211545,"uuid":"549166298","full_name":"stanipetrosyan/go-eventbus","owner":"stanipetrosyan","description":"Event Bus package for Go","archived":false,"fork":false,"pushed_at":"2024-08-26T14:34:16.000Z","size":76,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-26T16:58:22.446Z","etag":null,"topics":["eventbus","go","golang","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/stanipetrosyan.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":"2022-10-10T19:25:21.000Z","updated_at":"2024-08-26T14:20:13.000Z","dependencies_parsed_at":"2024-03-18T15:03:34.330Z","dependency_job_id":"27592a04-80dc-43bd-81d0-9f92b4899183","html_url":"https://github.com/stanipetrosyan/go-eventbus","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanipetrosyan%2Fgo-eventbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanipetrosyan%2Fgo-eventbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanipetrosyan%2Fgo-eventbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanipetrosyan%2Fgo-eventbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanipetrosyan","download_url":"https://codeload.github.com/stanipetrosyan/go-eventbus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498743,"owners_count":16833055,"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":["eventbus","go","golang","hacktoberfest","pubsub"],"created_at":"2024-07-30T20:01:39.386Z","updated_at":"2026-06-12T05:31:16.462Z","avatar_url":"https://github.com/stanipetrosyan.png","language":"Go","funding_links":[],"categories":["消息","Messaging"],"sub_categories":["检索及分析资料库","Search and Analytic Databases"],"readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/stanipetrosyan/go-eventbus)](https://goreportcard.com/report/github.com/stanipetrosyan/go-eventbus)\n[![codecov](https://codecov.io/gh/stanipetrosyan/go-eventbus/graph/badge.svg?token=YAGXYA64E6)](https://codecov.io/gh/stanipetrosyan/go-eventbus)\n[![Go Reference](https://pkg.go.dev/badge/github.com/stanipetrosyan/go-eventbus.svg)](https://pkg.go.dev/github.com/stanipetrosyan/go-eventbus)\n![workflow](https://github.com/StaniPetrosyan/go-eventbus/actions/workflows/test.yml/badge.svg)\n\n# EventBus for Golang\n\n## Description\n\nThis is a simple implementation of an event bus in golang. Actually support follwing pattern:\n\n- [x] publish/subscribe\n- [x] request/response\n\n## Get Started\n\nTo start use eventbus in your project, you can run the following command.\n\n```\ngo get github.com/stanipetrosyan/go-eventbus\n```\n\nAnd import\n``` go\nimport (\n\tgoeventbus \"github.com/stanipetrosyan/go-eventbus\"\n)\n\n```\n\n## Publish/Subscribe\n\nSimple example of publish/subscribe pattern.\n\n```go\n\neventbus = goeventbus.NewEventBus()\n\naddress := \"topic\"\noptions := goeventbus.NewMessageHeadersBuilder().SetHeader(\"header\", \"value\").Build()\nmessage := goeventbus.NewMessageBuilder().SetPayload(\"Hi Topic\").SetHeaders(options).Build()\n\neventbus.Channel(address).Subscriber().Listen(func(dc goeventbus.Context) {\n\tfmt.Printf(\"Message %s\\n\", dc.Result().Data)\n})\n\neventbus.Channel(address).Publisher().Publish(message)\n```\n\n## Request/Response\n\nSimple example of request/response pattern.\n\n```go\n\neventbus = goeventbus.NewEventBus()\n\naddress := \"topic\"\nmessage := goeventbus.NewMessageBuilder().SetPayload(\"Hi Topic\").Build()\n\neventbus.Channel(address).Subscriber().Listen(func(context goeventbus.Context) {\n\tfmt.Printf(\"Message %s\\n\", context.Result().Extract())\n\tcontext.Reply(\"Hello from subscriber\")\n})\n\neventbus.Channel(address).Publisher().Request(message, func(context goeventbus.Context) {\n\tfmt.Printf(\"Message %s\\n\", context.Result().Extract())\n})\n```\n\n## Message\n\nFor publishing, you need to create a Message object using this method.\n\n```go\nmessage := goeventbus.NewMessageBuilder().SetPayload(\"Hi Topic\").SetHeaders(options).Build()\n```\nEach message can have some options:\n\n```go\n\noptions := goeventbus.NewMessageHeadersBuilder().SetHeader(\"header\", \"value\").Build()\nmessage := goeventbus.NewMessageBuilder().setHeaders(options).Build()\n\neventBus.Channel(\"address\").Publisher().Publish(message)\n```\n\n## Processor\n\nA processor works like a middleware, in fact forwards messages only if context Next method is called. The entity works as Subscriber: Listen method accept a callback with context.\n\nThe processor intercept message from publisher to subscribers on a specific channel.\n\n```go\neventbus.Channel(\"topic1\").Processor().Listen(func(context goeventbus.Context) {\n\tif context.Result().ExtractHeaders().Contains(\"header\") {\n\t\tcontext.Next()\n\t}\n})\n```\n\nInside processor is possible change message to forward using `Map` method: \n\n```go\neventbus.Channel(\"topic1\").Processor().Listen(func(context goeventbus.Context) {\n\tif context.Result().ExtractHeaders().Contains(\"header\") {\n\t\tnewMessage := NewMessageBuilder().SetPayload(\"new message\").Build()\n\n\t\tcontext.Map(newMessage).Next()\n\t}\n})\n```\n\n## Network Bus\n\nA Network bus create a tcp connection between different services.\n\nNetworkBus is a wrapper of local eventbus.\n\nA simple server/client example is in `examples/networkbus` directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanipetrosyan%2Fgo-eventbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanipetrosyan%2Fgo-eventbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanipetrosyan%2Fgo-eventbus/lists"}