{"id":42201002,"url":"https://github.com/yudhasubki/eventpool","last_synced_at":"2026-01-27T00:25:26.463Z","repository":{"id":144653568,"uuid":"535179700","full_name":"yudhasubki/eventpool","owner":"yudhasubki","description":"Fast Go Event Queue with Partitioned Topics \u0026 Broadcast Channels 🚀","archived":false,"fork":false,"pushed_at":"2025-04-04T04:18:14.000Z","size":39,"stargazers_count":17,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T04:19:42.934Z","etag":null,"topics":["concurrency","concurrent","go","golang","pubsub","queue","workerpool"],"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/yudhasubki.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}},"created_at":"2022-09-11T03:24:48.000Z","updated_at":"2025-04-04T04:18:17.000Z","dependencies_parsed_at":"2023-04-20T21:18:00.979Z","dependency_job_id":"334f1070-c9fb-4fe2-9ab5-9396c1c3b551","html_url":"https://github.com/yudhasubki/eventpool","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/yudhasubki/eventpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Feventpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Feventpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Feventpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Feventpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yudhasubki","download_url":"https://codeload.github.com/yudhasubki/eventpool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Feventpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28792959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T21:49:50.245Z","status":"ssl_error","status_checked_at":"2026-01-26T21:48:29.455Z","response_time":59,"last_error":"SSL_read: 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":["concurrency","concurrent","go","golang","pubsub","queue","workerpool"],"created_at":"2026-01-27T00:25:26.376Z","updated_at":"2026-01-27T00:25:26.438Z","avatar_url":"https://github.com/yudhasubki.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## EventPool\n\nThis library provides a high-performance implementation of publish-subscribe pattern in Go with two distinct models:\n\n- **Broadcast Type (Pub-Sub)** - Deliver messages to all subscribers\n- **Partition Type (Queue)** - Distributed message processing with minimal contention\n\n### Partition Type Feature\n#### Smart Partitioning\n- Uses XXH3 hash algorithm for consistent message partitioning\n\t- Automatic key-based partition assignment\n\t- Empty keys use random distribution\n\t- Hashed keys ensure consistent routing\n\n#### Concurrency Optimized\n- Partition-level isolation minimizes lock contention\n- Each partition operates independently\n\n## Features\n- **Topic-Based Pub-Sub**: The library allows publishers to send messages to specific topics. Subscribers can then listen to those topics of interest and receive messages accordingly.\n- **Flexible Communication**: Decouple your application's components by using the publish-subscribe pattern, promoting a more maintainable and scalable architecture.\n- **Efficient and Lightweight**: Built on top of Golang channels, this library is highly performant, making it suitable for resource-constrained environments.\n- **Maximum Retry Limit**: Define a maximum number of retry attempts for a specific operation or task. When this limit is reached, the error hook is triggered to handle the error gracefully.\n- **Error Hooks**: Register custom error hook functions to implement tailored actions when an error occurs. This can include logging the error, sending notifications, triggering fallback mechanisms, or performing any other appropriate response.\n- **Graceful Shutdown**: Implement a reliable and efficient shutdown process, allowing your application to complete ongoing tasks and clean up resources before terminating.\n- **Close Hooks**: Register custom close hooks to execute specific cleanup tasks during the shutdown process. This ensures that essential operations are completed before the application exits.\n- **Panic Recovery**: Put in place a mechanism to recover from panics and prevent your application from crashing.\n- **Recover Hooks**: Register custom recover hooks to execute specific actions when a panic occurs. This allows you to log errors, perform cleanup tasks, or gracefully terminate the application.\n- **Dead Letter Queue**: Integrate a Dead Letter Queue that receives messages that have failed to be processed by subscribers through the Error Hook.\n\n## Installation\n\nTo use this library, make sure you have Go installed and set up a Go workspace.\n\nUse go get to fetch the library:\n\n```bash\ngo get -u github.com/yudhasubki/eventpool\n```\n\n## Usage\nHere's a quick example of how to use the library:\n\n### Event Partition\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/yudhasubki/eventpool\"\n)\n\nfunc main() {\n\teventPart := eventpool.NewPartition(3)\n\tlisteners := []eventpool.EventpoolListener{\n\t\t{\n\t\t\tName:       \"groupA\",\n\t\t\tSubscriber: SendMetrics,\n\t\t},\n\t\t{\n\t\t\tName:       \"groupB\",\n\t\t\tSubscriber: SetCache,\n\t\t},\n\t}\n\n\teventPart.Submit(3, listeners...)\n\teventPart.Run()\n}\n\nfunc SendMetrics(name string, message []byte) error {\n\tpanic(\"recover send metrics function\")\n}\n\nfunc SetCache(name string, message []byte) error {\n\tfmt.Println(name, \" receive message from publisher \", string(message))\n\n\treturn nil\n}\n```\n\n### Event Broadcast\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/yudhasubki/eventpool\"\n)\n\nfunc main() {\n\tevent := eventpool.New()\n\tevent.Submit(\n\t\teventpool.EventpoolListener{\n\t\t\tName:       \"send-metric\",\n\t\t\tSubscriber: SendMetrics,\n\t\t\tOpts: []eventpool.SubscriberConfigFunc{\n\t\t\t\teventpool.RecoverHook(func(name string, job []byte) {\n\n\t\t\t\t\tfmt.Printf(\"[RecoverPanic][%s] message : %v \\n\", name, string(job))\n\t\t\t\t}),\n\t\t\t\teventpool.CloseHook(func(name string) {\n\t\t\t\t\tfmt.Printf(\"[Enter Gracefully Shutdown][%s]\\n\", name)\n\t\t\t\t}),\n\t\t\t},\n\t\t},\n\t\teventpool.EventpoolListener{\n\t\t\tName:       \"set-cache\",\n\t\t\tSubscriber: SetCache,\n\t\t},\n\t)\n\tevent.Run()\n\n\tfor i := 0; i \u003c 10; i++ {\n\t\tgo event.Publish(eventpool.SendString(fmt.Sprintf(\"Order ID [%d] Received \", i)))\n\t}\n\ttime.Sleep(5 * time.Second)\n\n\tevent.CloseBy(\n\t\t\"send-metric\",\n\t\t\"set-cache\",\n\t)\n\n\tfor i := 0; i \u003c 10; i++ {\n\t\tgo func(i int) {\n\t\t\tevent.Publish(eventpool.SendString(fmt.Sprintf(\"Order ID [%d] Received \", i)))\n\t\t}(i)\n\t}\n\n\ttime.Sleep(5 * time.Second)\n\tevent.Close()\n\ttime.Sleep(5 * time.Second)\n}\n\nfunc SendMetrics(name string, message []byte) error {\n\tpanic(\"recover send metrics function\")\n}\n\nfunc SetCache(name string, message []byte) error {\n\n\tfmt.Println(name, \" receive message from publisher \", string(message))\n\n\treturn nil\n}\n```\n\nif you want to add a new listener while the application is already running just do it this simple way:\n\n```go\nevent.SubmitOnFlight(eventpool.EventpoolListener{\n\tName:       \"set-in-the-air\",\n\tSubscriber: SetWorkerInTheAir,\n})\n```\n\nIf you want to handle multiple topics, you can use a simple approach with a struct. For example:\n\n```go\ntype PubSub struct {\n\ttopics map[string]*eventpool.Eventpool\n}\n```\n\n## 🚀 Benchmark Performance\n\n### System Specification\n```text\nOS: darwin (macOS)  \nArch: arm64 (Apple M1)  \nCPU: 8-core (4 performance + 4 efficiency)  \nGo Version: 1.21+\n\nBenchmarkEventSpecificGroupByPartition-8   6710184   221.5 ns/op   8 B/op   1 allocs/op\nBenchmarkSingleEventByBroadcast-8          3252388   386.6 ns/op   8 B/op   1 allocs/op\nBenchmarkEventWildcardByPartition-8        3077424   345.2 ns/op   8 B/op   1 allocs/op  \nBenchmarkMultipleEventByBroadcast-8        2266489   457.7 ns/op   8 B/op   1 allocs/op\n```\n\n### 📊 Throughput Comparison\n\n| Benchmark Mode                  | Operations/sec | Latency       | Memory | Allocs |\n|---------------------------------|----------------|---------------|--------|--------|\n| `SpecificGroupByPartition`      | **6,710,184**  | 221.5 ns/op   | 8 B    | 1      |\n| `SingleEventBroadcast`          | 3,252,388      | 386.6 ns/op   | 8 B    | 1      |\n| `WildcardByPartition`           | 3,077,424      | 345.2 ns/op   | 8 B    | 1      |\n| `MultipleEventBroadcast`        | 2,266,489      | 457.7 ns/op   | 8 B    | 1      |\n\n\n## Contributing\nContributions to this library are welcome! If you find any issues, have suggestions for improvements, or want to add new features, please submit a pull request or create an issue on the GitHub repository.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyudhasubki%2Feventpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyudhasubki%2Feventpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyudhasubki%2Feventpool/lists"}