public class ZMQ
extends java.lang.Object
The ØMQ lightweight messaging kernel is a library which extends the standard socket interfaces with features traditionally provided by specialised messaging middleware products. ØMQ sockets provide an abstraction of asynchronous message queues, multiple messaging patterns, message filtering (subscriptions), seamless access to multiple transport protocols and more.
Following is an overview of ØMQ concepts, describes how ØMQ abstracts standard sockets and provides a reference manual for the functions provided by the ØMQ library.
Before using any ØMQ library functions you must create a ØMQ context
using context(int)
.
When you exit your application you must destroy the context using ZMQ.Context.close()
.
ZMQ.Context.socket(SocketType)
and then pass it to a newly created thread as part of thread initialization.
ØMQ sockets
present an abstraction of a asynchronous message queue,
with the exact queueing semantics depending on the socket type in use.
A ØMQ socket can use multiple different underlying transport mechanisms. Each transport mechanism is suited to a particular purpose and has its own advantages and drawbacks.
The following transport mechanisms are provided:
ØMQ provides proxies to create fanout and fan-in topologies. A proxy connects a frontend socket to a backend socket and switches all messages between the two sockets, opaquely. A proxy may optionally capture all traffic to a third socket.
A ØMQ socket can select a security mechanism. Both peers must use the same security mechanism.
The following security mechanisms are provided for IPC and TCP connections:
Modifier and Type | Class and Description |
---|---|
static class |
ZMQ.CancellationToken
A cancellation token that allows canceling ongoing Socket send/receive operations.
|
static class |
ZMQ.Context
Container for all sockets in a single process,
acting as the transport for inproc sockets,
which are the fastest way to connect threads in one process.
|
static class |
ZMQ.Curve
Class that interfaces the generation of CURVE key pairs.
|
static class |
ZMQ.Error
Resolve code from errornumber.
|
static class |
ZMQ.Event
Inner class: Event.
|
static class |
ZMQ.Poller
Provides a mechanism for applications to multiplex input/output events in a level-triggered fashion over a set of sockets
|
static class |
ZMQ.PollItem |
static class |
ZMQ.Socket
Abstracts an asynchronous message queue, with the exact queuing semantics depending on the socket type in use.
|
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
CHARSET |
static int |
DEALER
Deprecated.
|
static int |
DONTWAIT
Socket flag to indicate a nonblocking send or recv mode.
|
static int |
DOWNSTREAM
Deprecated.
|
static int |
EVENT_ACCEPT_FAILED
EVENT_ACCEPT_FAILED: could not accept client connection.
|
static int |
EVENT_ACCEPTED
EVENT_ACCEPTED: connection accepted to bound interface.
|
static int |
EVENT_ALL
EVENT_ALL: all events known.
|
static int |
EVENT_BIND_FAILED
EVENT_BIND_FAILED: socket could not bind to an address.
|
static int |
EVENT_CLOSE_FAILED
EVENT_CLOSE_FAILED: connection couldn't be closed.
|
static int |
EVENT_CLOSED
EVENT_CLOSED: connection closed.
|
static int |
EVENT_CONNECT_DELAYED
EVENT_CONNECT_DELAYED: synchronous connect failed, it's being polled.
|
static int |
EVENT_CONNECT_RETRIED
EVENT_CONNECT_RETRIED: asynchronous connect / reconnection attempt.
|
static int |
EVENT_CONNECTED
EVENT_CONNECTED: connection established.
|
static int |
EVENT_DELAYED
Deprecated.
|
static int |
EVENT_DISCONNECTED
EVENT_DISCONNECTED: broken session.
|
static int |
EVENT_HANDSHAKE_PROTOCOL
EVENT_HANDSHAKE_PROTOCOL: protocol has been successfully negotiated.
|
static int |
EVENT_LISTENING
EVENT_LISTENING: socket bound to an address, ready to accept connections.
|
static int |
EVENT_MONITOR_STOPPED
EVENT_MONITOR_STOPPED: monitor has been stopped.
|
static int |
EVENT_RETRIED
Deprecated.
|
static int |
FORWARDER
Deprecated.
|
static int |
HANDSHAKE_FAILED_AUTH
Failed authentication requests.
|
static int |
HANDSHAKE_FAILED_NO_DETAIL
Unspecified system errors during handshake.
|
static int |
HANDSHAKE_FAILED_PROTOCOL
Protocol errors between ZMTP peers or between server and ZAP handler.
|
static int |
HANDSHAKE_SUCCEEDED
Handshake complete successfully with successful authentication (if
enabled).
|
static byte[] |
MESSAGE_SEPARATOR |
static int |
NOBLOCK |
static int |
PAIR
Deprecated.
|
static byte[] |
PROXY_PAUSE |
static byte[] |
PROXY_RESUME |
static byte[] |
PROXY_TERMINATE |
static int |
PUB
Deprecated.
|
static int |
PULL
Deprecated.
|
static int |
PUSH
Deprecated.
|
static int |
QUEUE
Deprecated.
|
static int |
REP
Deprecated.
|
static int |
REQ
Deprecated.
|
static int |
ROUTER
Deprecated.
|
static int |
SNDMORE
Socket flag to indicate that more message parts are coming.
|
static int |
STREAM
Deprecated.
|
static int |
STREAMER
Deprecated.
|
static int |
SUB
Deprecated.
|
static byte[] |
SUBSCRIPTION_ALL |
static int |
UPSTREAM
Deprecated.
|
static int |
XPUB
Deprecated.
|
static int |
XREP
Deprecated.
As of release 3.0 of zeromq, replaced by
ROUTER |
static int |
XREQ
Deprecated.
As of release 3.0 of zeromq, replaced by
DEALER |
static int |
XSUB
Deprecated.
|
Modifier | Constructor and Description |
---|---|
private |
ZMQ() |
Modifier and Type | Method and Description |
---|---|
static ZMQ.Context |
context(int ioThreads)
Create a new Context.
|
static boolean |
device(int type,
ZMQ.Socket frontend,
ZMQ.Socket backend)
Deprecated.
|
static int |
getFullVersion() |
static int |
getMajorVersion() |
static int |
getMinorVersion() |
static int |
getPatchVersion() |
static java.lang.String |
getVersionString() |
static int |
makeVersion(int major,
int minor,
int patch) |
static void |
msleep(long millis) |
static int |
poll(java.nio.channels.Selector selector,
ZMQ.PollItem[] items,
int count,
long timeout) |
static int |
poll(java.nio.channels.Selector selector,
ZMQ.PollItem[] items,
long timeout) |
static boolean |
proxy(ZMQ.Socket frontend,
ZMQ.Socket backend,
ZMQ.Socket capture)
Starts the built-in 0MQ proxy in the current application thread.
|
static boolean |
proxy(ZMQ.Socket frontend,
ZMQ.Socket backend,
ZMQ.Socket capture,
ZMQ.Socket control) |
static void |
sleep(long seconds) |
static void |
sleep(long amount,
java.util.concurrent.TimeUnit unit) |
public static final int SNDMORE
public static final int DONTWAIT
public static final int NOBLOCK
@Deprecated public static final int PAIR
@Deprecated public static final int PUB
@Deprecated public static final int SUB
@Deprecated public static final int REQ
@Deprecated public static final int REP
@Deprecated public static final int DEALER
@Deprecated public static final int XREQ
DEALER
@Deprecated public static final int ROUTER
@Deprecated public static final int XREP
ROUTER
@Deprecated public static final int PULL
@Deprecated public static final int PUSH
@Deprecated public static final int XPUB
@Deprecated public static final int XSUB
@Deprecated public static final int STREAM
@Deprecated public static final int STREAMER
@Deprecated public static final int FORWARDER
@Deprecated public static final int QUEUE
@Deprecated public static final int UPSTREAM
PULL
,
Constant Field Values@Deprecated public static final int DOWNSTREAM
PUSH
,
Constant Field Valuespublic static final int EVENT_CONNECTED
public static final int EVENT_CONNECT_DELAYED
@Deprecated public static final int EVENT_DELAYED
EVENT_CONNECT_DELAYED
,
Constant Field Valuespublic static final int EVENT_CONNECT_RETRIED
@Deprecated public static final int EVENT_RETRIED
EVENT_CONNECT_RETRIED
,
Constant Field Valuespublic static final int EVENT_LISTENING
public static final int EVENT_BIND_FAILED
public static final int EVENT_ACCEPTED
public static final int EVENT_ACCEPT_FAILED
public static final int EVENT_CLOSED
public static final int EVENT_CLOSE_FAILED
public static final int EVENT_DISCONNECTED
public static final int EVENT_MONITOR_STOPPED
public static final int EVENT_HANDSHAKE_PROTOCOL
public static final int EVENT_ALL
public static final int HANDSHAKE_FAILED_NO_DETAIL
public static final int HANDSHAKE_SUCCEEDED
public static final int HANDSHAKE_FAILED_PROTOCOL
public static final int HANDSHAKE_FAILED_AUTH
public static final byte[] MESSAGE_SEPARATOR
public static final byte[] SUBSCRIPTION_ALL
public static final byte[] PROXY_PAUSE
public static final byte[] PROXY_RESUME
public static final byte[] PROXY_TERMINATE
public static final java.nio.charset.Charset CHARSET
public static ZMQ.Context context(int ioThreads)
ioThreads
- Number of threads to use, usually 1 is sufficient for most use cases.@Deprecated public static boolean device(int type, ZMQ.Socket frontend, ZMQ.Socket backend)
public static boolean proxy(ZMQ.Socket frontend, ZMQ.Socket backend, ZMQ.Socket capture)
Before calling ZMQ.proxy() you must set any socket options, and connect or bind both frontend and backend sockets. The two conventional proxy models are:
ZMQ.proxy() runs in the current thread and returns only if/when the current context is closed.
frontend
- ZMQ.Socketbackend
- ZMQ.Socketcapture
- If the capture socket is not NULL, the proxy shall send all messages, received on both
frontend and backend, to the capture socket. The capture socket should be a
ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH, or ZMQ_PAIR socket.public static boolean proxy(ZMQ.Socket frontend, ZMQ.Socket backend, ZMQ.Socket capture, ZMQ.Socket control)
public static int poll(java.nio.channels.Selector selector, ZMQ.PollItem[] items, long timeout)
public static int poll(java.nio.channels.Selector selector, ZMQ.PollItem[] items, int count, long timeout)
public static int getMajorVersion()
public static int getMinorVersion()
public static int getPatchVersion()
public static int getFullVersion()
public static int makeVersion(int major, int minor, int patch)
major
- Version major component.minor
- Version minor component.patch
- Version patch component.public static java.lang.String getVersionString()
public static void msleep(long millis)
public static void sleep(long seconds)
public static void sleep(long amount, java.util.concurrent.TimeUnit unit)