{"id":13645218,"url":"https://github.com/genkami/kiara","last_synced_at":"2025-03-29T09:10:17.597Z","repository":{"id":39869737,"uuid":"337732336","full_name":"genkami/kiara","owner":"genkami","description":"Backend-agnostic, lightweight pub/sub library which makes it easy for Go applications to communicate with each other.","archived":false,"fork":false,"pushed_at":"2025-03-19T22:28:04.000Z","size":370,"stargazers_count":143,"open_issues_count":12,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T23:28:29.322Z","etag":null,"topics":["go","golang","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/genkami.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":"2021-02-10T13:28:12.000Z","updated_at":"2024-09-26T10:04:15.000Z","dependencies_parsed_at":"2023-10-25T21:24:24.264Z","dependency_job_id":"dd346f2d-4d61-4dc5-851f-d7b02e4887f7","html_url":"https://github.com/genkami/kiara","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genkami%2Fkiara","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genkami%2Fkiara/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genkami%2Fkiara/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/genkami%2Fkiara/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/genkami","download_url":"https://codeload.github.com/genkami/kiara/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246162147,"owners_count":20733357,"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":["go","golang","pubsub"],"created_at":"2024-08-02T01:02:31.365Z","updated_at":"2025-03-29T09:10:17.580Z","avatar_url":"https://github.com/genkami.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Kiara\n\n![ci status](https://github.com/genkami/kiara/workflows/Test/badge.svg)\n[![Go Reference](https://pkg.go.dev/badge/github.com/genkami/kiara.svg)](https://pkg.go.dev/github.com/genkami/kiara)\n\n![phoenix](./doc/img/phoenix.png)\n\nKiara is a Go equivalent of Phoenix PubSub that makes it easy for Go applications to communicate with each other.\n\n## Examples\n* [Basic Usage](https://github.com/genkami/kiara/tree/main/examples/basic-usage)\n* [Custom Codec (WATSON × Kiara)](https://github.com/genkami/kiara/tree/main/examples/custom-codec)\n* [NATS Adapter](https://github.com/genkami/kiara/tree/main/examples/nats-adapter)\n* [Chat](https://github.com/genkami/kiara/tree/main/examples/chat)\n\n![demo chat application](./doc/img/kiara-chat-demo.gif)\n\n## Basic Usage (with Redis Backend)\n\n``` go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/genkami/kiara\"\n\tadapter \"github.com/genkami/kiara/adapter/redis\"\n\t\"github.com/go-redis/redis/v8\"\n)\n\ntype Message struct {\n\tFrom string\n\tBody string\n}\n\nfunc main() {\n\tvar err error\n\tredisClient := redis.NewClient(\u0026redis.Options{Addr: \"localhost:6379\"})\n\tpubsub := kiara.NewPubSub(adapter.NewAdapter(redisClient))\n\tdefer pubsub.Close()\n\n\tchannel := make(chan Message, 5)\n\tsub, err := pubsub.Subscribe(\"room:123\", channel)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer sub.Unsubscribe()\n\n\tctx := context.Background()\n\tmsg := \u0026Message{From: \"birb\", Body: \"cock-a-doodle-doo\"}\n\terr = pubsub.Publish(ctx, \"room:123\", msg)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsent := \u003c-channel\n\tfmt.Printf(\"%s: %s\\n\", sent.From, sent.Body)\n}\n```\n\n## Run Test\nTo run an entire test, you need to run Redis and NATS, and to tell their addresses to test cases by setting environment variables.\n\nWe have `docker-compose.yml` to set up these dependencies easily. To run tests with docker-compose, type these following commands:\n\n```\n$ docker-compose up -d\n$ export KIARA_TEST_REDIS_ADDR=localhost:6379\n$ export KIARA_TEST_NATS_URL=nats://localhost:4222\n$ go test ./...\n```\n\n## Codec\nBy default, messages are marshaled into gob format. You can specify which codec Kiara uses to marshal and unmarshal messages by passing `WithCodec()` to `NewPubSub()`.\n\n``` go\nimport \"github.com/genkami/kiara/codec/msgpack\"\n\npubsub := kiara.NewPubSub(\n    adapter.NewAdapter(redisClient),\n    kiara.WithCodec(msgpack.Codec),\n)\n```\n\nCurrently these codecs are officially available:\n* [gob](https://pkg.go.dev/github.com/genkami/kiara/codec/gob)\n* [JSON](https://pkg.go.dev/github.com/genkami/kiara/codec/json)\n* [MessagePack](https://pkg.go.dev/github.com/genkami/kiara/codec/msgpack)\n* [Protocol Buffers](https://pkg.go.dev/github.com/genkami/kiara/codec/proto)\n\n## Custom Codec\nYou can implement your own codec by simply implementing `Marshal` and `Unmarshal`. For example, if you want to encode messages into [WATSON](https://github.com/genkami/watson), you have to implement WATSON codec like this:\n\n``` go\nimport \t\"github.com/genkami/watson\"\n\ntype WatsonCodec struct{}\n\nfunc (_ *WatsonCodec) Marshal(v interface{}) ([]byte, error) {\n\treturn watson.Marshal(v)\n}\n\nfunc (_ *WatsonCodec) Unmarshal(src []byte, v interface{}) error {\n\treturn watson.Unmarshal(src, v)\n}\n```\n\n## Backend-Agnostic\nKiara does not depend on specific message broker implementation. Currently these message brokers are officially supported:\n\n* [Redis](https://pkg.go.dev/github.com/genkami/kiara/adapter/redis)\n* [NATS](https://pkg.go.dev/github.com/genkami/kiara/adapter/nats)\n\nYou can change backend message brokers with little effort. Here are examples of connecting to Redis and NATS as a Kiara's backend.\n\nExample(Redis):\n\n``` go\nimport (\n    \"github.com/go-redis/redis/v8\"\n    adapter \"github.com/genkami/kiara/adapter/redis\"\n)\nredisClient := redis.NewClient(\u0026redis.Options{Addr: \"localhost:6379\"})\npubsub := kiara.NewPubSub(adapter.NewAdapter(redisClient))\n```\n\nExample(NATS):\n\n``` go\nimport (\n    \"github.com/nats-io/nats.go\"\n    adapter \"github.com/genkami/kiara/adapter/nats\"\n)\nconn, err := nats.Connect(\"nats://localhost:4222\")\n// error handling omitted\npubsub := kiara.NewPubSub(adapter.NewAdapter(conn))\n```\n\n## License\n\nDistributed under the MIT License. See LICENSE for more information.\n\n## Acknowledgements\n\nThis library is highly inspired by [phoenixframework/phoenix_pubsub](https://github.com/phoenixframework/phoenix_pubsub), [nats-io/nats.go](https://github.com/nats-io/nats.go), and the majestic phoenix [Takanashi Kiara](https://www.youtube.com/channel/UCHsx4Hqa-1ORjQTh9TYDhww?sub_confirmation=1).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenkami%2Fkiara","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenkami%2Fkiara","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenkami%2Fkiara/lists"}