Class Context

A ØMQ context. Contexts manage the background I/O to send and receive messages of their associated sockets.

It is usually not necessary to instantiate a new context - the global context is used for new sockets by default. The global context is the only context that is shared between threads (when using worker_threads). Custom contexts can only be used in the same thread.

// Use default context (recommended).
const socket = new Dealer()
// Use custom context.
const context = new Context()
const socket = new Dealer({context})

Note: By default all contexts (including the global context) will prevent the process from terminating if there are any messages in an outgoing queue, even if the associated socket was closed. For some applications this is unnecessary or unwanted. Consider setting blocky to false or setting linger for each new socket.

Hierarchy

  • Context

Constructors

  • Creates a new ØMQ context and sets any provided context options. Sockets need to be explicitly associated with a new context during construction.

    Parameters

    • Optional options: {
          blocky?: boolean;
          ioThreads?: number;
          ipv6?: boolean;
          maxMessageSize?: number;
          maxSockets?: number;
          threadPriority?: number;
          threadSchedulingPolicy?: number;
      }

      An optional object with options that will be set on the context during creation.

      • Optional blocky?: boolean

        ZMQ_BLOCKY

        By default the context will block forever when closed at process exit. The assumption behind this behavior is that abrupt termination will cause message loss. Most real applications use some form of handshaking to ensure applications receive termination messages, and then terminate the context with linger set to zero on all sockets. This setting is an easier way to get the same result. When blocky is set to false, all new sockets are given a linger timeout of zero. You must still close all sockets before exiting.

      • Optional ioThreads?: number

        ZMQ_IO_THREADS

        Size of the ØMQ thread pool to handle I/O operations. If your application is using only the inproc transport for messaging you may set this to zero, otherwise set it to at least one (default).

      • Optional ipv6?: boolean

        ZMQ_IPV6

        Enable or disable IPv6. When IPv6 is enabled, a socket will connect to, or accept connections from, both IPv4 and IPv6 hosts.

      • Optional maxMessageSize?: number

        ZMQ_MAX_MSGSZ

        Maximum allowed size of a message sent in the context.

      • Optional maxSockets?: number

        ZMQ_MAX_SOCKETS

        Maximum number of sockets allowed on the context.

      • Optional threadPriority?: number

        ZMQ_THREAD_PRIORITY

        Scheduling priority for internal context's thread pool. This option is not available on Windows. Supported values for this option depend on chosen scheduling policy. Details can be found at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. This option only applies before creating any sockets on the context.

        Writeonly

      • Optional threadSchedulingPolicy?: number

        ZMQ_THREAD_SCHED_POLICY

        Scheduling policy for internal context's thread pool. This option is not available on Windows. Supported values for this option can be found at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. This option only applies before creating any sockets on the context.

        Writeonly

    Returns Context

Properties

blocky: boolean

ZMQ_BLOCKY

By default the context will block forever when closed at process exit. The assumption behind this behavior is that abrupt termination will cause message loss. Most real applications use some form of handshaking to ensure applications receive termination messages, and then terminate the context with linger set to zero on all sockets. This setting is an easier way to get the same result. When blocky is set to false, all new sockets are given a linger timeout of zero. You must still close all sockets before exiting.

ioThreads: number

ZMQ_IO_THREADS

Size of the ØMQ thread pool to handle I/O operations. If your application is using only the inproc transport for messaging you may set this to zero, otherwise set it to at least one (default).

ipv6: boolean

ZMQ_IPV6

Enable or disable IPv6. When IPv6 is enabled, a socket will connect to, or accept connections from, both IPv4 and IPv6 hosts.

maxMessageSize: number

ZMQ_MAX_MSGSZ

Maximum allowed size of a message sent in the context.

maxSockets: number

ZMQ_MAX_SOCKETS

Maximum number of sockets allowed on the context.

maxSocketsLimit: number

ZMQ_SOCKET_LIMIT

Largest number of sockets that can be set with maxSockets.

threadPriority: number

ZMQ_THREAD_PRIORITY

Scheduling priority for internal context's thread pool. This option is not available on Windows. Supported values for this option depend on chosen scheduling policy. Details can be found at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. This option only applies before creating any sockets on the context.

Writeonly

threadSchedulingPolicy: number

ZMQ_THREAD_SCHED_POLICY

Scheduling policy for internal context's thread pool. This option is not available on Windows. Supported values for this option can be found at http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. This option only applies before creating any sockets on the context.

Writeonly

Methods

  • Parameters

    • option: number

    Returns boolean

  • Parameters

    • option: number

    Returns number

  • Parameters

    • option: number
    • value: boolean

    Returns void

  • Parameters

    • option: number
    • value: number

    Returns void

Generated using TypeDoc