goczmq

package module
v0.0.0-...-b9cddd3 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2015 License: MPL-2.0 Imports: 9 Imported by: 11

README

goczmq Build Status Doc Status

Introduction

A golang interface to the CZMQ v3 API.

Update 2015-06-02

With the releases of zeromq 4.1 and czmq 3, we are declaring a stable release. What does "stable release" mean in the world of go getting projects off of git master? It means our exported API is finalized and we will, to the absolute best of our ability, make no breaking changes to it. We may make additive changes, and we may refactor internals in order to improve performance.

Installation

Building From Source (Linux)
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.3.tar.gz
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.3.tar.gz.sig
wget https://download.libsodium.org/jedi.gpg.asc
gpg --import jedi.gpg.asc
gpg --verify libsodium-1.0.3.tar.gz.sig libsodium-1.0.3.tar.gz
tar zxvf libsodium-1.0.3.tar.gz
cd libsodium-1.0.3
./configure; make check
sudo make install
sudo ldconfig
wget http://download.zeromq.org/zeromq-4.1.1.tar.gz
tar zxvf zeromq-4.1.1.tar.gz
cd zeromq-4.1.1
./configure --with-libsodium; make; make check
sudo make install
sudo ldconfig
wget http://download.zeromq.org/czmq-3.0.1.tar.gz
tar zxvf czmq-3.0.1.tar.gz
cd czmq-3.0.1
./configure; make check
sudo make install
sudo ldconfig
go get github.com/zeromq/goczmq

Usage

Direct CZMQ Sock API
Example
package main

import (
	"log"

	"github.com/zeromq/goczmq"
)

func main() {
	// Create a router socket and bind it to port 5555.
	router, err := goczmq.NewRouter("tcp://*:5555")
	if err != nil {
		log.Fatal(err)
	}
	defer router.Destroy()

	log.Println("router created and bound")

	// Create a dealer socket and connect it to the router.
	dealer, err := goczmq.NewDealer("tcp://127.0.0.1:5555")
	if err != nil {
		log.Fatal(err)
	}
	defer dealer.Destroy()

	log.Println("dealer created and connected")

	// Send a 'Hello' message from the dealer to the router.
	// Here we send it as a frame ([]byte), with a FlagNone
	// flag to indicate there are no more frames following.
	err = dealer.SendFrame([]byte("Hello"), goczmq.FlagNone)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("dealer sent 'Hello'")

	// Receve the message. Here we call RecvMessage, which
	// will return the message as a slice of frames ([][]byte).
	// Since this is a router socket that support async
	// request / reply, the first frame of the message will
	// be the routing frame.
	request, err := router.RecvMessage()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("router received '%s' from '%v'", request[1], request[0])

	// Send a reply. First we send the routing frame, which
	// lets the dealer know which client to send the message.
	// The FlagMore flag tells the router there will be more
	// frames in this message.
	err = router.SendFrame(request[0], goczmq.FlagMore)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("router sent 'World'")

	// Next send the reply. The FlagNone flag tells the router
	// that this is the last frame of the message.
	err = router.SendFrame([]byte("World"), goczmq.FlagNone)
	if err != nil {
		log.Fatal(err)
	}

	// Receive the reply.
	reply, err := dealer.RecvMessage()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("dealer received '%s'", string(reply[0]))
}
Output
2015/05/26 21:52:52 router created and bound
2015/05/26 21:52:52 dealer created and connected
2015/05/26 21:52:52 dealer sent 'Hello'
2015/05/26 21:52:52 router received 'Hello' from '[0 103 84 189 175]'
2015/05/26 21:52:52 router sent 'World'
2015/05/26 21:52:52 dealer received 'World'
io.ReadWriter support
Example
package main

import (
	"log"

	"github.com/zeromq/goczmq"
)

func main() {
	// Create a router socket and bind it to port 5555.
	router, err := goczmq.NewRouter("tcp://*:5555")
	if err != nil {
		log.Fatal(err)
	}
	defer router.Destroy()

	log.Println("router created and bound")

	// Create a dealer socket and connect it to the router.
	dealer, err := goczmq.NewDealer("tcp://127.0.0.1:5555")
	if err != nil {
		log.Fatal(err)
	}
	defer dealer.Destroy()

	log.Println("dealer created and connected")

	// Send a 'Hello' message from the dealer to the router,
	// using the io.Write interface
	n, err := dealer.Write([]byte("Hello"))
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("dealer sent %d byte message 'Hello'\n", n)

	// Make a byte slice and pass it to the router
	// Read interface. When using the ReadWriter
	// interface with a router socket, the router
	// caches the routing frames internally in a
	// FIFO and uses them transparently when
	// sending replies.
	buf := make([]byte, 16386)

	n, err = router.Read(buf)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("router received '%s'\n", buf[:n])

	// Send a reply.
	n, err = router.Write([]byte("World"))
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("router sent %d byte message 'World'\n", n)

	// Receive the reply, reusing the previous buffer.
	n, err = dealer.Read(buf)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("dealer received '%s'", string(buf[:n]))
}
Output
2015/05/26 21:54:10 router created and bound
2015/05/26 21:54:10 dealer created and connected
2015/05/26 21:54:10 dealer sent 5 byte message 'Hello'
2015/05/26 21:54:10 router received 'Hello'
2015/05/26 21:54:10 router sent 5 byte message 'World'
2015/05/26 21:54:10 dealer received 'World'
Thread safe channel interface
Example
package main

