zmqchan

package module
v0.0.0-...-0bfd16e Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2016 License: BSD-2-Clause Imports: 5 Imported by: 0

README

zmqchan Build Status GoDoc GitHub release

zmqchan provides an idiomatic channels interface for go to zeromq

A library to provide channels for the Go interface to ZeroMQ version 4.

Keywords: zmq, zeromq, 0mq, networks, distributed computing, message passing, fanout, pubsub, pipeline, request-reply

zmqchan provides a zmqchan.ChannelPair class which wraps a zmq.Socket into a TX and RX channel.

Currently zmq.Sockets are not threadsafe. These are difficulty to use in combination with golang channels as you can poll on a set of sockets, or select on a set of channels, but not both. This creates problems if you want to use conventional go idioms, e.g. using a chan bool for ending goroutines.

This library provides a means of wrapping a zmq.Socket into a zmq.ChannelPair, which provides an Rx and Tx channel (as well as an error channel). This is loosely based on the idea of the go-zmq binding by vaughan0 but works with ZMQ 4.x.

This is currently lightly tested / experimental.

See also
  • zmq4 - The go interface to ZMQ4 used by zmqchan
  • go-zmq - Another go interface to ZMQ4

Install

go get github.com/abligh/zmqchan

Docs

Documentation

Index

Constants

View Source
const (
	ZC_IN  = iota
	ZC_OUT = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelPair

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

ChannelPair provides a structure that wraps a zeromq zmq.Socket and provides TX, RX and error channels.

This enables a zmq.Socket to be used in a threadsafe manner between goroutines in an idiomatic manner using channels.

This library relies completely on https://github.com/pebbe/zmq4 to provide the interface to zeromq.

See NewChannelPair for more details.

func NewChannelPair

func NewChannelPair(zSock *zmq.Socket, txbuf int, rxbuf int) (*ChannelPair, error)

NewChannelPair produces a new ChannelPair. Pass a zmq.Socket, plus the buffering parameters for the channels.

If this call succeeds (i.e. if a nil error is returned), then a ChannelPair is returned, and control of your zmq.Socket is passed irrevocably to this routine. You should forget you ever had the socket. Do not attempt to use it in any way, as its manipulation is now the responsibility of goroutines launched by this routine. Closing the ChannelPair will also close your zmq.Socket.

If this routine errors, it is the caller's responsibility to close the zmq.Socket.

The buffering parameters control the maximum amount of buffered data, in and out. An extra message may be buffered under some circumstances for internal reasons.

func (*ChannelPair) Close

func (cp *ChannelPair) Close() error

Close closes a ChannelPair. This will kill the internal goroutines, and close the main zmq.Socket. It will also close the error channel, so a select() on it will return 'ok' as false. If an error is produced either during the close or has been produced prior to the close, it will be returned.

func (*ChannelPair) Errors

func (cp *ChannelPair) Errors() <-chan error

Errors get the errors channel as a read-only channel.

func (*ChannelPair) RxChan

func (cp *ChannelPair) RxChan() <-chan [][]byte

RxChan gets the RX channel as a read-only channel.

func (*ChannelPair) TxChan

func (cp *ChannelPair) TxChan() chan<- [][]byte

TxChan gets the TX channel as a write-only channel.

Jump to

Keyboard shortcuts

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