Documentation
¶
Overview ¶
Package zmq4 implements the ØMQ sockets and protocol for ZeroMQ-4.
For more informations, see http://zeromq.org.
Index ¶
- Constants
- Variables
- func AuthAllow(domain string, addresses ...string)
- func AuthCurveAdd(domain, publicKey string)
- func AuthCurvePublic(secretKey string) (string, error)
- func AuthCurveRemove(domain, publicKey string)
- func AuthDeny(domain string, addresses ...string)
- func AuthSetMetadataHandler(handler MetadataHandler)
- func AuthSetVerbose(verbose bool)
- func AuthStart() error
- func AuthStop()
- func BackendName() string
- func CWithID(id SocketIdentity) czmq4.SockOption
- func IsCZMQAvailable() bool
- func NewCurveKeypair() (publicKey, secretKey string, err error)
- func Proxy(frontend, backend Socket) error
- func RegisterTransport(name string, trans transport.Transport) error
- func Transports() []string
- func Z85decode(text string) ([]byte, error)
- func Z85encode(data []byte) string
- type Cmd
- type Conn
- func (c *Conn) Close() error
- func (conn *Conn) Closed() bool
- func (c *Conn) Read(p []byte) (int, error)
- func (c *Conn) RecvCmd() (Cmd, error)
- func (c *Conn) RecvMsg() (Msg, error)
- func (c *Conn) SendCmd(name string, body []byte) error
- func (c *Conn) SendMsg(msg Msg) error
- func (conn *Conn) SetClosed()
- func (c *Conn) Write(p []byte) (int, error)
- type Metadata
- type MetadataHandler
- type Msg
- type MsgType
- type Option
- func WithAutomaticReconnect(auto bool) Option
- func WithDialerMaxRetries(maxRetries int) Option
- func WithDialerRetry(retry time.Duration) Option
- func WithID(id SocketIdentity) Option
- func WithLogger(logger interface{}) Option
- func WithSecurity(sec Security) Option
- func WithTimeout(timeout time.Duration) Option
- type Property
- type Queue
- type Security
- type SecurityType
- type Socket
- func NewCDealer(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCPair(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCPub(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCPull(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCPush(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCRep(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCReq(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCRouter(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCStream(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCSub(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCXPub(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewCXSub(ctx context.Context, opts ...czmq4.SockOption) Socket
- func NewDealer(ctx context.Context, opts ...Option) Socket
- func NewPair(ctx context.Context, opts ...Option) Socket
- func NewPub(ctx context.Context, opts ...Option) Socket
- func NewPull(ctx context.Context, opts ...Option) Socket
- func NewPush(ctx context.Context, opts ...Option) Socket
- func NewRep(ctx context.Context, opts ...Option) Socket
- func NewReq(ctx context.Context, opts ...Option) Socket
- func NewRouter(ctx context.Context, opts ...Option) Socket
- func NewStream(ctx context.Context, opts ...Option) Socket
- func NewSub(ctx context.Context, opts ...Option) Socket
- func NewXPub(ctx context.Context, opts ...Option) Socket
- func NewXSub(ctx context.Context, opts ...Option) Socket
- type SocketIdentity
- type SocketType
- type Topics
- type UnknownTransportError
Constants ¶
const ( CmdCancel = "CANCEL" CmdError = "ERROR" CmdHello = "HELLO" CmdInitiate = "INITIATE" CmdPing = "PING" CmdPong = "PONG" CmdReady = "READY" CmdSubscribe = "SUBSCRIBE" CmdUnsubscribe = "UNSUBSCRIBE" CmdWelcome = "WELCOME" )
ZMTP commands as per:
https://rfc.zeromq.org/spec:23/ZMTP/#commands
const ( OptionSubscribe = "SUBSCRIBE" OptionUnsubscribe = "UNSUBSCRIBE" OptionHWM = "HWM" OptionIdentity = "IDENTITY" )
Socket option constants - only essential ones
const (
DefaultSendHwm = 1000
)
Variables ¶
var ( ErrBadCmd = errors.New("zmq4: invalid command name") ErrBadFrame = errors.New("zmq4: invalid frame") )
var (
ErrBadProperty = errors.New("zmq4: bad property")
)
var ErrClosedConn = errors.New("zmq4: read/write on closed connection")
Functions ¶
func AuthCurveAdd ¶ added in v4.2.1
func AuthCurveAdd(domain, publicKey string)
AuthCurveAdd adds a CURVE public key (no-op for simplicity)
func AuthCurvePublic ¶ added in v4.2.1
AuthCurvePublic derives the public key from a secret key
func AuthCurveRemove ¶ added in v4.2.1
func AuthCurveRemove(domain, publicKey string)
AuthCurveRemove removes a CURVE public key (no-op for simplicity)
func AuthSetMetadataHandler ¶ added in v4.2.1
func AuthSetMetadataHandler(handler MetadataHandler)
AuthSetMetadataHandler sets the metadata handler (no-op for simplicity)
func AuthSetVerbose ¶ added in v4.2.1
func AuthSetVerbose(verbose bool)
AuthSetVerbose sets verbose mode (no-op)
func AuthStart ¶ added in v4.2.1
func AuthStart() error
AuthStart starts authentication (simplified)
func BackendName ¶ added in v4.2.1
func BackendName() string
BackendName returns the name of the current backend
func CWithID ¶ added in v4.2.2
func CWithID(id SocketIdentity) czmq4.SockOption
CWithID configures a ZeroMQ socket identity.
func IsCZMQAvailable ¶ added in v4.2.1
func IsCZMQAvailable() bool
IsCZMQAvailable returns false when using pure Go backend
func NewCurveKeypair ¶ added in v4.2.1
NewCurveKeypair generates a new CURVE keypair
func Proxy ¶
Proxy starts a proxy that forwards messages between frontend and backend. This is the ONLY way to create a proxy - no complex variations.
func RegisterTransport ¶
RegisterTransport registers a new transport with the zmq4 package.
func Transports ¶
func Transports() []string
Transports returns the sorted list of currently registered transports.
Types ¶
type Conn ¶
type Conn struct { Server bool Meta Metadata Peer struct { Server bool Meta Metadata } // contains filtered or unexported fields }
Conn implements the ZeroMQ Message Transport Protocol as defined in https://rfc.zeromq.org/spec:23/ZMTP/.
func Open ¶
func Open(rw net.Conn, sec Security, sockType SocketType, sockID SocketIdentity, server bool, onCloseErrorCB func(c *Conn)) (*Conn, error)
Open opens a ZMTP connection over rw with the given security, socket type and identity. An optional onCloseErrorCB can be provided to inform the caller when this Conn is closed. Open performs a complete ZMTP handshake.
type Metadata ¶
Metadata is describing a Conn's metadata information.
func (Metadata) MarshalZMTP ¶
MarshalZMTP marshals MetaData to ZMTP encoded data.
func (*Metadata) UnmarshalZMTP ¶
UnmarshalZMTP unmarshals MetaData from a ZMTP encoded data.
type MetadataHandler ¶ added in v4.2.1
MetadataHandler simplified
type Msg ¶
Msg is a ZMTP message, possibly composed of multiple frames.
func NewMsgFrom ¶
func NewMsgFromString ¶
func NewMsgString ¶
type Option ¶
type Option func(s *socket)
Option configures a ZeroMQ socket - ONE way to configure
func WithAutomaticReconnect ¶
WithAutomaticReconnect is a no-op for compatibility
func WithDialerMaxRetries ¶
WithDialerMaxRetries is a no-op for compatibility
func WithDialerRetry ¶
WithDialerRetry is a no-op for compatibility
func WithLogger ¶
func WithLogger(logger interface{}) Option
WithLogger is a no-op for compatibility
func WithSecurity ¶
WithSecurity sets security mechanism (default: NULL)
type Property ¶
Property describes a Conn metadata's entry. The on-wire respresentation of Property is specified by:
https://rfc.zeromq.org/spec:23/ZMTP/
type Security ¶
type Security interface { // Type returns the security mechanism type. Type() SecurityType // Handshake implements the ZMTP security handshake according to // this security mechanism. // see: // https://rfc.zeromq.org/spec:23/ZMTP/ // https://rfc.zeromq.org/spec:24/ZMTP-PLAIN/ // https://rfc.zeromq.org/spec:25/ZMTP-CURVE/ Handshake(conn *Conn, server bool) error // Encrypt writes the encrypted form of data to w. Encrypt(w io.Writer, data []byte) (int, error) // Decrypt writes the decrypted form of data to w. Decrypt(w io.Writer, data []byte) (int, error) }
Security is an interface for ZMTP security mechanisms
type SecurityType ¶
type SecurityType string
SecurityType denotes types of ZMTP security mechanisms
const ( // NullSecurityType is an empty security mechanism // that does no authentication nor encryption. NullSecurity SecurityType = "NULL" // PlainSecurity is a security mechanism that uses // plaintext passwords. It is a reference implementation and // should not be used to anything important. PlainSecurity SecurityType = "PLAIN" // CurveSecurity uses ZMQ_CURVE for authentication // and encryption. CurveSecurity SecurityType = "CURVE" )
type Socket ¶
type Socket interface { // Close closes the open Socket. Close() error // Send puts the message on the outbound send queue. // // Send blocks until the message can be queued or the send deadline expires. Send(msg Msg) error // SendMulti puts the message on the outbound send queue. // // SendMulti blocks until the message can be queued or the send deadline // expires. The message will be sent as a multipart message. SendMulti(msg Msg) error // Recv receives a complete message. Recv() (Msg, error) // Listen connects a local endpoint to the Socket. // // In ZeroMQ's terminology, it binds. Listen(ep string) error // Dial connects a remote endpoint to the Socket. // // In ZeroMQ's terminology, it connects. Dial(ep string) error // Type returns the type of this Socket (for example PUB, SUB, etc.) Type() SocketType // Addr returns the listener's address. It returns nil if the socket isn't a // listener. Addr() net.Addr // GetOption retrieves an option for a socket. GetOption(name string) (interface{}, error) // SetOption sets an option for a socket. SetOption(name string, value interface{}) error }
Socket represents a ZeroMQ socket.
func NewCDealer ¶ added in v4.2.2
func NewCDealer(ctx context.Context, opts ...czmq4.SockOption) Socket
func NewCRouter ¶ added in v4.2.2
func NewCRouter(ctx context.Context, opts ...czmq4.SockOption) Socket
func NewCStream ¶ added in v4.2.2
func NewCStream(ctx context.Context, opts ...czmq4.SockOption) Socket
func NewDealer ¶
NewDealer returns a new DEALER ZeroMQ socket. The returned socket value is initially unbound.
func NewPair ¶
NewPair returns a new PAIR ZeroMQ socket. The returned socket value is initially unbound.
func NewPub ¶
NewPub returns a new PUB ZeroMQ socket. The returned socket value is initially unbound.
func NewPull ¶
NewPull returns a new PULL ZeroMQ socket. The returned socket value is initially unbound.
func NewPush ¶
NewPush returns a new PUSH ZeroMQ socket. The returned socket value is initially unbound.
func NewRep ¶
NewRep returns a new REP ZeroMQ socket. The returned socket value is initially unbound.
func NewReq ¶
NewReq returns a new REQ ZeroMQ socket. The returned socket value is initially unbound.
func NewRouter ¶
NewRouter returns a new ROUTER ZeroMQ socket. The returned socket value is initially unbound.
func NewStream ¶ added in v4.2.1
NewStream returns a new STREAM ZeroMQ socket. The returned socket value is initially unbound. STREAM sockets are used to send and receive TCP data from a non-ZeroMQ peer when using the tcp:// transport.
func NewSub ¶
NewSub returns a new SUB ZeroMQ socket. The returned socket value is initially unbound.
type SocketIdentity ¶
type SocketIdentity []byte
SocketIdentity is the ZMTP metadata socket identity. See:
https://rfc.zeromq.org/spec:23/ZMTP/.
func (SocketIdentity) String ¶
func (id SocketIdentity) String() string
type SocketType ¶
type SocketType string
SocketType is a ZeroMQ socket type.
const ( Pair SocketType = "PAIR" // a ZMQ_PAIR socket Pub SocketType = "PUB" // a ZMQ_PUB socket Sub SocketType = "SUB" // a ZMQ_SUB socket Req SocketType = "REQ" // a ZMQ_REQ socket Rep SocketType = "REP" // a ZMQ_REP socket Dealer SocketType = "DEALER" // a ZMQ_DEALER socket Router SocketType = "ROUTER" // a ZMQ_ROUTER socket Pull SocketType = "PULL" // a ZMQ_PULL socket Push SocketType = "PUSH" // a ZMQ_PUSH socket XPub SocketType = "XPUB" // a ZMQ_XPUB socket XSub SocketType = "XSUB" // a ZMQ_XSUB socket Stream SocketType = "STREAM" // a ZMQ_STREAM socket )
func (SocketType) IsCompatible ¶
func (sck SocketType) IsCompatible(peer SocketType) bool
IsCompatible checks whether two sockets are compatible and thus can be connected together. See https://rfc.zeromq.org/spec:23/ZMTP/ for more informations.
type Topics ¶
type Topics interface { // Topics returns the sorted list of topics a socket is subscribed to. Topics() []string }
Topics is an interface that wraps the basic Topics method.
type UnknownTransportError ¶
type UnknownTransportError struct {
Name string
}
UnknownTransportError records an error when trying to use an unknown transport.
func (UnknownTransportError) Error ¶
func (ute UnknownTransportError) Error() string
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
errgroup
Package errgroup is bit more advanced than golang.org/x/sync/errgroup.
|
Package errgroup is bit more advanced than golang.org/x/sync/errgroup. |
inproc
Package inproc provides tools to implement an in-process asynchronous pipe of net.Conns.
|
Package inproc provides tools to implement an in-process asynchronous pipe of net.Conns. |
Package networking provides high-level ZMQ4 networking primitives for distributed systems communication.
|
Package networking provides high-level ZMQ4 networking primitives for distributed systems communication. |
security
|
|
null
Package null provides the ZeroMQ NULL security mechanism
|
Package null provides the ZeroMQ NULL security mechanism |
plain
Package plain provides the ZeroMQ PLAIN security mechanism as specified by: https://rfc.zeromq.org/spec:24/ZMTP-PLAIN/
|
Package plain provides the ZeroMQ PLAIN security mechanism as specified by: https://rfc.zeromq.org/spec:24/ZMTP-PLAIN/ |
Package transport defines the Transport interface and provides a net-based implementation that can be used by zmq4 sockets to exchange messages.
|
Package transport defines the Transport interface and provides a net-based implementation that can be used by zmq4 sockets to exchange messages. |