import (
	"log"

	"github.com/zeromq/goczmq"
)

func main() {
	// Create a router channeler and bind it to port 5555.
	// A channeler provides a thread safe channel interface
	// to a *Sock
	router := goczmq.NewRouterChanneler("tcp://*:5555")
	defer router.Destroy()

	log.Println("router created and bound")

	// Create a dealer channeler and connect it to the router.
	dealer := goczmq.NewDealerChanneler("tcp://127.0.0.1:5555")
	defer dealer.Destroy()

	log.Println("dealer created and connected")

	// Send a 'Hello' message from the dealer to the router.
	dealer.SendChan <- [][]byte{[]byte("Hello")}
	log.Println("dealer sent 'Hello'")

	// Receve the message as a [][]byte. Since this is
	// a router, the first frame of the message wil
	// be the routing frame.
	request := <-router.RecvChan
	log.Printf("router received '%s' from '%v'", request[1], request[0])

	// Send a reply. First we send the routing frame, which
	// lets the dealer know which client to send the message.
	router.SendChan <- [][]byte{request[0], []byte("World")}
	log.Printf("router sent 'World'")

	// Receive the reply.
	reply := <-dealer.RecvChan
	log.Printf("dealer received '%s'", string(reply[0]))
}
Output
2015/05/26 21:56:43 router created and bound
2015/05/26 21:56:43 dealer created and connected
2015/05/26 21:56:43 dealer sent 'Hello'
2015/05/26 21:56:43 received 'Hello' from '[0 12 109 153 35]'
2015/05/26 21:56:43 router sent 'World'
2015/05/26 21:56:43 dealer received 'World'

GoDoc

godoc

See Also

License

This project uses the MPL v2 license, see LICENSE

Documentation

Overview

Package goczmq is a golang binding for CZMQ 3. CZMQ is a high level binding for ZeroMQ. Along with ZeroMQ socket support, CZMQ provides "actor" based services for authentication, service discovery, and creating proxies. GoCZMQ provides direct bindings to CZMQ along with higher level go abstractions such as channels and io.ReadWriter interface support.

Index

Examples

Constants

View Source
const (
	Req    = int(C.ZMQ_REQ)
	Rep    = int(C.ZMQ_REP)
	Dealer = int(C.ZMQ_DEALER)
	Router = int(C.ZMQ_ROUTER)
	Pub    = int(C.ZMQ_PUB)
	Sub    = int(C.ZMQ_SUB)
	XPub   = int(C.ZMQ_XPUB)
	XSub   = int(C.ZMQ_XSUB)
	Push   = int(C.ZMQ_PUSH)
	Pull   = int(C.ZMQ_PULL)
	Pair   = int(C.ZMQ_PAIR)
	Stream = int(C.ZMQ_STREAM)

	Pollin  = int(C.ZMQ_POLLIN)
	Pollout = int(C.ZMQ_POLLOUT)

	FlagMore     = int(C.ZFRAME_MORE)
	FlagReuse    = int(C.ZFRAME_REUSE)
	FlagDontWait = int(C.ZFRAME_DONTWAIT)
	FlagNone     = 0

	CurveAllowAny = "*"
)
View Source
const WaitAfterDestroyPanicMessage = "Wait() is invalid on Poller after Destroy() is called."

Variables

View Source
var (
	ErrActorCmd        = errors.New("error sending actor command")
	ErrSockAttach      = errors.New("error attaching zsock")
	ErrInvalidSockType = errors.New("invalid socket type")
)
View Source
var (
	// ErrSliceFull is returned if a []byte passed to Read was not
	// large enough to hold the contents of a message
	ErrSliceFull = errors.New("goczmq: slice full")
)

Functions

This section is empty.

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

Auth wraps the CZMQ zauth actor. It handles authentication for all incoming connections. It allows whitelisting and blackisting peers based on IP address and support PLAIN and CURVE authentication policies.

Example
// create a new server certificate
serverCert := NewCert()
defer serverCert.Destroy()

// create a client certificate and save it
clientCert := NewCert()
defer clientCert.Destroy()
clientCert.SavePublic("client_cert")

// create a new auth actor
auth := NewAuth()
defer auth.Destroy()

// set the client certificate as an allowed client
auth.Curve("client_cert")
defer func() { os.Remove("client_cert") }()

// create a server, set its auth domain to global
server := NewSock(Push)
defer server.Destroy()
server.SetZapDomain("global")

// assign the server cert to the server,
// make it use CURVE auth and bind it
serverCert.Apply(server)
server.SetCurveServer(1)

server.Bind("inproc://auth_example")

// create a client socket, apply the client
// certificate to it, and set the server's
// public key so it can connect
client := NewSock(Pull)
defer client.Destroy()

clientCert.Apply(client)
client.SetCurveServerkey(serverCert.PublicText())

client.Connect("inproc://auth_example")
Output:

func NewAuth

func NewAuth() *Auth

NewAuth creates a new Auth actor.

func (*Auth) Allow

func (a *Auth) Allow(address string) error

Allow removes a previous Deny

func (*Auth) Curve

func (a *Auth) Curve(allowed string) error

Curve sets auth method to curve

func (*Auth) Deny

func (a *Auth) Deny(address string) error

Deny adds an address to a socket's deny list

func (*Auth) Destroy

func (a *Auth) Destroy()

Destroy destroys the auth actor.

