{"id":18576038,"url":"https://github.com/zacksff/pubsubgo","last_synced_at":"2025-05-16T00:34:42.230Z","repository":{"id":190010247,"uuid":"681768541","full_name":"zacksfF/PubSubGo","owner":"zacksfF","description":"A lightweight, in-memory message bus library written in Golang that facilitates asynchronous communication between different components of an application using the publish-subscribe pattern.","archived":false,"fork":false,"pushed_at":"2024-08-26T18:10:58.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T15:15:48.340Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zacksfF.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":"2023-08-22T18:06:07.000Z","updated_at":"2024-08-26T18:11:02.000Z","dependencies_parsed_at":"2024-08-25T20:54:39.851Z","dependency_job_id":"cd99be41-d57a-469a-8662-72541f7721f0","html_url":"https://github.com/zacksfF/PubSubGo","commit_stats":null,"previous_names":["zacksff/practical-data-preprocessing","zacksff/pubsubgo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksfF%2FPubSubGo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksfF%2FPubSubGo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksfF%2FPubSubGo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zacksfF%2FPubSubGo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zacksfF","download_url":"https://codeload.github.com/zacksfF/PubSubGo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254447833,"owners_count":22072754,"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":[],"created_at":"2024-11-06T23:23:19.561Z","updated_at":"2025-05-16T00:34:42.176Z","avatar_url":"https://github.com/zacksfF.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PubSubGo\nA lightweight, in-memory message bus library written in Golang that facilitates asynchronous communication between different components of an application using the publish-subscribe pattern. Designed for simplicity and efficiency.\n\n## Features\n\n* Simple HTTP API\n* Simple command-line client\n* In memory queues\n* WebSockets for real-time messages\n* Pull and Push model\n* Concurrency Support\n* Thread-Safe\n\n##  Use Cases\n\n- **Microservices Communication**: In a microservices architecture, msgbus can be used to facilitate internal communication between services or components.\n- **Event-Driven Systems**: Applications that rely on event-driven architecture can use msgbus to propagate events between different modules.\n- **Decoupling Components**: When you want to decouple components of a large application, msgbus can be a good choice to enable communication without tight coupling.\n\n## How It Works\n\n- **Publish**: Components publish messages to specific topics on the message bus.\n- **Subscribe**: Other components subscribe to those topics and receive messages asynchronously when they are published.\n- **Handling Messages**: Subscribers define handlers that process incoming messages in a way that suits the application’s needs.\n\n## Install\n\n```#!bash\n$ git clone https://github.com/zacksfF/PubSubGo.git\ncd PubSubGo\nmake test\n```\n\n## Use Cases\n\n\n## Usage (library)\n\n\n```#!go\npackage main\n\nimport (\n    \"log\"\n\n    \"github.com/zacksfF/PubSubGo/pubsub\"\n)\n\nfunc main() {\n    m := pubsub.New()\n    m.Put(\"foo\", m.NewMessage([]byte(\"Hello World!\")))\n\n    msg, ok := m.Get(\"foo\")\n    if !ok {\n        log.Printf(\"No more messages in queue: foo\")\n    } else {\n        log.Printf\n\t    \"Received message: id=%s topic=%s payload=%s\",\n\t    msg.ID, msg.Topic, msg.Payload,\n\t)\n    }\n}\n```\n\nRunning this example should yield something like this:\n\n```#!bash\n$ go run examples/main.go\n2017/08/09 03:01:54 [pubsub] PUT id=0 topic=foo payload=Hello World!\n2017/08/09 03:01:54 [pubsub] NotifyAll id=0 topic=foo payload=Hello World!\n2017/08/09 03:01:54 [pubsub] GET topic=foo\n2017/08/09 03:01:54 Received message: id=%!s(uint64=0) topic=foo payload=Hello World!\n``` \n\n## Usage (tool)\n\nRun the message bus daemon/server:\n\n```#!bash\n$ PubSubGo\n2017/08/07 01:11:16 [msgbus] Subscribe id=[::1]:55341 topic=foo\n2017/08/07 01:11:22 [msgbus] PUT id=0 topic=foo payload=hi\n2017/08/07 01:11:22 [msgbus] NotifyAll id=0 topic=foo payload=hi\n2017/08/07 01:11:26 [msgbus] PUT id=1 topic=foo payload=bye\n2017/08/07 01:11:26 [msgbus] NotifyAll id=1 topic=foo payload=bye\n2017/08/07 01:11:33 [msgbus] GET topic=foo\n2017/08/07 01:11:33 [msgbus] GET topic=foo\n2017/08/07 01:11:33 [msgbus] GET topic=foo\n```\n\nSubscribe to a topic using the message bus client:\n\n```#!bash\n$ PubSubGo sub foo\n2017/08/07 01:11:22 [PubSubGo] received message: id=0 topic=foo payload=hi\n2017/08/07 01:11:26 [PubSubGo] received message: id=1 topic=foo payload=bye\n```\n\n\nYou can also manually pull messages using the client:\n\n```#!bash\n$ PubSubGo pull foo\n2017/08/07 01:11:33 [PubSubGo] received message: id=0 topic=foo payload=hi\n2017/08/07 01:11:33 [PubSubGo] received message: id=1 topic=foo payload=bye\n```\n\n\u003e This is slightly different from a listening subscriber (*using websockets*) where messages are pulled directly.\n\n## Usage (HTTP)\n\nRun the message bus daemon/server:\n\n```#!bash\n$ PubSubGo\n2018/03/25 13:21:18 PubSubGo listening on :8000\n```\n\nSend a message with using `curl`:\n\n```#!bash\n$ curl -q -o - -X PUT -d '{\"message\": \"hello\"}' http://localhost:8000/hello\n```\n\nPull the messages off the \"hello\" queue using `curl`:\n\n```#!bash\n$ curl -q -o - http://localhost:8000/hello\n{\"id\":0,\"topic\":{\"name\":\"hello\",\"ttl\":60000000000,\"seq\":1,\"created\":\"2018-03-25T13:18:38.732437-07:00\"},\"payload\":\"eyJtZXNzYWdlIjogImhlbGxvIn0=\",\"created\":\"2018-03-25T13:18:38.732465-07:00\"}\n```\n\nDecode the payload:\n\n```#!bash\n$ echo 'eyJtZXNzYWdlIjogImhlbGxvIn0=' | base64 -d\n{\"message\": \"hello\"}\n```\n\n## API\n\n### GET /\n\nList all known topics/queues.\n\nExample:\n\n```#!bash\n$ curl -q -o - http://localhost:8000/ | jq '.'\n{\n  \"hello\": {\n    \"name\": \"hello\",\n    \"ttl\": 60000000000,\n    \"seq\": 1,\n    \"created\": \"2018-05-07T23:44:25.681392205-07:00\"\n  }\n}\n```\n\n## POST|PUT /topic\n\nPost a new message to the queue named by `\u003ctopic\u003e`.\n\n**NB:** Either `POST` or `PUT` methods can be used here.\n\nExample:\n\n```#!bash\n$ curl -q -o - -X PUT -d '{\"message\": \"hello\"}' http://localhost:8000/hello\nmessage successfully published to hello with sequence 1\n```\n\n## GET /topic\n\nGet the next message of the queue named by `\u003ctopic\u003e`.\n\n- If the topic is not found. Returns: `404 Not Found`\n- If the Websockets `Upgrade` header is found, upgrades to a websocket channel\n  and subscribes to the topic `\u003ctopic\u003e`. Each new message published to the\n  topic `\u003ctopic\u003e` are instantly published to all subscribers.\n\nExample:\n\n```#!bash\n$ curl -q -o - http://localhost:8000/hello\n{\"id\":0,\"topic\":{\"name\":\"hello\",\"ttl\":60000000000,\"seq\":1,\"created\":\"2018-03-25T13:18:38.732437-07:00\"},\"payload\":\"eyJtZXNzYWdlIjogImhlbGxvIn0=\",\"created\":\"2018-03-25T13:18:38.732465-07:00\"}\n```\n\n## DELETE /topic\n\nDeletes a queue named by `\u003ctopic\u003e`.\n\n\n## License\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzacksff%2Fpubsubgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzacksff%2Fpubsubgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzacksff%2Fpubsubgo/lists"}