Giter VIP home page Giter VIP logo

gozyre's Introduction

CircleCI license

Introduction

A golang interface to the Zyre v2.0 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

Install

Dependencies

For GoZyre master

import "github.com/zeromq/gozyre"

Example

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

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 for contributing, see CONTRIBUTING.md.

gozyre's People

Contributors

vyskocilm avatar karolhrdina avatar bluca avatar stephan57160 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.