func (*Auth) Plain

func (a *Auth) Plain(directory string) error

Plain sets auth method to plain

func (*Auth) Verbose

func (a *Auth) Verbose() error

Verbose sets the auth actor to log information to stdout.

type Beacon

type Beacon struct {
	// contains filtered or unexported fields
}

Beacon wraps the CZMQ beacon actor. It implements a peer-to-peer discovery service for local networks. Beacons can broadcast and receive UDPv4 service broadcasts.

func NewBeacon

func NewBeacon() *Beacon

NewBeacon creates a new Beacon instance.

func (*Beacon) Configure

func (b *Beacon) Configure(port int) (string, error)

Configure accepts a port number and configures the beacon, returning an address

func (*Beacon) Destroy

func (b *Beacon) Destroy()

Destroy destroys the beacon.

func (*Beacon) Publish

func (b *Beacon) Publish(announcement string, interval int) error

Publish publishes an announcement at an interval

func (*Beacon) Recv

func (b *Beacon) Recv(timeout int) string

Recv waits for the specific timeout in milliseconds to receive a beacon

func (*Beacon) Subscribe

func (b *Beacon) Subscribe(filter string) error

Subscribe subscribes to beacons matching the filter

func (*Beacon) Verbose

func (b *Beacon) Verbose() error

Verbose sets the beacon to log information to stdout.

type Cert

type Cert struct {
	// contains filtered or unexported fields
}

Cert wraps the CZMQ zcert class. It provides tools for creating and working with ZMQ CURVE security certs. The certs can be used as a temporary object in memory or persisted to disk. Certs are made up of a public and secret keypair + metadata.

Example
cert := NewCert()
defer cert.Destroy()
cert.SetMeta("email", "taotetek@gmail.com")
cert.SetMeta("name", "Brian Knox")
cert.SetMeta("organization", "ZeroMQ")
Output:

func NewCert

func NewCert() *Cert

NewCert creates a new empty Cert instance

func NewCertFromFile

func NewCertFromFile(filename string) (*Cert, error)

NewCertFromFile Load loads a Cert from files

func NewCertFromKeys

func NewCertFromKeys(public []byte, secret []byte) (*Cert, error)

NewCertFromKeys creates a new Cert from a public and private key

func (*Cert) Apply

func (c *Cert) Apply(s *Sock)

Apply sets the public and private keys for a socket

func (*Cert) Destroy

func (c *Cert) Destroy()

Destroy destroys Cert instance

func (*Cert) Dup

func (c *Cert) Dup() *Cert

Dup duplicates a Cert

func (*Cert) Equal

func (c *Cert) Equal(compare *Cert) bool

Equal checks two Certs for equality

func (*Cert) Meta

func (c *Cert) Meta(key string) string

Meta returns a meta data item from a Cert given a key

func (*Cert) Print

func (c *Cert) Print()

Print prints a Cert to stdout

func (*Cert) PublicText

func (c *Cert) PublicText() string

PublicText returns the public key as a string

func (*Cert) Save

func (c *Cert) Save(filename string) error

Save saves the public and secret key to filename and filename_secret

func (*Cert) SavePublic

func (c *Cert) SavePublic(filename string) error

SavePublic saves the public key to a file

func (*Cert) SaveSecret

func (c *Cert) SaveSecret(filename string) error

SaveSecret saves the secret key to a file

func (*Cert) SetMeta

func (c *Cert) SetMeta(key string, value string)

SetMeta sets meta data for a Cert

type CertStore

type CertStore struct {
	// contains filtered or unexported fields
}

CertStore works with directories of CURVE security certificates. It lets you easily load stores from disk and check if a key is present or not. This could be done fairly easily in pure Go, but is included for the sake of compatibility.

func NewCertStore

func NewCertStore(location string) *CertStore

NewCertStore creates a new certificate store from a disk directory, loading and indexing all certificates.

func (*CertStore) Destroy

func (c *CertStore) Destroy()

Destroy destroys Cert instance

func (*CertStore) Insert

func (c *CertStore) Insert(cert *Cert)

Insert inserts a certificate into the store in memory. Call Save directly on the cert if you wish to save it to disk.

func (*CertStore) Lookup

func (c *CertStore) Lookup(key string) *Cert

Lookup looks up a certificate in the store by public key and returns it.

func (*CertStore) Print

func (c *CertStore) Print()

Print prints a list of certificates in the store to stdout

type Channeler

type Channeler struct {
	SendChan chan<- [][]byte
	RecvChan <-chan [][]byte
	// contains filtered or unexported fields
}

Channeler serializes all access to a socket through a send and receive channel. It starts two threads, on is used for receiving from the zeromq socket. The other is used to listen to the receive channel, and send everything back to the socket thrad for sending using an additional inproc socket.

Example (Output)
// create a dealer channeler
dealer := NewDealerChanneler("inproc://channelerdealerrouter")
defer dealer.Destroy()

// create a router channeler
router := NewRouterChanneler("inproc://channelerdealerrouter")
defer router.Destroy()

// send a hello message
dealer.SendChan <- [][]byte{[]byte("Hello")}

// receive the hello message
request := <-router.RecvChan

// first frame is identity of client - let's append 'World'
// to the message and route it back
request = append(request, []byte("World"))

// send the reply
router.SendChan <- request

// receive the reply
reply := <-dealer.RecvChan

fmt.Printf("%s %s", string(reply[0]), string(reply[1]))
Output:

