{"id":20214774,"url":"https://github.com/raezil/goeventbus","last_synced_at":"2025-04-10T14:10:26.480Z","repository":{"id":255361373,"uuid":"849363374","full_name":"Raezil/GoEventBus","owner":"Raezil","description":"Event sourcing library in Go","archived":false,"fork":false,"pushed_at":"2025-04-04T11:19:46.000Z","size":229,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-04T12:25:02.146Z","etag":null,"topics":["event-driven","eventsourcing","golang","library","rabbitmq"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"xhd2015/GOEventBus-fork","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Raezil.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-08-29T13:13:20.000Z","updated_at":"2025-04-04T11:19:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c0616bf-0ac4-481d-9ab8-36df71abcc80","html_url":"https://github.com/Raezil/GoEventBus","commit_stats":null,"previous_names":["raezil/goeventbus"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raezil%2FGoEventBus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raezil%2FGoEventBus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raezil%2FGoEventBus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Raezil%2FGoEventBus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Raezil","download_url":"https://codeload.github.com/Raezil/GoEventBus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248232369,"owners_count":21069487,"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","eventsourcing","golang","library","rabbitmq"],"created_at":"2024-11-14T06:18:00.113Z","updated_at":"2025-04-10T14:10:26.468Z","avatar_url":"https://github.com/Raezil.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/Raezil/GoEventBus/blob/main/examples/95a41958-9fd0-4ff9-9770-c2cfd30affb1.jpg?raw=true\"\u003e\n\u003c/p\u003e\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/Raezil/GoEventBus)](https://goreportcard.com/report/github.com/Raezil/GoEventBus)\n[![libs.tech recommends](https://libs.tech/project/849363374/badge.svg)](https://libs.tech/project/849363374/goeventbus)\n\nEventBus is a simple and efficient **event-driven system** for Go applications.  \nIt allows you to **publish** and **subscribe** to events seamlessly.\n\n---\n\n## 📦 Installation\n\nTo install the library, run:\n\n```sh\ngo get github.com/Raezil/GoEventBus\n```\n\n---\n\n## 🚀 Quick Start\n\n### 1️⃣ Initialize a New Project\n\n```sh\nmkdir eventbus-demo\ncd eventbus-demo\ngo mod init eventbus-demo\n```\n\n### 2️⃣ Create `main.go`\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\n\tgbus \"github.com/Raezil/GoEventBus\"\n\t\"github.com/gorilla/mux\"\n)\n\n// HouseWasSold represents an event for a house sale.\ntype HouseWasSold struct{}\n\n// NewDispatcher sets up event handlers.\nfunc NewDispatcher() *gbus.Dispatcher {\n\treturn \u0026gbus.Dispatcher{\n\t\tHouseWasSold{}: func(data map[string]interface{}) (gbus.Result, error) {\n\t\t\tprice, ok := data[\"price\"].(int)\n\t\t\tif !ok {\n\t\t\t\treturn gbus.Result{}, fmt.Errorf(\"invalid or missing 'price'\")\n\t\t\t}\n\t\t\tmessage := fmt.Sprintf(\"House sold for %d!\", price)\n\t\t\tlog.Println(message)\n\t\t\treturn gbus.Result{Message: message}, nil\n\t\t},\n\t}\n}\n\nfunc main() {\n\tdispatcher := NewDispatcher()\n\teventStore := gbus.NewEventStore(dispatcher)\n\n\trouter := mux.NewRouter()\n\trouter.HandleFunc(\"/house-sold\", func(w http.ResponseWriter, r *http.Request) {\n\t\teventStore.Publish(gbus.NewEvent(HouseWasSold{}, map[string]interface{}{\"price\": 100}))\n\t\t\n\t\tif err := eventStore.Broadcast(); err != nil {\n\t\t\tlog.Printf(\"Error broadcasting event: %v\", err)\n\t\t\thttp.Error(w, \"Event processing failed\", http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\t\n\t\tw.Header().Set(\"Content-Type\", \"application/json\")\n\t\tjson.NewEncoder(w).Encode(map[string]string{\"status\": \"House sold event published\"})\n\t})\n\n\tlog.Println(\"Server running on :8080\")\n\tlog.Fatal(http.ListenAndServe(\":8080\", router))\n}\n```\n\n### 3️⃣ Run Your Application\n\n```sh\ngo run main.go\n```\n\nNow, visiting `http://localhost:8080/house-sold` will trigger the event and process it.\n\n---\n\n## 🐇 RabbitMQ Integration\n\n### 1️⃣ Start RabbitMQ\n\n```sh\ndocker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4.0-management\n```\n\n### 2️⃣ Implement Event Publishing in `main.go`\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t. \"github.com/Raezil/GoEventBus\"\n)\n\nfunc NewDispatcher() *RabbitDispatcher {\n\treturn \u0026RabbitDispatcher{\n\t\t\"HouseWasSold\": func(data map[string]interface{}) (Result, error) {\n\t\t\tprice, ok := data[\"price\"].(float64)\n\t\t\tif !ok {\n\t\t\t\treturn Result{}, fmt.Errorf(\"invalid or missing 'price'\")\n\t\t\t}\n\t\t\treturn Result{Message: fmt.Sprintf(\"House sold for %.2f\", price)}, nil\n\t\t},\n\t}\n}\n\nfunc main() {\n\tdispatcher := NewDispatcher()\n\trabbitStore, err := NewRabbitEventStore(dispatcher, \"amqp://guest:guest@localhost:5672/\", \"events_queue\")\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to initialize RabbitEventStore: %v\", err)\n\t}\n\n\trabbitStore.Publish(\u0026Event{Id: \"12345\", Projection: \"HouseWasSold\", Args: map[string]interface{}{\"price\": 100.0}})\n\trabbitStore.Publish(\u0026Event{Id: \"123456\", Projection: \"HouseWasSold\", Args: map[string]interface{}{\"price\": 200.0}})\n\n\tgo rabbitStore.Broadcast()\n\tselect {}\n}\n```\n\n### 3️⃣ Run Your Application\n\n```sh\ngo run main.go\n```\n\n---\n\n## **📜 Contributing**\nWant to improve GoEventBus? 🚀  \n1. Fork the repo  \n2. Create a feature branch (`git checkout -b feature-new`)  \n3. Commit your changes (`git commit -m \"Added feature\"`)  \n4. Push to your branch (`git push origin feature-new`)  \n5. Submit a PR!  \n\n\n\n## 📖 References\n\n- [GoEventBus GitHub Repository](https://github.com/Raezil/GoEventBus)\n- [RabbitMQ Official Documentation](https://www.rabbitmq.com/)\n- [Event Sourcing Overview](https://martinfowler.com/eaaDev/EventSourcing.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraezil%2Fgoeventbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraezil%2Fgoeventbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraezil%2Fgoeventbus/lists"}