{"id":37109884,"url":"https://github.com/tinh-tinh/pubsub","last_synced_at":"2026-01-14T13:03:37.498Z","repository":{"id":260201869,"uuid":"873040701","full_name":"tinh-tinh/pubsub","owner":"tinh-tinh","description":"🔔 Pubsub for Tinh Tinh framework","archived":false,"fork":false,"pushed_at":"2025-09-01T12:45:22.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-01T14:38:24.583Z","etag":null,"topics":["framework","golang","pubsub"],"latest_commit_sha":null,"homepage":"https://tinh-tinh.github.io/docs/docs/intergrations/pubsub","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/tinh-tinh.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-15T13:58:29.000Z","updated_at":"2025-09-01T12:45:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"3a7ef584-7edd-497d-bc8e-dc85c0e7de31","html_url":"https://github.com/tinh-tinh/pubsub","commit_stats":null,"previous_names":["tinh-tinh/pubsub"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/tinh-tinh/pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinh-tinh%2Fpubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinh-tinh%2Fpubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinh-tinh%2Fpubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinh-tinh%2Fpubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinh-tinh","download_url":"https://codeload.github.com/tinh-tinh/pubsub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinh-tinh%2Fpubsub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["framework","golang","pubsub"],"created_at":"2026-01-14T13:03:36.855Z","updated_at":"2026-01-14T13:03:37.485Z","avatar_url":"https://github.com/tinh-tinh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PubSub for Tinh Tinh\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg alt=\"GitHub Release\" src=\"https://img.shields.io/github/v/release/tinh-tinh/pubsub\"\u003e\n\u003cimg alt=\"GitHub License\" src=\"https://img.shields.io/github/license/tinh-tinh/pubsub\"\u003e\n\u003ca href=\"https://codecov.io/gh/tinh-tinh/pubsub\" \u003e \n \u003cimg src=\"https://codecov.io/gh/tinh-tinh/pubsub/graph/badge.svg?token=TS4B5QAO3T\"/\u003e \n\u003c/a\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/tinh-tinh/pubsub\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/tinh-tinh/pubsub.svg\" alt=\"Go Reference\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://avatars.githubusercontent.com/u/178628733?s=400\u0026u=2a8230486a43595a03a6f9f204e54a0046ce0cc4\u0026v=4\" width=\"200\" alt=\"Tinh Tinh Logo\"\u003e\n\u003c/div\u003e\n\n## Overview\n\nPubSub is a modular, in-memory publish/subscribe (pubsub) system for the Tinh Tinh framework. It enables decoupled communication between different parts of your application using topics and message subscribers.\n\n## Install \n\n```bash\ngo get -u github.com/tinh-tinh/pubsub/v2\n```\n\n## Features\n\n- **Central Broker:** Manages topics and subscribers.\n- **Dynamic Subscribers:** Subscribe to one or many topics dynamically.\n- **Asynchronous Messaging:** Message delivery is non-blocking.\n- **Topic Patterns:** Supports wildcards and topic delimiters for pattern-based subscriptions.\n- **Broadcast Support:** Broadcast a message to all subscribers.\n- **Integration with Tinh Tinh Modules:** Use dependency injection for broker and subscribers.\n- **Subscriber Limits:** Optionally limit the max number of subscribers.\n- **Handler Utility:** Simplifies listening to topics with concise functions and is the recommended way to consume messages.\n\n## Basic Usage\n\n### 1. Register the Broker\n\n```go\nimport \"github.com/tinh-tinh/pubsub/v2\"\n\npubsubModule := pubsub.ForRoot(pubsub.BrokerOptions{\n    // Optional: MaxSubscribers, Wildcard, Delimiter, etc.\n})\n```\n\n### 2. Register Subscribers (Feature Modules)\n\nSubscribe to specific topics:\n\n```go\npriceSubModule := pubsub.ForFeature(\"BTC\", \"ETH\") // subscribe to multiple topics\n```\n\n### 3. Use Handler for Consumption (Recommended)\n\n**Instead of using `subscriber.GetMessages()` or `Listener`, use the Handler utility for subscribing to topics and consuming messages.**\n\n```go\nimport (\n    \"github.com/tinh-tinh/pubsub/v2\"\n    \"github.com/tinh-tinh/tinhtinh/v2/core\"\n)\n\ntype PriceService struct {\n    Message interface{}\n}\n\npriceService := func(module core.Module) core.Provider {\n    return module.NewProvider(core.ProviderOptions{\n        Name:  \"PriceService\",\n        Value: \u0026PriceService{},\n    })\n}\n\npriceHandler := func(module core.Module) core.Provider {\n    handler := pubsub.NewHandler(module)\n    priceService := module.Ref(\"PriceService\").(*PriceService)\n\n    handler.Listen(func(msg *pubsub.Message) {\n        priceService.Message = msg.GetContent()\n    }, \"BTC\", \"ETH\", \"SOL\")\n\n    return handler\n}\n```\n\n### 4. Use in Controllers\n\n```go\ncontroller := func(module core.Module) core.Controller {\n    ctrl := module.NewController(\"prices\")\n\n    ctrl.Post(\"\", func(ctx core.Ctx) error {\n        broker := pubsub.InjectBroker(module)\n        go broker.Publish(\"BTC\", \"hihi\")\n        return ctx.JSON(core.Map{\"data\": \"ok\"})\n    })\n\n    ctrl.Get(\"\", func(ctx core.Ctx) error {\n        service := module.Ref(\"PriceService\").(*PriceService)\n        return ctx.JSON(core.Map{\"data\": service.Message})\n    })\n\n    return ctrl\n}\n```\n\n## Contributing\n\nWe welcome contributions! Please feel free to submit a Pull Request.\n\n## Support\n\nIf you encounter any issues or need help, you can:\n- Open an issue in the GitHub repository\n- Check our documentation\n- Join our community discussions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinh-tinh%2Fpubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinh-tinh%2Fpubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinh-tinh%2Fpubsub/lists"}