Hello World

func NewDealerChanneler

func NewDealerChanneler(endpoints string) *Channeler

NewDealerChanneler creates a new Channeler wrapping a Dealer socket. The socket will connect by default.

func NewPairChanneler

func NewPairChanneler(endpoints string) *Channeler

NewPairChanneler creates a new Channeler wrapping a Pair socket. The socket will connect by default.

func NewPubChanneler

func NewPubChanneler(endpoints string) *Channeler

NewPubChanneler creats a new Channeler wrapping a Pub socket. The socket will bind by default.

func NewPullChanneler

func NewPullChanneler(endpoints string) *Channeler

NewPullChanneler creates a new Channeler wrapping a Pull socket. The socket will bind by default.

func NewPushChanneler

func NewPushChanneler(endpoints string) *Channeler

NewPushChanneler creates a new Channeler wrapping a Push socket. The socket will connect by default.

func NewRepChanneler

func NewRepChanneler(endpoints string) *Channeler

NewRepChanneler creates a new Channeler wrapping a Rep socket. The socket will bind by default.

func NewReqChanneler

func NewReqChanneler(endpoints string) *Channeler

NewReqChanneler creates a new Channeler wrapping a Req socket. The socket will connect by default.

func NewRouterChanneler

func NewRouterChanneler(endpoints string) *Channeler

NewRouterChanneler creates a new Channeler wrapping a Router socket. The socket will Bind by default.

func NewStreamChanneler

func NewStreamChanneler(endpoints string) *Channeler

NewStreamChanneler creates a new Channeler wrapping a Pair socket. The socket will connect by default.

func NewSubChanneler

func NewSubChanneler(endpoints, subscribe string) *Channeler

NewSubChanneler creates a new Channeler wrapping a Sub socket. Along with an endpoint list it accepts a comma delimited list of topics. The socket will connect by default.

func NewXPubChanneler

func NewXPubChanneler(endpoints string) *Channeler

NewXPubChanneler creates a new Channeler wrapping an XPub socket. The socket will Bind by default.

func NewXSubChanneler

func NewXSubChanneler(endpoints, subscribe string) *Channeler

NewXSubChanneler creates a new Channeler wrapping a XSub socket. Along with an endpoint list it accepts a comma delimited list of topics. The socket will connect by default.

func (*Channeler) Destroy

func (c *Channeler) Destroy()

Destroy sends a message to the Channeler to shut it down and clean it up.

type Gossip

type Gossip struct {
	// contains filtered or unexported fields
}

Gossip wraps the CZMQ gossip actor. This actor speaks a gossip protocol for decentralized configuration management. Nodes form a loosely connected network and publish name / value pair tuples. Each node redistributes tuples it receives.

Example
gossiper := NewGossip("client")

err := gossiper.Bind("inproc://gossip_example")
if err != nil {
	panic(err)
}

err = gossiper.Publish("key", "value")
if err != nil {
	panic(err)
}

gossiper.Destroy()
Output:

func NewGossip

func NewGossip(name string) *Gossip

NewGossip creates a new Gossip actor

func (*Gossip) Bind

func (g *Gossip) Bind(endpoint string) error

Bind binds the gossip service to a specified endpoint

func (*Gossip) Connect

func (g *Gossip) Connect(endpoint string) error

Connect connects the gossip service to a specified endpoint

func (*Gossip) Destroy

func (g *Gossip) Destroy()

Destroy destroys the gossip actor.

func (*Gossip) Publish

func (g *Gossip) Publish(key, value string) error

Publish announces a key / value pair

func (*Gossip) Verbose

func (g *Gossip) Verbose() error

Verbose sets the gossip actor to log information to stdout.

type Poller

type Poller struct {
	// contains filtered or unexported fields
}

Poller provides a simple wrapper to ZeroMQ's zmq_poll API, for the common case of reading from a number of sockets. Sockets can be added and removed from the running poller.

Example
sock1, err := NewRouter("inproc://poller_example_1")
if err != nil {
	panic(err)
}
defer sock1.Destroy()

poller, err := NewPoller(sock1)
if err != nil {
	panic(err)
}

sock2, err := NewRouter("inproc://poller_example_2")
if err != nil {
	panic(err)
}
defer sock2.Destroy()

err = poller.Add(sock2)
if err != nil {
	panic(err)
}

// Poller.Wait(millis) returns first socket that has a waiting message
_ = poller.Wait(1)
Output:

func NewPoller

func NewPoller(readers ...*Sock) (*Poller, error)

NewPoller creates a new Poller instance. It accepts one or more readers to poll.

func (*Poller) Add

func (p *Poller) Add(reader *Sock) error

Add adds a reader to be polled.

func (*Poller) Destroy

func (p *Poller) Destroy()

Destroy destroys the Poller

func (*Poller) Remove

func (p *Poller) Remove(reader *Sock)

Remove removes a Sock from the poller

func (*Poller) Wait

func (p *Poller) Wait(millis int) *Sock

Wait waits for the timeout period in milliseconds for a Pollin event, and returns the first socket that returns one

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy wraps the CZMQ zproxy actor. A proxy actor switches messages between a frontend and backend socket, and also provides an optional capture socket messages can be mirrored to. The proxy can be paused and resumed.

Example
proxy := NewProxy()
defer proxy.Destroy()

