grapevine

package module
v0.0.0-...-002e196 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2017 License: MIT Imports: 16 Imported by: 0

README

grapevine

Brokerless (p2p) cluster with service auto-discover and failure resilient implemented in gomsg

It is very easy to use, with very little configuration.

The provider

var peer = grapevine.NewPeer(grapevine.Config{})
peer.Handle("GREETING", func(name string) string {
	return "Hello " + name
})
if err := <-peer.Bind(":7000"); err != nil {
	panic(err)
}

The consumer

var peer = grapevine.NewPeer(grapevine.Config{})
go func() {
	if err := <-peer.Bind(":8000"); err != nil {
		panic(err)
	}
}()

// give time for the Peer to connect
time.Sleep(time.Second)

<-peer.Request("GREETING", "Paulo", func(reply string) {
	fmt.Println("Reply:", reply)
})

Details

Auto discovery is implemented by a UDP heartbeat that every node emits. When a node receives a heartbeat from a new node, it connects to it.

A node is implemented with a gomsg.Server (to make calls) and a list of gomsg.Client (to listen), one for each cluster node.

Documentation

Index

Constants

View Source
const (
	UuidSize       = 16
	PING           = "PING"
	PeerAddressKey = "peer.address"
)

defaults

Variables

This section is empty.

Functions

This section is empty.

Types

type Beacon

type Beacon struct {
	Addr            string        `json:"addr"`
	Name            string        `json:"name"`
	MaxDatagramSize int           `json:"maxDatagramSize"`
	Interval        time.Duration `json:"interval"`
	MaxInterval     time.Duration `json:"maxInterval"`
	// BeaconCountdown is the number of consecutive UDP pings inside the ping window
	// to reactivate the UDP health check
	Countdown int `json:"countdown"`
}

type Config

type Config struct {
	Addr   string  `json:"addr"`
	Uuid   tk.UUID `json:"uuid"`
	Beacon `json:"beacon"`
}

type Peer

type Peer struct {
	sync.RWMutex
	*gomsg.Server
	// contains filtered or unexported fields
}

func NewPeer

func NewPeer(cfg Config) *Peer

func (*Peer) AddDropPeerListener

func (this *Peer) AddDropPeerListener(listener PeerListener) uint64

func (*Peer) AddNewPeerListener

func (this *Peer) AddNewPeerListener(listener PeerListener) uint64

func (*Peer) Bind

func (peer *Peer) Bind() <-chan error

func (*Peer) Cancel

func (peer *Peer) Cancel(name string)

func (*Peer) Config

func (peer *Peer) Config() Config

func (*Peer) Destroy

func (peer *Peer) Destroy()

func (*Peer) Handle

func (peer *Peer) Handle(name string, hnd ...interface{})

func (*Peer) RemoveDropPeerListener

func (this *Peer) RemoveDropPeerListener(idx uint64)

RemoveSendListener removes a previously added listener on send messages

func (*Peer) RemoveNewPeerListener

func (this *Peer) RemoveNewPeerListener(idx uint64)

RemoveSendListener removes a previously added listener on send messages

type PeerListener

type PeerListener func(*gomsg.Client)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL