https://github.com/zeromq/gozyre
Go bindings for zeromq libzyre - an open-source framework for proximity-based peer-to-peer applications
https://github.com/zeromq/gozyre
Last synced: about 1 year ago
JSON representation
Go bindings for zeromq libzyre - an open-source framework for proximity-based peer-to-peer applications
- Host: GitHub
- URL: https://github.com/zeromq/gozyre
- Owner: zeromq
- License: mpl-2.0
- Created: 2019-03-12T15:03:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-12T08:47:23.000Z (almost 7 years ago)
- Last Synced: 2025-04-08T01:34:27.718Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 5
- Watchers: 9
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
[](https://circleci.com/gh/zeromq/gozyre) [](https://raw.githubusercontent.com/zeromq/gozyre/master/LICENSE)
# Introduction
A golang interface to the [Zyre v2.0](http://github.com/zeromq/zyre) API. Wraps
most of the API methods to idiomatic Go.
## About Zyre
Zyre is a frameworkd for peer to peer networks written in ZeroMQ
Typical use cases for Zyre are:
* Local service discovery.
* Clustering of a set of services on the same Ethernet network.
* Controlling a network of smart devices (Internet of Things).
* Multi-user mobile applications (like smart classrooms).
Check [Zyre Github page](http://github.com/zeromq/zyre)
# Install
## Dependencies
* [libsodium](https://github.com/jedisct1/libsodium)
* [libzmq](https://github.com/zeromq/libzmq)
* [czmq](https://github.com/zeromq/czmq)
* [zyre](https://github.com/zeromq/zyre)
## For GoZyre master
```
import "github.com/zeromq/gozyre"
```
# Example
```go
package main
import (
"flag"
"time"
zyre "github.com/zeromq/gozyre"
)
const (
Group = "THEROOM"
)
func main() {
var name string
flag.StringVar(&name, "name", "", "node name")
flag.Parse()
node := zyre.New(
name,
zyre.SetHeader("foo", "bar"),
)
defer node.Destroy()
err := node.Start()
if err != nil {
panic(err)
}
err = node.Join(Group)
if err != nil {
panic(err)
}
for i := 0; i != 10; i++ {
node.Shouts(Group, "Hello from %s", name)
time.Sleep(250 * time.Millisecond)
m, err := node.Recv()
if err != nil {
fmt.Printf("err=%s\n", err.Error())
} else {
switch m.(type) {
case Shout:
m := m.(Shout)
fmt.Printf("%T{Peer:\"%s\", Name:\"%s\", Group:\"%s\", Message: []byte{\"%s\"}}\n", m, m.Peer, m.Name, m.Group, string(m.Message[0]))
case Whisper:
m := m.(Whisper)
fmt.Printf("%T{Peer:\"%s\", Name:\"%s\", Message: []byte{\"%s\"}}\n", m, m.Peer, m.Name, string(m.Message[0]))
default:
fmt.Printf("%#+v\n", m)
}
}
}
node.Stop()
}
```
# Note on panic
`gozyre` panics only when user try to operate on destroyed node
```go
node := zyre.New()
...
node.Destroy()
node.Shout(...) <- panic
```
This is violation of API contract and SHALL not be done.
# License
This project uses the MPL v2 license, see LICENSE.
It uses [Collective Code Construction Contract](https://rfc.zeromq.org/spec:42/C4/) for contributing, see CONTRIBUTING.md.