// set front end address and socket type
err := proxy.SetFrontend(Pull, "inproc://frontend")
if err != nil {
	panic(err)
}

// set back end address and socket type
err = proxy.SetBackend(Push, "inproc://backend")
if err != nil {
	panic(err)
}

// set address for "tee"ing proxy traffic to
err = proxy.SetCapture("inproc://capture")
if err != nil {
	panic(err)
}

// we can pause the proxy
err = proxy.Pause()
if err != nil {
	panic(err)
}

// and we can resume it
err = proxy.Resume()
if err != nil {
	panic(err)
}

proxy.Destroy()
Output:

func NewProxy

func NewProxy() *Proxy

NewProxy creates a new Proxy instance.

func (*Proxy) Destroy

func (p *Proxy) Destroy()

Destroy destroys the proxy.

func (*Proxy) Pause

func (p *Proxy) Pause() error

Pause sends a message to the zproxy actor telling it to pause.

func (*Proxy) Resume

func (p *Proxy) Resume() error

Resume sends a message to the zproxy actor telling it to resume.

func (*Proxy) SetBackend

func (p *Proxy) SetBackend(sockType int, endpoint string) error

SetBackend accepts a socket type and endpoint, and sends a message to the zactor thread telling it to set up a socket bound to the endpoint.

func (*Proxy) SetCapture

func (p *Proxy) SetCapture(endpoint string) error

SetCapture accepts a socket endpoint and sets up a Push socket bound to that endpoint, that sends a copy of all messages passing through the proxy.

func (*Proxy) SetFrontend

func (p *Proxy) SetFrontend(sockType int, endpoint string) error

SetFrontend accepts a socket type and endpoint, and sends a message to the zactor thread telling it to set up a socket bound to the endpoint.

func (*Proxy) Verbose

func (p *Proxy) Verbose() error

Verbose sets the proxy to log information to stdout.

type Sock

type Sock struct {
	// contains filtered or unexported fields
}

Sock wraps the CZMQ zsock class.

Example (Output)
// create dealer socket
dealer, err := NewDealer("inproc://example")
if err != nil {
	panic(err)
}

// create router socket
router, err := NewRouter("inproc://example")
if err != nil {
	panic(err)
}

// send hello message
dealer.SendFrame([]byte("Hello"), FlagNone)

// receive hello message
request, err := router.RecvMessage()
if err != nil {
	panic(err)
}

// first frame is identify of client - let's append 'World'
// to the message and route it back.
request = append(request, []byte("World"))

// send reply
err = router.SendMessage(request)
if err != nil {
	panic(err)
}

// receive reply
reply, err := dealer.RecvMessage()
if err != nil {
	panic(err)
}

fmt.Printf("%s %s", string(reply[0]), string(reply[1]))
Output:

Hello World

func NewDealer

func NewDealer(endpoints string) (*Sock, error)

NewDealer creates a Dealer socket and calls Attach. The socket will Connect by default.

func NewPair

func NewPair(endpoints string) (*Sock, error)

NewPair creates a Pair socket and calls Attach. The socket will Connect by default.

func NewPub

func NewPub(endpoints string) (*Sock, error)

NewPub creates a Pub socket and calls Attach. The socket will Bind by default.

func NewPull

func NewPull(endpoints string) (*Sock, error)

NewPull creates a Pull socket and calls Attach. The socket will Bind by default.

func NewPush

func NewPush(endpoints string) (*Sock, error)

NewPush creates a Push socket and calls Attach. The socket will Connect by default.

func NewRep

func NewRep(endpoints string) (*Sock, error)

NewRep creates a Rep socket and calls Attach. The socket will Bind by default.

func NewReq

func NewReq(endpoints string) (*Sock, error)

NewReq creates a Req socket and calls Attach. The socket will Connect by default.

func NewRouter

func NewRouter(endpoints string) (*Sock, error)

NewRouter creates a Router socket and calls Attach. The socket will Bind by default.

func NewSock

func NewSock(t int) *Sock

NewSock creates a new socket. The caller source and line number are passed so CZMQ can report socket leaks intelligently.

func NewStream

func NewStream(endpoints string) (*Sock, error)

NewStream creates a Stream socket and calls Attach. The socket will Connect by default.

func NewSub

func NewSub(endpoints string, subscribe string) (*Sock, error)

NewSub creates a Sub socket and calls Attach. 'subscribe' is a comma delimited list of topics to subscribe to. The socket will Connect by default.

func NewXPub

func NewXPub(endpoints string) (*Sock, error)

NewXPub creates an XPub socket and calls Attach. The socket will Bind by default.

func NewXSub

func NewXSub(endpoints string) (*Sock, error)

NewXSub creates an XSub socket and calls Attach. The socket will Connect by default.

func (*Sock) Affinity

func (s *Sock) Affinity() int

Affinity returns the current value of the socket's affinity option

func (*Sock) Attach

func (s *Sock) Attach(endpoints string, serverish bool) error

Attach attaches a socket to zero or more endpoints. If endpoints is not null, parses as list of ZeroMQ endpoints, separated by commas, and prefixed by '@' (to bind the socket) or '>' (to attach the socket). If the endpoint does not start with '@' or '>', the serverish argument determines whether it is used to bind (serverish = true) or connect (serverish = false)

func (*Sock) Backlog

func (s *Sock) Backlog() int

Backlog returns the current value of the socket's backlog option

func (*Sock) Bind

func (s *Sock) Bind(endpoint string) (int, error)

