{"id":34842349,"url":"https://github.com/serialt/mqrr","last_synced_at":"2026-05-23T01:02:05.817Z","repository":{"id":211660829,"uuid":"729682129","full_name":"serialt/mqrr","owner":"serialt","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-12T14:47:24.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-27T02:20:58.739Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/serialt.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-12-10T02:10:55.000Z","updated_at":"2023-12-10T02:11:26.000Z","dependencies_parsed_at":"2023-12-12T15:43:53.900Z","dependency_job_id":null,"html_url":"https://github.com/serialt/mqrr","commit_stats":null,"previous_names":["serialt/mqrr"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/serialt/mqrr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fmqrr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fmqrr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fmqrr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fmqrr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serialt","download_url":"https://codeload.github.com/serialt/mqrr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fmqrr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33378554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-22T21:56:13.512Z","status":"ssl_error","status_checked_at":"2026-05-22T21:56:10.769Z","response_time":265,"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":[],"created_at":"2025-12-25T17:13:45.225Z","updated_at":"2026-05-23T01:02:05.808Z","avatar_url":"https://github.com/serialt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MQRR\n\nMQTT v5 Request-Response (MQRR) Pattern provides similar behavior like HTTP. \nDifferent from the HTTP Request-Response model, MQTT request-response is asynchronous, \nwhich brings a problem, that is how to associate the response message with the request message.\nThe following diagram describes the request-response interaction process:\n\n![img](https://assets.emqx.com/images/d624fb3a3061f043f32ae02338f635a0.png?imageMogr2/thumbnail/1520x)\n\nSee the [MQTT Request Response](https://www.emqx.com/en/blog/mqtt5-request-response) article for detailed description.\n\n## Installation\n```shell\ngo get github.com/serialt/mqrr\n```\n\n## Quick start\n\n### Server\n\nLet's create a simple API server that listens for the `hello` topic.\n\n```go\npackage main\n\nimport (\n\t\"github.com/serialt/mqrr\"\n)\n\nfunc main() {\n\tr := mqrr.New()\n\tr.Route(\"hello\", func(c *mqrr.Context) {\n\t\tc.String(\"Hello %s\", c.GetRawString())\n\t})\n\tr.Run(\"mqtt://broker-cn.emqx.io:1883\")\n}\n```\n\n### Client\n\nIn the client side, we publish a message with our name to the `hello` topic, then wait for a response.\n\n```shell\ngo get github.com/serialt/mqrr/client\n```\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/eclipse/paho.golang/paho\"\n\t\"github.com/serialt/mqrr/client\"\n)\n\nfunc main() {\n\tresp, err := client.Request(context.Background(), \"mqtt://broker-cn.emqx.io:1883\", \u0026paho.Publish{\n\t\tTopic:   \"hello\",\n\t\tPayload: []byte(\"John\"),\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(string(resp.Payload)) // Should output \"Hello John\"\n}\n```\n\n## API Examples\n\n### Parameters in topic\n```go\nfunc main() {\n\tr := mqrr.New()\n\tr.Route(\"user/:name\", func(c *mqrr.Context) {\n        name := c.Param(\"name\")\n\t\tc.String(\"Hello %s\", name)\n\t})\n\tr.Route(\"groups/*last\", func(c *mqrr.Context) {\n\t\tc.String(c.Param(\"last\"))\n\t})\n\tr.Run(\"mqtt://broker-cn.emqx.io:1883\")\n}\n```\n\n### Grouping routes\n```go\nfunc main() {\n\tr := mqrr.New()\n\tg1 := r.Group(\"G1\")\n\tg1.Route(\":dev/new\", func(c *mqrr.Context) {\n\t\tc.String(\"new\")\n\t})\n\tg2 := g1.Group(\"G2\")\n\tg2.Route(\":temp\", func(c *mqrr.Context) {\n\t\tc.String(\"temp\")\n\t})\n\tr.Run(\"mqtt://broker-cn.emqx.io:1883\")\n}\n```\n\n### Data binding\n```go\ntype User struct {\n\tName string `topic:\"name\"`\n\tAge  int    `json:\"age\" validate:\"gte=18\"`\n}\n\nfunc main() {\n\tr := mqrr.New()\n\tr.Route(\"user/:name\", func(c *mqrr.Context) {\n\t\tuser := User{}\n\t\tif err := c.BindTopic(\u0026user); err != nil {\n\t\t\tc.String(err.Error())\n\t\t\treturn\n\t\t}\n\t\tif err := c.ShouldBindJSON(\u0026user); err != nil {\n\t\t\tc.String(err.Error())\n\t\t\treturn\n\t\t}\n\t\tc.JSON(user)\n\t})\n\tr.Run(\"mqtt://broker-cn.emqx.io:1883\")\n}\n```\n\n### Client requests in same connection\n```go\nfunc main() {\n\tc, err := client.New(\"mqtt://broker-cn.emqx.io:1883\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer c.Close(context.Background())\n\twg := sync.WaitGroup{}\n\tfor _, name := range []string{\"John\", \"Mary\", \"Ben\"} {\n\t\twg.Add(1)\n\t\tgo func(n string) {\n\t\t\tdefer wg.Done()\n\t\t\tresp, err := c.Request(context.Background(), \u0026paho.Publish{\n\t\t\t\tTopic:   \"hello\",\n\t\t\t\tPayload: []byte(n),\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t\tfmt.Println(string(resp.Payload))\n\t\t}(name)\n\t}\n\twg.Wait()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fmqrr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserialt%2Fmqrr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fmqrr/lists"}