{"id":19973229,"url":"https://github.com/zeromq/goczmq","last_synced_at":"2025-12-18T11:09:58.086Z","repository":{"id":20440438,"uuid":"23717271","full_name":"zeromq/goczmq","owner":"zeromq","description":"goczmq is a golang wrapper for CZMQ.","archived":false,"fork":false,"pushed_at":"2024-03-25T20:09:55.000Z","size":988,"stargazers_count":604,"open_issues_count":30,"forks_count":95,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-01T10:07:34.988Z","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":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeromq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-05T20:26:12.000Z","updated_at":"2025-03-02T17:28:00.000Z","dependencies_parsed_at":"2024-06-18T12:30:14.952Z","dependency_job_id":"deae0f21-beea-42c5-8c02-24eff68c3ace","html_url":"https://github.com/zeromq/goczmq","commit_stats":{"total_commits":284,"total_committers":29,"mean_commits":9.793103448275861,"dds":0.3063380281690141,"last_synced_commit":"4e50cfc0edc9f02f25eb3b1f6948f0db93749a9b"},"previous_names":["taotetek/goczmq"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fgoczmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fgoczmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fgoczmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fgoczmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeromq","download_url":"https://codeload.github.com/zeromq/goczmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247631666,"owners_count":20970062,"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-13T03:10:42.444Z","updated_at":"2025-12-18T11:09:52.773Z","avatar_url":"https://github.com/zeromq.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# goczmq [![Build Status](https://travis-ci.org/zeromq/goczmq.svg?branch=master)](https://travis-ci.org/zeromq/goczmq) [![Doc Status](https://godoc.org/github.com/zeromq/goczmq?status.png)](https://godoc.org/github.com/zeromq/goczmq)\n\n## Introduction\nA golang interface to the [CZMQ v4.2](http://czmq.zeromq.org) API.\n\n## Install\n### Dependencies\n* [libsodium](https://github.com/jedisct1/libsodium)\n* [libzmq](https://github.com/zeromq/libzmq)\n* [czmq](https://github.com/zeromq/czmq)\n\n### For CZMQ master\n```\ngo get github.com/zeromq/goczmq\n```\n#### A Note on Build Tags\nThe CZMQ library includes experimental classes that are not built by default, but can be built\nby passing `--enable-drafts` to configure. Support for these draft classes are being added\nto goczmq. To build these features against a CZMQ that has been compiled with `--enable-drafts`,\nuse `go build -tags draft`.\n\n### For CMZQ = 4.2\n```\ngo get gopkg.in/zeromq/goczmq.v4\n```\n**Note**: [CZMQ 4.2](https://github.com/zeromq/czmq/releases) is has not been released yet.\n\n### For CZMQ Before 4.0\n```\ngo get gopkg.in/zeromq/goczmq.v1\n```\n## Usage\n### Direct CZMQ Sock API\n#### Example\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/zeromq/goczmq\"\n)\n\nfunc main() {\n\t// Create a router socket and bind it to port 5555.\n\trouter, err := goczmq.NewRouter(\"tcp://*:5555\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer router.Destroy()\n\n\tlog.Println(\"router created and bound\")\n\n\t// Create a dealer socket and connect it to the router.\n\tdealer, err := goczmq.NewDealer(\"tcp://127.0.0.1:5555\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer dealer.Destroy()\n\n\tlog.Println(\"dealer created and connected\")\n\n\t// Send a 'Hello' message from the dealer to the router.\n\t// Here we send it as a frame ([]byte), with a FlagNone\n\t// flag to indicate there are no more frames following.\n\terr = dealer.SendFrame([]byte(\"Hello\"), goczmq.FlagNone)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Println(\"dealer sent 'Hello'\")\n\n\t// Receive the message. Here we call RecvMessage, which\n\t// will return the message as a slice of frames ([][]byte).\n\t// Since this is a router socket that support async\n\t// request / reply, the first frame of the message will\n\t// be the routing frame.\n\trequest, err := router.RecvMessage()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"router received '%s' from '%v'\", request[1], request[0])\n\n\t// Send a reply. First we send the routing frame, which\n\t// lets the dealer know which client to send the message.\n\t// The FlagMore flag tells the router there will be more\n\t// frames in this message.\n\terr = router.SendFrame(request[0], goczmq.FlagMore)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"router sent 'World'\")\n\n\t// Next send the reply. The FlagNone flag tells the router\n\t// that this is the last frame of the message.\n\terr = router.SendFrame([]byte(\"World\"), goczmq.FlagNone)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Receive the reply.\n\treply, err := dealer.RecvMessage()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"dealer received '%s'\", string(reply[0]))\n}\n```\n#### Output\n```\n2015/05/26 21:52:52 router created and bound\n2015/05/26 21:52:52 dealer created and connected\n2015/05/26 21:52:52 dealer sent 'Hello'\n2015/05/26 21:52:52 router received 'Hello' from '[0 103 84 189 175]'\n2015/05/26 21:52:52 router sent 'World'\n2015/05/26 21:52:52 dealer received 'World'\n```\n### io.ReadWriter support\n#### Example\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/zeromq/goczmq\"\n)\n\nfunc main() {\n\t// Create a router socket and bind it to port 5555.\n\trouter, err := goczmq.NewRouter(\"tcp://*:5555\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer router.Destroy()\n\n\tlog.Println(\"router created and bound\")\n\n\t// Create a dealer socket and connect it to the router.\n\tdealer, err := goczmq.NewDealer(\"tcp://127.0.0.1:5555\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer dealer.Destroy()\n\n\tlog.Println(\"dealer created and connected\")\n\n\t// Send a 'Hello' message from the dealer to the router,\n\t// using the io.Write interface\n\tn, err := dealer.Write([]byte(\"Hello\"))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"dealer sent %d byte message 'Hello'\\n\", n)\n\n\t// Make a byte slice and pass it to the router\n\t// Read interface. When using the ReadWriter\n\t// interface with a router socket, the router\n\t// caches the routing frames internally in a\n\t// FIFO and uses them transparently when\n\t// sending replies.\n\tbuf := make([]byte, 16386)\n\n\tn, err = router.Read(buf)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"router received '%s'\\n\", buf[:n])\n\n\t// Send a reply.\n\tn, err = router.Write([]byte(\"World\"))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"router sent %d byte message 'World'\\n\", n)\n\n\t// Receive the reply, reusing the previous buffer.\n\tn, err = dealer.Read(buf)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"dealer received '%s'\", string(buf[:n]))\n}\n```\n#### Output\n```\n2015/05/26 21:54:10 router created and bound\n2015/05/26 21:54:10 dealer created and connected\n2015/05/26 21:54:10 dealer sent 5 byte message 'Hello'\n2015/05/26 21:54:10 router received 'Hello'\n2015/05/26 21:54:10 router sent 5 byte message 'World'\n2015/05/26 21:54:10 dealer received 'World'\n```\n### Thread safe channel interface\n#### Example\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/zeromq/goczmq\"\n)\n\nfunc main() {\n\t// Create a router channeler and bind it to port 5555.\n\t// A channeler provides a thread safe channel interface\n\t// to a *Sock\n\trouter := goczmq.NewRouterChanneler(\"tcp://*:5555\")\n\tdefer router.Destroy()\n\n\tlog.Println(\"router created and bound\")\n\n\t// Create a dealer channeler and connect it to the router.\n\tdealer := goczmq.NewDealerChanneler(\"tcp://127.0.0.1:5555\")\n\tdefer dealer.Destroy()\n\n\tlog.Println(\"dealer created and connected\")\n\n\t// Send a 'Hello' message from the dealer to the router.\n\tdealer.SendChan \u003c- [][]byte{[]byte(\"Hello\")}\n\tlog.Println(\"dealer sent 'Hello'\")\n\n\t// Receve the message as a [][]byte. Since this is\n\t// a router, the first frame of the message wil\n\t// be the routing frame.\n\trequest := \u003c-router.RecvChan\n\tlog.Printf(\"router received '%s' from '%v'\", request[1], request[0])\n\n\t// Send a reply. First we send the routing frame, which\n\t// lets the dealer know which client to send the message.\n\trouter.SendChan \u003c- [][]byte{request[0], []byte(\"World\")}\n\tlog.Printf(\"router sent 'World'\")\n\n\t// Receive the reply.\n\treply := \u003c-dealer.RecvChan\n\tlog.Printf(\"dealer received '%s'\", string(reply[0]))\n}\n```\n#### Output\n```\n2015/05/26 21:56:43 router created and bound\n2015/05/26 21:56:43 dealer created and connected\n2015/05/26 21:56:43 dealer sent 'Hello'\n2015/05/26 21:56:43 received 'Hello' from '[0 12 109 153 35]'\n2015/05/26 21:56:43 router sent 'World'\n2015/05/26 21:56:43 dealer received 'World'\n```\n## GoDoc\n[godoc](https://godoc.org/github.com/zeromq/goczmq)\n\n## See Also\n* [Peter Kleiweg's](https://github.com/pebbe) [zmq4](https://github.com/pebbe/zmq4) bindings\n\n## License\nThis project uses the MPL v2 license, see LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromq%2Fgoczmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeromq%2Fgoczmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromq%2Fgoczmq/lists"}