Bind binds a socket to an endpoint. On success returns the port number used for tcp transports, or 0 for other transports. On failure returns a -1 for port, and an error.

func (*Sock) Connect

func (s *Sock) Connect(endpoint string) error

Connect connects a socket to an endpoint returns an error if the connect failed.

func (*Sock) CurvePublickey

func (s *Sock) CurvePublickey() string

CurvePublickey returns the current value of the socket's curve_publickey option

func (*Sock) CurveSecretkey

func (s *Sock) CurveSecretkey() string

CurveSecretkey returns the current value of the socket's curve_secretkey option

func (*Sock) CurveServer

func (s *Sock) CurveServer() int

CurveServer returns the current value of the socket's curve_server option

func (*Sock) CurveServerkey

func (s *Sock) CurveServerkey() string

CurveServerkey returns the current value of the socket's curve_serverkey option

func (*Sock) Destroy

func (s *Sock) Destroy()

Destroy destroys the underlying zsockT.

func (*Sock) Disconnect

func (s *Sock) Disconnect(endpoint string) error

Disconnect disconnects a socket from an endpoint. If returns an error if the endpoint was not found

func (*Sock) Events

func (s *Sock) Events() int

Events returns the current value of the socket's events option

func (*Sock) Fd

func (s *Sock) Fd() int

Fd returns the current value of the socket's fd option

func (*Sock) GetLastClientID

func (s *Sock) GetLastClientID() []byte

GetLastClientID returns the id of the last client you received a message from if the underlying socket is a Router or SERVER socket

func (*Sock) GetType

func (s *Sock) GetType() int

GetType returns the socket's type

func (*Sock) GssapiPlaintext

func (s *Sock) GssapiPlaintext() int

GssapiPlaintext returns the current value of the socket's gssapi_plaintext option

func (*Sock) GssapiPrincipal

func (s *Sock) GssapiPrincipal() string

GssapiPrincipal returns the current value of the socket's gssapi_principal option

func (*Sock) GssapiServer

func (s *Sock) GssapiServer() int

GssapiServer returns the current value of the socket's gssapi_server option

func (*Sock) GssapiServicePrincipal

func (s *Sock) GssapiServicePrincipal() string

GssapiServicePrincipal returns the current value of the socket's gssapi_service_principal option

func (*Sock) Identity

func (s *Sock) Identity() string

Identity returns the current value of the socket's identity option

func (*Sock) Immediate

func (s *Sock) Immediate() int

Immediate returns the current value of the socket's immediate option

func (*Sock) Ipv4only

func (s *Sock) Ipv4only() int

Ipv4only returns the current value of the socket's ipv4only option

func (*Sock) Ipv6

func (s *Sock) Ipv6() int

Ipv6 returns the current value of the socket's ipv6 option

func (*Sock) LastEndpoint

func (s *Sock) LastEndpoint() string

LastEndpoint returns the current value of the socket's last_endpoint option

func (*Sock) Linger

func (s *Sock) Linger() int

Linger returns the current value of the socket's linger option

func (*Sock) Maxmsgsize

func (s *Sock) Maxmsgsize() int

Maxmsgsize returns the current value of the socket's maxmsgsize option

func (*Sock) Mechanism

func (s *Sock) Mechanism() int

Mechanism returns the current value of the socket's mechanism option

func (*Sock) MulticastHops

func (s *Sock) MulticastHops() int

MulticastHops returns the current value of the socket's multicast_hops option

func (*Sock) PlainPassword

func (s *Sock) PlainPassword() string

PlainPassword returns the current value of the socket's plain_password option

func (*Sock) PlainServer

func (s *Sock) PlainServer() int

PlainServer returns the current value of the socket's plain_server option

func (*Sock) PlainUsername

func (s *Sock) PlainUsername() string

PlainUsername returns the current value of the socket's plain_username option

func (*Sock) Pollin

func (s *Sock) Pollin() bool

Pollin returns true if there is a Pollin event on the socket

func (*Sock) Pollout

func (s *Sock) Pollout() bool

Pollout returns true if there is a Pollout event on the socket

func (*Sock) Rate

func (s *Sock) Rate() int

Rate returns the current value of the socket's rate option

func (*Sock) Rcvbuf

func (s *Sock) Rcvbuf() int

Rcvbuf returns the current value of the socket's rcvbuf option

func (*Sock) Rcvhwm

func (s *Sock) Rcvhwm() int

Rcvhwm returns the current value of the socket's rcvhwm option

func (*Sock) Rcvmore

func (s *Sock) Rcvmore() int

Rcvmore returns the current value of the socket's rcvmore option

func (*Sock) Rcvtimeo

func (s *Sock) Rcvtimeo() int

Rcvtimeo returns the current value of the socket's rcvtimeo option

func (*Sock) Read

func (s *Sock) Read(p []byte) (int, error)

Read provides an io.Reader interface to a zeromq socket

func (*Sock) ReconnectIvl

func (s *Sock) ReconnectIvl() int

ReconnectIvl returns the current value of the socket's reconnect_ivl option

func (*Sock) ReconnectIvlMax

func (s *Sock) ReconnectIvlMax() int

ReconnectIvlMax returns the current value of the socket's reconnect_ivl_max option

func (*Sock) RecoveryIvl

func (s *Sock) RecoveryIvl() int

RecoveryIvl returns the current value of the socket's recovery_ivl option

func (*Sock) RecvFrame

func (s *Sock) RecvFrame() ([]byte, int, error)

RecvFrame reads a frame from the socket and returns it as a byte array, along with a more flag and and error (if there is an error)

func (*Sock) RecvFrameNoWait

func (s *Sock) RecvFrameNoWait() ([]byte, int, error)

RecvFrameNoWait receives a frame from the socket and returns it as a byte array if one is waiting. Returns an empty frame, a 0 more flag and an error if one is not immediately available

func (*Sock) RecvMessage

func (s *Sock) RecvMessage() ([][]byte, error)

RecvMessage receives a full message from the socket and returns it as an array of byte arrays.

func (*Sock) RecvMessageNoWait

func (s *Sock) RecvMessageNoWait() ([][]byte, error)

RecvMessageNoWait receives a full message from the socket and returns it as an array of byte arrays if one is waiting. Returns an empty message and an error if one is not immediately available

func (*Sock) SendFrame

func (s *Sock) SendFrame(data []byte, flags int) error

SendFrame sends a byte array via the socket. For the flags value, use 0 for a single message, or SNDFlagMore if it is a multi-part message

func (*Sock) SendMessage

func (s *Sock) SendMessage(parts [][]byte) error

SendMessage accepts an array of byte arrays and sends it as a multi-part message.

func (*Sock) SetAffinity

func (s *Sock) SetAffinity(val int)

SetAffinity sets the affinity option for the socket

func (*Sock) SetBacklog

func (s *Sock) SetBacklog(val int)

SetBacklog sets the backlog option for the socket

func (*Sock) SetConflate

func (s *Sock) SetConflate(val int)

SetConflate sets the conflate option for the socket

func (*Sock) SetCurvePublickey

func (s *Sock) SetCurvePublickey(val string)

SetCurvePublickey sets the curve_publickey option for the socket

func (*Sock) SetCurveSecretkey

func (s *Sock) SetCurveSecretkey(val string)

SetCurveSecretkey sets the curve_secretkey option for the socket

func (*Sock) SetCurveServer

func (s *Sock) SetCurveServer(val int)

SetCurveServer sets the curve_server option for the socket

func (*Sock) SetCurveServerkey

func (s *Sock) SetCurveServerkey(val string)

SetCurveServerkey sets the curve_serverkey option for the socket

func (*Sock) SetDelayAttachOnConnect

func (s *Sock) SetDelayAttachOnConnect(val int)

SetDelayAttachOnConnect sets the delay_attach_on_connect option for the socket

func (*Sock) SetGssapiPlaintext

func (s *Sock) SetGssapiPlaintext(val int)

SetGssapiPlaintext sets the gssapi_plaintext option for the socket

func (*Sock) SetGssapiPrincipal

func (s *Sock) SetGssapiPrincipal(val string)

SetGssapiPrincipal sets the gssapi_principal option for the socket

func (*Sock) SetGssapiServer

func (s *Sock) SetGssapiServer(val int)

SetGssapiServer sets the gssapi_server option for the socket

func (*Sock) SetGssapiServicePrincipal

func (s *Sock) SetGssapiServicePrincipal(val string)

SetGssapiServicePrincipal sets the gssapi_service_principal option for the socket

func (*Sock) SetIdentity

func (s *Sock) SetIdentity(val string)

SetIdentity sets the identity option for the socket

func (*Sock) SetImmediate

func (s *Sock) SetImmediate(val int)

SetImmediate sets the immediate option for the socket

func (*Sock) SetIpv4only

func (s *Sock) SetIpv4only(val int)

SetIpv4only sets the ipv4only option for the socket

func (*Sock) SetIpv6

func (s *Sock) SetIpv6(val int)

SetIpv6 sets the ipv6 option for the socket

func (*Sock) SetLastClientID

func (s *Sock) SetLastClientID(id []byte)

func (*Sock) SetLinger

func (s *Sock) SetLinger(val int)

SetLinger sets the linger option for the socket

func (*Sock) SetMaxmsgsize

func (s *Sock) SetMaxmsgsize(val int)

SetMaxmsgsize sets the maxmsgsize option for the socket

func (*Sock) SetMulticastHops

func (s *Sock) SetMulticastHops(val int)

SetMulticastHops sets the multicast_hops option for the socket

func (*Sock) SetPlainPassword

func (s *Sock) SetPlainPassword(val string)

SetPlainPassword sets the plain_password option for the socket

func (*Sock) SetPlainServer

func (s *Sock) SetPlainServer(val int)

SetPlainServer sets the plain_server option for the socket

func (*Sock) SetPlainUsername

func (s *Sock) SetPlainUsername(val string)

SetPlainUsername sets the plain_username option for the socket

func (*Sock) SetProbeRouter

func (s *Sock) SetProbeRouter(val int)

SetProbeRouter sets the probe_router option for the socket

func (*Sock) SetRate

func (s *Sock) SetRate(val int)

SetRate sets the rate option for the socket

func (*Sock) SetRcvbuf

func (s *Sock) SetRcvbuf(val int)

SetRcvbuf sets the rcvbuf option for the socket

func (*Sock) SetRcvhwm

func (s *Sock) SetRcvhwm(val int)

SetRcvhwm sets the rcvhwm option for the socket

func (*Sock) SetRcvtimeo

func (s *Sock) SetRcvtimeo(val int)

SetRcvtimeo sets the rcvtimeo option for the socket

func (*Sock) SetReconnectIvl

func (s *Sock) SetReconnectIvl(val int)

SetReconnectIvl sets the reconnect_ivl option for the socket

func (*Sock) SetReconnectIvlMax

func (s *Sock) SetReconnectIvlMax(val int)

SetReconnectIvlMax sets the reconnect_ivl_max option for the socket

func (*Sock) SetRecoveryIvl

func (s *Sock) SetRecoveryIvl(val int)

SetRecoveryIvl sets the recovery_ivl option for the socket

func (*Sock) SetReqCorrelate

func (s *Sock) SetReqCorrelate(val int)

SetReqCorrelate sets the req_correlate option for the socket

func (*Sock) SetReqRelaxed

func (s *Sock) SetReqRelaxed(val int)

SetReqRelaxed sets the req_relaxed option for the socket

func (*Sock) SetRouterHandover

func (s *Sock) SetRouterHandover(val int)

SetRouterHandover sets the router_handover option for the socket

func (*Sock) SetRouterMandatory

func (s *Sock) SetRouterMandatory(val int)

SetRouterMandatory sets the router_mandatory option for the socket

func (*Sock) SetRouterRaw

func (s *Sock) SetRouterRaw(val int)

SetRouterRaw sets the router_raw option for the socket

func (*Sock) SetSndbuf

func (s *Sock) SetSndbuf(val int)

SetSndbuf sets the sndbuf option for the socket

func (*Sock) SetSndhwm

func (s *Sock) SetSndhwm(val int)

SetSndhwm sets the sndhwm option for the socket

func (*Sock) SetSndtimeo

func (s *Sock) SetSndtimeo(val int)

SetSndtimeo sets the sndtimeo option for the socket

func (*Sock) SetSubscribe

func (s *Sock) SetSubscribe(val string)

SetSubscribe sets the subscribe option for the socket

func (*Sock) SetTcpAcceptFilter

func (s *Sock) SetTcpAcceptFilter(val string)

SetTcpAcceptFilter sets the tcp_accept_filter option for the socket

func (*Sock) SetTcpKeepalive

func (s *Sock) SetTcpKeepalive(val int)

SetTcpKeepalive sets the tcp_keepalive option for the socket

func (*Sock) SetTcpKeepaliveCnt

func (s *Sock) SetTcpKeepaliveCnt(val int)

SetTcpKeepaliveCnt sets the tcp_keepalive_cnt option for the socket

func (*Sock) SetTcpKeepaliveIdle

func (s *Sock) SetTcpKeepaliveIdle(val int)

SetTcpKeepaliveIdle sets the tcp_keepalive_idle option for the socket

func (*Sock) SetTcpKeepaliveIntvl

func (s *Sock) SetTcpKeepaliveIntvl(val int)

SetTcpKeepaliveIntvl sets the tcp_keepalive_intvl option for the socket

func (*Sock) SetTos

func (s *Sock) SetTos(val int)

SetTos sets the tos option for the socket

func (*Sock) SetUnsubscribe

func (s *Sock) SetUnsubscribe(val string)

SetUnsubscribe sets the unsubscribe option for the socket

func (*Sock) SetXpubVerbose

func (s *Sock) SetXpubVerbose(val int)

SetXpubVerbose sets the xpub_verbose option for the socket

func (*Sock) SetZapDomain

func (s *Sock) SetZapDomain(val string)

SetZapDomain sets the zap_domain option for the socket

func (*Sock) Sndbuf

func (s *Sock) Sndbuf() int

Sndbuf returns the current value of the socket's sndbuf option

func (*Sock) Sndhwm

func (s *Sock) Sndhwm() int

Sndhwm returns the current value of the socket's sndhwm option

func (*Sock) Sndtimeo

func (s *Sock) Sndtimeo() int

Sndtimeo returns the current value of the socket's sndtimeo option

func (*Sock) TcpAcceptFilter

func (s *Sock) TcpAcceptFilter() string

TcpAcceptFilter returns the current value of the socket's tcp_accept_filter option

func (*Sock) TcpKeepalive

func (s *Sock) TcpKeepalive() int

TcpKeepalive returns the current value of the socket's tcp_keepalive option

func (*Sock) TcpKeepaliveCnt

func (s *Sock) TcpKeepaliveCnt() int

TcpKeepaliveCnt returns the current value of the socket's tcp_keepalive_cnt option

func (*Sock) TcpKeepaliveIdle

func (s *Sock) TcpKeepaliveIdle() int

TcpKeepaliveIdle returns the current value of the socket's tcp_keepalive_idle option

func (*Sock) TcpKeepaliveIntvl

func (s *Sock) TcpKeepaliveIntvl() int

TcpKeepaliveIntvl returns the current value of the socket's tcp_keepalive_intvl option

func (*Sock) Tos

func (s *Sock) Tos() int

Tos returns the current value of the socket's tos option

func (*Sock) Type

func (s *Sock) Type() int

Type returns the current value of the socket's type option

func (*Sock) Unbind

func (s *Sock) Unbind(endpoint string) error

Unbind unbinds a socket from an endpoint. If returns an error if the endpoint was not found

func (*Sock) Write

func (s *Sock) Write(p []byte) (int, error)

Write provides an io.Writer interface to a zeromq socket

func (*Sock) ZapDomain

func (s *Sock) ZapDomain() string

ZapDomain returns the current value of the socket's zap_domain option

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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