1 | /// <reference types="node" />
|
2 | /// <reference types="node" />
|
3 | export { capability, context, curveKeyPair, version, Context, Event, EventOfType, EventType, Socket, Observer, Proxy, } from "./native";
|
4 | import { Context, EventOfType, EventType, Options, Socket } from "./native";
|
5 | /**
|
6 | * A type representing the messages that are returned inside promises by
|
7 | * {@link Readable.receive}().
|
8 | */
|
9 | export type Message = Buffer;
|
10 | /**
|
11 | * Union type representing all message types that are accepted by
|
12 | * {@link Writable.send}().
|
13 | */
|
14 | export type MessageLike = ArrayBufferView | ArrayBuffer | SharedArrayBuffer | string | number | null;
|
15 | /**
|
16 | * Describes sockets that can send messages.
|
17 | *
|
18 | * @typeparam M The type of the message or message parts that can be sent.
|
19 | * @typeparam O Rest type for any options, if applicable to the socket type
|
20 | * (DRAFT only).
|
21 | */
|
22 | export interface Writable<M extends MessageLike | MessageLike[] = MessageLike | MessageLike[], O extends [...object[]] = []> {
|
23 | /**
|
24 | * ZMQ_MULTICAST_HOPS
|
25 | *
|
26 | * Sets the time-to-live field in every multicast packet sent from this
|
27 | * socket. The default is 1 which means that the multicast packets don't leave
|
28 | * the local network.
|
29 | */
|
30 | multicastHops: number;
|
31 | /**
|
32 | * ZMQ_SNDBUF
|
33 | *
|
34 | * Underlying kernel transmit buffer size in bytes. A value of -1 means leave
|
35 | * the OS default unchanged.
|
36 | */
|
37 | sendBufferSize: number;
|
38 | /**
|
39 | * ZMQ_SNDHWM
|
40 | *
|
41 | * The high water mark is a hard limit on the maximum number of outgoing
|
42 | * messages ØMQ shall queue in memory for any single peer that the specified
|
43 | * socket is communicating with. A value of zero means no limit.
|
44 | *
|
45 | * If this limit has been reached the socket shall enter an exceptional state
|
46 | * and depending on the socket type, ØMQ shall take appropriate action such as
|
47 | * blocking or dropping sent messages.
|
48 | */
|
49 | sendHighWaterMark: number;
|
50 | /**
|
51 | * ZMQ_SNDTIMEO
|
52 | *
|
53 | * Sets the timeout for sending messages on the socket. If the value is 0,
|
54 | * {@link send}() will return a rejected promise immediately if the message
|
55 | * cannot be sent. If the value is -1, it will wait asynchronously until the
|
56 | * message is sent. For all other values, it will try to send the message for
|
57 | * that amount of time before rejecting.
|
58 | */
|
59 | sendTimeout: number;
|
60 | /**
|
61 | * Sends a single message or a multipart message on the socket. Queues the
|
62 | * message immediately if possible, and returns a resolved promise. If the
|
63 | * message cannot be queued because the high water mark has been reached, it
|
64 | * will wait asynchronously. The promise will be resolved when the message was
|
65 | * queued successfully.
|
66 | *
|
67 | * ```typescript
|
68 | * await socket.send("hello world")
|
69 | * await socket.send(["hello", "world"])
|
70 | * ```
|
71 | *
|
72 | * Queueing may fail eventually if the socket has been configured with a
|
73 | * {@link sendTimeout}.
|
74 | *
|
75 | * A call to {@link send}() is guaranteed to return with a resolved promise
|
76 | * immediately if the message could be queued directly.
|
77 | *
|
78 | * Only **one** asynchronously blocking call to {@link send}() may be executed
|
79 | * simultaneously. If you call {@link send}() again on a socket that is in the
|
80 | * mute state it will return a rejected promise with an `EBUSY` error.
|
81 | *
|
82 | * The reason for disallowing multiple {@link send}() calls simultaneously is
|
83 | * that it could create an implicit queue of unsendable outgoing messages.
|
84 | * This would circumvent the socket's {@link sendHighWaterMark}. Such an
|
85 | * implementation could even exhaust all system memory and cause the Node.js
|
86 | * process to abort.
|
87 | *
|
88 | * For most application you should not notice this implementation detail. Only
|
89 | * in rare occasions will a call to {@link send}() that does not resolve
|
90 | * immediately be undesired. Here are some common scenarios:
|
91 | *
|
92 | * * If you wish to **send a message**, use `await send(...)`. ZeroMQ socket
|
93 | * types have been carefully designed to give you the correct blocking
|
94 | * behaviour on the chosen socket type in almost all cases:
|
95 | *
|
96 | * * If sending is not possible, it is often better to wait than to continue
|
97 | * as if nothing happened. For example, on a {@link Request} socket, you
|
98 | * can only receive a reply once a message has been sent; so waiting until
|
99 | * a message could be queued before continuing with the rest of the
|
100 | * program (likely to read from the socket) is required.
|
101 | *
|
102 | * * Certain socket types (such as {@link Router}) will always allow
|
103 | * queueing messages and `await send(...)` won't delay any code that comes
|
104 | * after. This makes sense for routers, since typically you don't want a
|
105 | * single send operation to stop the handling of other incoming or
|
106 | * outgoing messages.
|
107 | *
|
108 | * * If you wish to send on an occasionally **blocking** socket (for example
|
109 | * on a {@link Router} with the {@link Router.mandatory} option set, or on a
|
110 | * {@link Dealer}) and you're 100% certain that **dropping a message is
|
111 | * better than blocking**, then you can set the {@link sendTimeout} option
|
112 | * to `0` to effectively force {@link send}() to always resolve immediately.
|
113 | * Be prepared to catch exceptions if sending a message is not immediately
|
114 | * possible.
|
115 | *
|
116 | * * If you wish to send on a socket and **messages should be queued before
|
117 | * they are dropped**, you should implement a [simple
|
118 | * queue](examples/queue/queue.ts) in JavaScript. Such a queue is not
|
119 | * provided by this library because most real world applications need to
|
120 | * deal with undeliverable messages in more complex ways - for example, they
|
121 | * might need to reply with a status message; or first retry delivery a
|
122 | * certain number of times before giving up.
|
123 | *
|
124 | * @param message Single message or multipart message to queue for sending.
|
125 | * @param options Any options, if applicable to the socket type (DRAFT only).
|
126 | * @returns Resolved when the message was successfully queued.
|
127 | */
|
128 | send(message: M, ...options: O): Promise<void>;
|
129 | }
|
130 | type ReceiveType<T> = T extends {
|
131 | receive(): Promise<infer U>;
|
132 | } ? U : never;
|
133 | /**
|
134 | * Describes sockets that can receive messages.
|
135 | *
|
136 | * @typeparam M The type of the message or message parts that can be read.
|
137 | */
|
138 | export interface Readable<M extends object[] = Message[]> {
|
139 | /**
|
140 | * ZMQ_RCVBUF
|
141 | *
|
142 | * Underlying kernel receive buffer size in bytes. A value of -1 means leave
|
143 | * the OS default unchanged.
|
144 | */
|
145 | receiveBufferSize: number;
|
146 | /**
|
147 | * ZMQ_RCVHWM
|
148 | *
|
149 | * The high water mark is a hard limit on the maximum number of incoming
|
150 | * messages ØMQ shall queue in memory for any single peer that the specified
|
151 | * socket is communicating with. A value of zero means no limit.
|
152 | *
|
153 | * If this limit has been reached the socket shall enter an exceptional state
|
154 | * and depending on the socket type, ØMQ shall take appropriate action such as
|
155 | * blocking or dropping sent messages.
|
156 | */
|
157 | receiveHighWaterMark: number;
|
158 | /**
|
159 | * ZMQ_RCVTIMEO
|
160 | *
|
161 | * Sets the timeout receiving messages on the socket. If the value is 0,
|
162 | * {@link receive}() will return a rejected promise immediately if there is no
|
163 | * message to receive. If the value is -1, it will wait asynchronously until a
|
164 | * message is available. For all other values, it will wait for a message for
|
165 | * that amount of time before rejecting.
|
166 | */
|
167 | receiveTimeout: number;
|
168 | /**
|
169 | * Waits for the next single or multipart message to become availeble on the
|
170 | * socket. Reads a message immediately if possible. If no messages can be
|
171 | * read, it will wait asynchonously. The promise will be resolved with an
|
172 | * array containing the parts of the next message when available.
|
173 | *
|
174 | * ```typescript
|
175 | * const [msg] = await socket.receive()
|
176 | * const [part1, part2] = await socket.receive()
|
177 | * ```
|
178 | *
|
179 | * Reading may fail (eventually) if the socket has been configured with a
|
180 | * {@link receiveTimeout}.
|
181 | *
|
182 | * A call to {@link receive}() is guaranteed to return with a resolved promise
|
183 | * immediately if a message could be read from the socket directly.
|
184 | *
|
185 | * Only **one** asynchronously blocking call to {@link receive}() can be in
|
186 | * progress simultaneously. If you call {@link receive}() again on the same
|
187 | * socket it will return a rejected promise with an `EBUSY` error. For
|
188 | * example, if no messages can be read and no `await` is used:
|
189 | *
|
190 | * ```typescript
|
191 | * socket.receive() // -> pending promise until read is possible
|
192 | * socket.receive() // -> promise rejection with `EBUSY` error
|
193 | * ```
|
194 | *
|
195 | * **Note:** Due to the nature of Node.js and to avoid blocking the main
|
196 | * thread, this method always attempts to read messages with the
|
197 | * `ZMQ_DONTWAIT` flag. It polls asynchronously if reading is not currently
|
198 | * possible. This means that all functionality related to timeouts and
|
199 | * blocking behaviour is reimplemented in the Node.js bindings. Any
|
200 | * differences in behaviour with the native ZMQ library is considered a bug.
|
201 | *
|
202 | * @returns Resolved with message parts that were successfully read.
|
203 | */
|
204 | receive(): Promise<M>;
|
205 | /**
|
206 | * Asynchronously iterate over messages becoming available on the socket. When
|
207 | * the socket is closed with {@link Socket.close}(), the iterator will return.
|
208 | * Returning early from the iterator will **not** close the socket unless it
|
209 | * also goes out of scope.
|
210 | *
|
211 | * ```typescript
|
212 | * for await (const [msg] of socket) {
|
213 | * // handle messages
|
214 | * }
|
215 | * ```
|
216 | */
|
217 | [Symbol.asyncIterator](): AsyncIterator<ReceiveType<this>, undefined>;
|
218 | }
|
219 | /**
|
220 | * Represents the options that can be assigned in the constructor of a given
|
221 | * socket type, for example `new Dealer({...})`. Readonly options
|
222 | * for the particular socket will be omitted.
|
223 | *
|
224 | * @typeparam S The socket type to which the options should be applied.
|
225 | */
|
226 | export type SocketOptions<S extends Socket> = Options<S, {
|
227 | context: Context;
|
228 | }>;
|
229 | export interface EventSubscriber {
|
230 | /**
|
231 | * Adds a listener function which will be invoked when the given event type is
|
232 | * observed. Calling this method will convert the {@link Observer} to **event
|
233 | * emitter mode**, which will make it impossible to call
|
234 | * {@link Observer.receive}() at the same time.
|
235 | *
|
236 | * ```typescript
|
237 | * socket.events.on("bind", event => {
|
238 | * console.log(`Socket bound to ${event.address}`)
|
239 | * // ...
|
240 | * })
|
241 | * ```
|
242 | *
|
243 | * @param type The type of event to listen for.
|
244 | * @param listener The listener function that will be called with all event
|
245 | * data when the event is observed.
|
246 | */
|
247 | on<E extends EventType>(type: E, listener: (data: EventOfType<E>) => void): EventSubscriber;
|
248 | /**
|
249 | * Removes the specified listener function from the list of functions to call
|
250 | * when the given event is observed.
|
251 | *
|
252 | * @param type The type of event that the listener was listening for.
|
253 | * @param listener The previously registered listener function.
|
254 | */
|
255 | off<E extends EventType>(type: E, listener: (data: EventOfType<E>) => void): EventSubscriber;
|
256 | }
|
257 | declare module "./native" {
|
258 | interface Context {
|
259 | /**
|
260 | * ZMQ_BLOCKY
|
261 | *
|
262 | * By default the context will block forever when closed at process exit.
|
263 | * The assumption behind this behavior is that abrupt termination will cause
|
264 | * message loss. Most real applications use some form of handshaking to
|
265 | * ensure applications receive termination messages, and then terminate the
|
266 | * context with {@link Socket.linger} set to zero on all sockets. This
|
267 | * setting is an easier way to get the same result. When {@link blocky} is
|
268 | * set to `false`, all new sockets are given a linger timeout of zero. You
|
269 | * must still close all sockets before exiting.
|
270 | */
|
271 | blocky: boolean;
|
272 | /**
|
273 | * ZMQ_IO_THREADS
|
274 | *
|
275 | * Size of the ØMQ thread pool to handle I/O operations. If your application
|
276 | * is using only the `inproc` transport for messaging you may set this to
|
277 | * zero, otherwise set it to at least one (default).
|
278 | */
|
279 | ioThreads: number;
|
280 | /**
|
281 | * ZMQ_MAX_MSGSZ
|
282 | *
|
283 | * Maximum allowed size of a message sent in the context.
|
284 | */
|
285 | maxMessageSize: number;
|
286 | /**
|
287 | * ZMQ_MAX_SOCKETS
|
288 | *
|
289 | * Maximum number of sockets allowed on the context.
|
290 | */
|
291 | maxSockets: number;
|
292 | /**
|
293 | * ZMQ_IPV6
|
294 | *
|
295 | * Enable or disable IPv6. When IPv6 is enabled, a socket will connect to,
|
296 | * or accept connections from, both IPv4 and IPv6 hosts.
|
297 | */
|
298 | ipv6: boolean;
|
299 | /**
|
300 | * ZMQ_THREAD_PRIORITY
|
301 | *
|
302 | * Scheduling priority for internal context's thread pool. This option is
|
303 | * not available on Windows. Supported values for this option depend on
|
304 | * chosen scheduling policy. Details can be found at
|
305 | * http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. This
|
306 | * option only applies before creating any sockets on the context.
|
307 | *
|
308 | * @writeonly
|
309 | */
|
310 | threadPriority: number;
|
311 | /**
|
312 | * ZMQ_THREAD_SCHED_POLICY
|
313 | *
|
314 | * Scheduling policy for internal context's thread pool. This option is not
|
315 | * available on Windows. Supported values for this option can be found at
|
316 | * http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. This
|
317 | * option only applies before creating any sockets on the context.
|
318 | *
|
319 | * @writeonly
|
320 | */
|
321 | threadSchedulingPolicy: number;
|
322 | /**
|
323 | * ZMQ_SOCKET_LIMIT
|
324 | *
|
325 | * Largest number of sockets that can be set with {@link maxSockets}.
|
326 | *
|
327 | * @readonly
|
328 | */
|
329 | readonly maxSocketsLimit: number;
|
330 | }
|
331 | /**
|
332 | * Socket option names differ somewhat from the native libzmq option names.
|
333 | * This is intentional to improve readability and be more idiomatic for
|
334 | * JavaScript/TypeScript.
|
335 | */
|
336 | interface Socket {
|
337 | /**
|
338 | * ZMQ_AFFINITY
|
339 | *
|
340 | * I/O thread affinity, which determines which threads from the ØMQ I/O
|
341 | * thread pool associated with the socket's context shall handle newly
|
342 | * created connections.
|
343 | *
|
344 | * **Note:** This value is a bit mask, but values higher than
|
345 | * `Number.MAX_SAFE_INTEGER` may not be represented accurately! This
|
346 | * currently means that configurations beyond 52 threads are unreliable.
|
347 | */
|
348 | affinity: number;
|
349 | /**
|
350 | * ZMQ_RATE
|
351 | *
|
352 | * Maximum send or receive data rate for multicast transports such as `pgm`.
|
353 | */
|
354 | rate: number;
|
355 | /**
|
356 | * ZMQ_RECOVERY_IVL
|
357 | *
|
358 | * Maximum time in milliseconds that a receiver can be absent from a
|
359 | * multicast group before unrecoverable data loss will occur.
|
360 | */
|
361 | recoveryInterval: number;
|
362 | /**
|
363 | * ZMQ_LINGER
|
364 | *
|
365 | * Determines how long pending messages which have yet to be sent to a peer
|
366 | * shall linger in memory after a socket is closed with {@link close}().
|
367 | */
|
368 | linger: number;
|
369 | /**
|
370 | * ZMQ_RECONNECT_IVL
|
371 | *
|
372 | * Period ØMQ shall wait between attempts to reconnect disconnected peers
|
373 | * when using connection-oriented transports. The value -1 means no
|
374 | * reconnection.
|
375 | */
|
376 | reconnectInterval: number;
|
377 | /**
|
378 | * ZMQ_BACKLOG
|
379 | *
|
380 | * Maximum length of the queue of outstanding peer connections for the
|
381 | * specified socket. This only applies to connection-oriented transports.
|
382 | */
|
383 | backlog: number;
|
384 | /**
|
385 | * ZMQ_RECONNECT_IVL_MAX
|
386 | *
|
387 | * Maximum period ØMQ shall wait between attempts to reconnect. On each
|
388 | * reconnect attempt, the previous interval shall be doubled until
|
389 | * {@link reconnectMaxInterval} is reached. This allows for exponential
|
390 | * backoff strategy. Zero (the default) means no exponential backoff is
|
391 | * performed and reconnect interval calculations are only based on
|
392 | * {@link reconnectInterval}.
|
393 | */
|
394 | reconnectMaxInterval: number;
|
395 | /**
|
396 | * ZMQ_MAXMSGSIZE
|
397 | *
|
398 | * Limits the size of the inbound message. If a peer sends a message larger
|
399 | * than the limit it is disconnected. Value of -1 means no limit.
|
400 | */
|
401 | maxMessageSize: number;
|
402 | /**
|
403 | * ZMQ_TCP_KEEPALIVE
|
404 | *
|
405 | * Override SO_KEEPALIVE socket option (if supported by OS). The default
|
406 | * value of -1 leaves it to the OS default.
|
407 | */
|
408 | tcpKeepalive: number;
|
409 | /**
|
410 | * ZMQ_TCP_KEEPALIVE_CNT
|
411 | *
|
412 | * Overrides TCP_KEEPCNT socket option (if supported by OS). The default
|
413 | * value of -1 leaves it to the OS default.
|
414 | */
|
415 | tcpKeepaliveCount: number;
|
416 | /**
|
417 | * ZMQ_TCP_KEEPALIVE_IDLE
|
418 | *
|
419 | * Overrides TCP_KEEPIDLE / TCP_KEEPALIVE socket option (if supported by
|
420 | * OS). The default value of -1 leaves it to the OS default.
|
421 | */
|
422 | tcpKeepaliveIdle: number;
|
423 | /**
|
424 | * ZMQ_TCP_KEEPALIVE_INTVL
|
425 | *
|
426 | * Overrides TCP_KEEPINTVL socket option (if supported by the OS). The
|
427 | * default value of -1 leaves it to the OS default.
|
428 | */
|
429 | tcpKeepaliveInterval: number;
|
430 | /**
|
431 | * ZMQ_TCP_ACCEPT_FILTER
|
432 | *
|
433 | * Assign a filter that will be applied for each new TCP transport
|
434 | * connection on a listening socket. If no filters are applied, then the TCP
|
435 | * transport allows connections from any IP address. If at least one filter
|
436 | * is applied then new connection source IP should be matched. To clear all
|
437 | * filters set to `null`. Filter is a string with IPv6 or IPv4 CIDR.
|
438 | */
|
439 | tcpAcceptFilter: string | null;
|
440 | /**
|
441 | * ZMQ_IMMEDIATE
|
442 | *
|
443 | * By default queues will fill on outgoing connections even if the
|
444 | * connection has not completed. This can lead to "lost" messages on sockets
|
445 | * with round-robin routing ({@link Request}, {@link Push}, {@link Dealer}).
|
446 | * If this option is set to `true`, messages shall be queued only to
|
447 | * completed connections. This will cause the socket to block if there are
|
448 | * no other connections, but will prevent queues from filling on pipes
|
449 | * awaiting connection.
|
450 | */
|
451 | immediate: boolean;
|
452 | /**
|
453 | * ZMQ_IPV6
|
454 | *
|
455 | * Enable or disable IPv6. When IPv6 is enabled, the socket will connect to,
|
456 | * or accept connections from, both IPv4 and IPv6 hosts.
|
457 | */
|
458 | ipv6: boolean;
|
459 | /**
|
460 | * ZMQ_PLAIN_SERVER
|
461 | *
|
462 | * Defines whether the socket will act as server for PLAIN security. A value
|
463 | * of `true` means the socket will act as PLAIN server. A value of `false`
|
464 | * means the socket will not act as PLAIN server, and its security role then
|
465 | * depends on other option settings.
|
466 | */
|
467 | plainServer: boolean;
|
468 | /**
|
469 | * ZMQ_PLAIN_USERNAME
|
470 | *
|
471 | * Sets the username for outgoing connections over TCP or IPC. If you set
|
472 | * this to a non-null value, the security mechanism used for connections
|
473 | * shall be PLAIN.
|
474 | */
|
475 | plainUsername: string | null;
|
476 | /**
|
477 | * ZMQ_PLAIN_PASSWORD
|
478 | *
|
479 | * Sets the password for outgoing connections over TCP or IPC. If you set
|
480 | * this to a non-null value, the security mechanism used for connections
|
481 | * shall be PLAIN.
|
482 | */
|
483 | plainPassword: string | null;
|
484 | /**
|
485 | * ZMQ_CURVE_SERVER
|
486 | *
|
487 | * Defines whether the socket will act as server for CURVE security. A value
|
488 | * of `true` means the socket will act as CURVE server. A value of `false`
|
489 | * means the socket will not act as CURVE server, and its security role then
|
490 | * depends on other option settings.
|
491 | */
|
492 | curveServer: boolean;
|
493 | /**
|
494 | * ZMQ_CURVE_PUBLICKEY
|
495 | *
|
496 | * Sets the socket's long term public key. You must set this on CURVE client
|
497 | * sockets. A server socket does not need to know its own public key. You
|
498 | * can create a new keypair with {@link curveKeyPair}().
|
499 | */
|
500 | curvePublicKey: string | null;
|
501 | /**
|
502 | * ZMQ_CURVE_SECRETKEY
|
503 | *
|
504 | * Sets the socket's long term secret key. You must set this on both CURVE
|
505 | * client and server sockets. You can create a new keypair with
|
506 | * {@link curveKeyPair}().
|
507 | */
|
508 | curveSecretKey: string | null;
|
509 | /**
|
510 | * ZMQ_CURVE_SERVERKEY
|
511 | *
|
512 | * Sets the socket's long term server key. This is the public key of the
|
513 | * CURVE *server* socket. You must set this on CURVE *client* sockets. This
|
514 | * key must have been generated together with the server's secret key. You
|
515 | * can create a new keypair with {@link curveKeyPair}().
|
516 | */
|
517 | curveServerKey: string | null;
|
518 | /** */
|
519 | gssapiServer: boolean;
|
520 | /** */
|
521 | gssapiPrincipal: string | null;
|
522 | /** */
|
523 | gssapiServicePrincipal: string | null;
|
524 | /** */
|
525 | gssapiPlainText: boolean;
|
526 | /** */
|
527 | gssapiPrincipalNameType: "hostBased" | "userName" | "krb5Principal";
|
528 | /** */
|
529 | gssapiServicePrincipalNameType: "hostBased" | "userName" | "krb5Principal";
|
530 | /**
|
531 | * ZMQ_ZAP_DOMAIN
|
532 | *
|
533 | * Sets the domain for ZAP (ZMQ RFC 27) authentication. For NULL security
|
534 | * (the default on all `tcp://` connections), ZAP authentication only
|
535 | * happens if you set a non-empty domain. For PLAIN and CURVE security, ZAP
|
536 | * requests are always made, if there is a ZAP handler present. See
|
537 | * http://rfc.zeromq.org/spec:27 for more details.
|
538 | */
|
539 | zapDomain: string | null;
|
540 | /**
|
541 | * ZMQ_TOS
|
542 | *
|
543 | * Sets the ToS fields (the *Differentiated Services* (DS) and *Explicit
|
544 | * Congestion Notification* (ECN) field) of the IP header. The ToS field is
|
545 | * typically used to specify a packet's priority. The availability of this
|
546 | * option is dependent on intermediate network equipment that inspect the
|
547 | * ToS field and provide a path for low-delay, high-throughput,
|
548 | * highly-reliable service, etc.
|
549 | */
|
550 | typeOfService: number;
|
551 | /**
|
552 | * ZMQ_HANDSHAKE_IVL
|
553 | *
|
554 | * Handshaking is the exchange of socket configuration information (socket
|
555 | * type, identity, security) that occurs when a connection is first opened
|
556 | * (only for connection-oriented transports). If handshaking does not
|
557 | * complete within the configured time, the connection shall be closed. The
|
558 | * value 0 means no handshake time limit.
|
559 | */
|
560 | handshakeInterval: number;
|
561 | /**
|
562 | * ZMQ_SOCKS_PROXY
|
563 | *
|
564 | * The SOCKS5 proxy address that shall be used by the socket for the TCP
|
565 | * connection(s). Does not support SOCKS5 authentication. If the endpoints
|
566 | * are domain names instead of addresses they shall not be resolved and they
|
567 | * shall be forwarded unchanged to the SOCKS proxy service in the client
|
568 | * connection request message (address type 0x03 domain name).
|
569 | */
|
570 | socksProxy: string | null;
|
571 | /**
|
572 | * ZMQ_HEARTBEAT_IVL
|
573 | *
|
574 | * Interval in milliseconds between sending ZMTP heartbeats for the
|
575 | * specified socket. If this option is greater than 0, then a PING ZMTP
|
576 | * command will be sent after every interval.
|
577 | */
|
578 | heartbeatInterval: number;
|
579 | /**
|
580 | * ZMQ_HEARTBEAT_TTL
|
581 | *
|
582 | * The timeout in milliseconds on the remote peer for ZMTP heartbeats. If
|
583 | * this option is greater than 0, the remote side shall time out the
|
584 | * connection if it does not receive any more traffic within the TTL period.
|
585 | * This option does not have any effect if {@link heartbeatInterval} is 0.
|
586 | * Internally, this value is rounded down to the nearest decisecond, any
|
587 | * value less than 100 will have no effect.
|
588 | */
|
589 | heartbeatTimeToLive: number;
|
590 | /**
|
591 | * ZMQ_HEARTBEAT_TIMEOUT
|
592 | *
|
593 | * How long (in milliseconds) to wait before timing-out a connection after
|
594 | * sending a PING ZMTP command and not receiving any traffic. This option is
|
595 | * only valid if {@link heartbeatInterval} is greater than 0. The connection
|
596 | * will time out if there is no traffic received after sending the PING
|
597 | * command. The received traffic does not have to be a PONG command - any
|
598 | * received traffic will cancel the timeout.
|
599 | */
|
600 | heartbeatTimeout: number;
|
601 | /**
|
602 | * ZMQ_CONNECT_TIMEOUT
|
603 | *
|
604 | * Sets how long to wait before timing-out a connect() system call. The
|
605 | * connect() system call normally takes a long time before it returns a time
|
606 | * out error. Setting this option allows the library to time out the call at
|
607 | * an earlier interval.
|
608 | */
|
609 | connectTimeout: number;
|
610 | /**
|
611 | * ZMQ_TCP_MAXRT
|
612 | *
|
613 | * Sets how long before an unacknowledged TCP retransmit times out (if
|
614 | * supported by the OS). The system normally attempts many TCP retransmits
|
615 | * following an exponential backoff strategy. This means that after a
|
616 | * network outage, it may take a long time before the session can be
|
617 | * re-established. Setting this option allows the timeout to happen at a
|
618 | * shorter interval.
|
619 | */
|
620 | tcpMaxRetransmitTimeout: number;
|
621 | /**
|
622 | * ZMQ_MULTICAST_MAXTPDU
|
623 | *
|
624 | * Sets the maximum transport data unit size used for outbound multicast
|
625 | * packets. This must be set at or below the minimum Maximum Transmission
|
626 | * Unit (MTU) for all network paths over which multicast reception is
|
627 | * required.
|
628 | */
|
629 | multicastMaxTransportDataUnit: number;
|
630 | /**
|
631 | * ZMQ_VMCI_BUFFER_SIZE
|
632 | *
|
633 | * The size of the underlying buffer for the socket. Used during negotiation
|
634 | * before the connection is established.
|
635 | * For `vmci://` transports only.
|
636 | */
|
637 | vmciBufferSize: number;
|
638 | /**
|
639 | * ZMQ_VMCI_BUFFER_MIN_SIZE
|
640 | *
|
641 | * Minimum size of the underlying buffer for the socket. Used during
|
642 | * negotiation before the connection is established.
|
643 | * For `vmci://` transports only.
|
644 | */
|
645 | vmciBufferMinSize: number;
|
646 | /**
|
647 | * ZMQ_VMCI_BUFFER_MAX_SIZE
|
648 | *
|
649 | * Maximum size of the underlying buffer for the socket. Used during
|
650 | * negotiation before the connection is established.
|
651 | * For `vmci://` transports only.
|
652 | */
|
653 | vmciBufferMaxSize: number;
|
654 | /**
|
655 | * ZMQ_VMCI_CONNECT_TIMEOUT
|
656 | *
|
657 | * Connection timeout for the socket.
|
658 | * For `vmci://` transports only.
|
659 | */
|
660 | vmciConnectTimeout: number;
|
661 | /**
|
662 | * ZMQ_BINDTODEVICE
|
663 | *
|
664 | * Binds the socket to the given network interface (Linux only). Allows to
|
665 | * use Linux VRF, see:
|
666 | * https://www.kernel.org/doc/Documentation/networking/vrf.txt. Requires the
|
667 | * program to be ran as root **or** with `CAP_NET_RAW`.
|
668 | */
|
669 | interface: string | null;
|
670 | /**
|
671 | * ZMQ_ZAP_ENFORCE_DOMAIN
|
672 | *
|
673 | * The ZAP (ZMQ RFC 27) authentication protocol specifies that a domain must
|
674 | * always be set. Older versions of libzmq did not follow the spec and
|
675 | * allowed an empty domain to be set. This option can be used to enabled or
|
676 | * disable the stricter, backward incompatible behaviour. For now it is
|
677 | * disabled by default, but in a future version it will be enabled by
|
678 | * default.
|
679 | */
|
680 | zapEnforceDomain: boolean;
|
681 | /**
|
682 | * ZMQ_LOOPBACK_FASTPATH
|
683 | *
|
684 | * Enable faster TCP connections on loopback devices. An application can
|
685 | * enable this option to reduce the latency and improve the performance of
|
686 | * loopback operations on a TCP socket on Windows.
|
687 | *
|
688 | * @windows
|
689 | */
|
690 | loopbackFastPath: boolean;
|
691 | /**
|
692 | * ZMQ_TYPE
|
693 | *
|
694 | * Retrieve the socket type. This is fairly useless because you can test the
|
695 | * socket class with e.g. `socket instanceof Dealer`.
|
696 | *
|
697 | * @readonly
|
698 | */
|
699 | readonly type: SocketType;
|
700 | /**
|
701 | * ZMQ_LAST_ENDPOINT
|
702 | *
|
703 | * The last endpoint bound for TCP and IPC transports.
|
704 | *
|
705 | * @readonly
|
706 | */
|
707 | readonly lastEndpoint: string | null;
|
708 | /**
|
709 | * ZMQ_MECHANISM
|
710 | *
|
711 | * Returns the current security mechanism for the socket, if any. The
|
712 | * security mechanism is set implictly by using any of the relevant security
|
713 | * options. The returned value is one of:
|
714 | * * `null` - No security mechanism is used.
|
715 | * * `"plain"` - The PLAIN mechanism defines a simple username/password
|
716 | * mechanism that lets a server authenticate a client. PLAIN makes no
|
717 | * attempt at security or confidentiality.
|
718 | * * `"curve"` - The CURVE mechanism defines a mechanism for secure
|
719 | * authentication and confidentiality for communications between a client
|
720 | * and a server. CURVE is intended for use on public networks.
|
721 | * * `"gssapi"` - The GSSAPI mechanism defines a mechanism for secure
|
722 | * authentication and confidentiality for communications between a client
|
723 | * and a server using the Generic Security Service Application Program
|
724 | * Interface (GSSAPI). The GSSAPI mechanism can be used on both public and
|
725 | * private networks.
|
726 | *
|
727 | * @readonly
|
728 | */
|
729 | readonly securityMechanism: null | "plain" | "curve" | "gssapi";
|
730 | /**
|
731 | * ZMQ_THREAD_SAFE
|
732 | *
|
733 | * Whether or not the socket is threadsafe. Currently only DRAFT sockets is
|
734 | * thread-safe.
|
735 | *
|
736 | * @readonly
|
737 | */
|
738 | readonly threadSafe: boolean;
|
739 | }
|
740 | interface Observer extends EventSubscriber {
|
741 | /**
|
742 | * Asynchronously iterate over socket events. When the socket is closed or
|
743 | * when the observer is closed manually with {@link Observer.close}(), the
|
744 | * iterator will return.
|
745 | *
|
746 | * ```typescript
|
747 | * for await (event of socket.events) {
|
748 | * switch (event.type) {
|
749 | * case "bind":
|
750 | * console.log(`Socket bound to ${event.address}`)
|
751 | * break
|
752 | * // ...
|
753 | * }
|
754 | * }
|
755 | * ```
|
756 | */
|
757 | [Symbol.asyncIterator](): AsyncIterator<ReceiveType<this>, undefined>;
|
758 | }
|
759 | }
|
760 | /**
|
761 | * A {@link Pair} socket can only be connected to one other {@link Pair} at any
|
762 | * one time. No message routing or filtering is performed on any messages.
|
763 | *
|
764 | * When a {@link Pair} socket enters the mute state due to having reached the
|
765 | * high water mark for the connected peer, or if no peer is connected, then any
|
766 | * {@link Writable.send}() operations on the socket shall block until the peer
|
767 | * becomes available for sending; messages are not discarded.
|
768 | *
|
769 | * While {@link Pair} sockets can be used over transports other than
|
770 | * `inproc://`, their inability to auto-reconnect coupled with the fact new
|
771 | * incoming connections will be terminated while any previous connections
|
772 | * (including ones in a closing state) exist makes them unsuitable for `tcp://`
|
773 | * in most cases.
|
774 | */
|
775 | export declare class Pair extends Socket {
|
776 | constructor(options?: SocketOptions<Pair>);
|
777 | }
|
778 | export interface Pair extends Writable, Readable {
|
779 | }
|
780 | /**
|
781 | * A {@link Publisher} socket is used to distribute data to {@link Subscriber}s.
|
782 | * Messages sent are distributed in a fan out fashion to all connected peers.
|
783 | * This socket cannot receive messages.
|
784 | *
|
785 | * When a {@link Publisher} enters the mute state due to having reached the high
|
786 | * water mark for a connected {@link Subscriber}, then any messages that would
|
787 | * be sent to the subscriber in question shall instead be dropped until the mute
|
788 | * state ends. The {@link Writable.send}() method will never block.
|
789 | */
|
790 | export declare class Publisher extends Socket {
|
791 | /**
|
792 | * ZMQ_XPUB_NODROP
|
793 | *
|
794 | * Sets the socket behaviour to return an error if the high water mark is
|
795 | * reached and the message could not be send. The default is to drop the
|
796 | * message silently when the peer high water mark is reached.
|
797 | */
|
798 | noDrop: boolean;
|
799 | /**
|
800 | * ZMQ_CONFLATE
|
801 | *
|
802 | * If set to `true`, a socket shall keep only one message in its
|
803 | * inbound/outbound queue: the last message to be received/sent. Ignores any
|
804 | * high water mark options. Does not support multi-part messages - in
|
805 | * particular, only one part of it is kept in the socket internal queue.
|
806 | */
|
807 | conflate: boolean;
|
808 | /**
|
809 | * ZMQ_INVERT_MATCHING
|
810 | *
|
811 | * Causes messages to be sent to all connected sockets except those subscribed
|
812 | * to a prefix that matches the message.
|
813 | *
|
814 | * All {@link Subscriber} sockets connecting to the {@link Publisher} must
|
815 | * also have the option set to `true`. Failure to do so will have the
|
816 | * {@link Subscriber} sockets reject everything the {@link Publisher} socket
|
817 | * sends them.
|
818 | */
|
819 | invertMatching: boolean;
|
820 | constructor(options?: SocketOptions<Publisher>);
|
821 | }
|
822 | export interface Publisher extends Writable {
|
823 | }
|
824 | /**
|
825 | * A {@link Subscriber} socket is used to subscribe to data distributed by a
|
826 | * {@link Publisher}. Initially a {@link Subscriber} is not subscribed to any
|
827 | * messages. Use {@link Subscriber.subscribe}() to specify which messages to
|
828 | * subscribe to. This socket cannot send messages.
|
829 | */
|
830 | export declare class Subscriber extends Socket {
|
831 | /**
|
832 | * ZMQ_CONFLATE
|
833 | *
|
834 | * If set to `true`, a socket shall keep only one message in its
|
835 | * inbound/outbound queue: the last message to be received/sent. Ignores any
|
836 | * high water mark options. Does not support multi-part messages - in
|
837 | * particular, only one part of it is kept in the socket internal queue.
|
838 | */
|
839 | conflate: boolean;
|
840 | /**
|
841 | * ZMQ_INVERT_MATCHING
|
842 | *
|
843 | * Causes incoming messages that do not match any of the socket's
|
844 | * subscriptions to be received by the user.
|
845 | *
|
846 | * All {@link Subscriber} sockets connecting to a {@link Publisher} must also
|
847 | * have the option set to `true`. Failure to do so will have the
|
848 | * {@link Subscriber} sockets reject everything the {@link Publisher} socket
|
849 | * sends them.
|
850 | */
|
851 | invertMatching: boolean;
|
852 | constructor(options?: SocketOptions<Subscriber>);
|
853 | /**
|
854 | * Establish a new message filter. Newly created {@link Subsriber} sockets
|
855 | * will filtered out all incoming messages. Call this method to subscribe to
|
856 | * messages beginning with the given prefix.
|
857 | *
|
858 | * Multiple filters may be attached to a single socket, in which case a
|
859 | * message shall be accepted if it matches at least one filter. Subscribing
|
860 | * without any filters shall subscribe to **all** incoming messages.
|
861 | *
|
862 | * ```typescript
|
863 | * const sub = new Subscriber()
|
864 | *
|
865 | * // Listen to all messages beginning with 'foo'.
|
866 | * sub.subscribe("foo")
|
867 | *
|
868 | * // Listen to all incoming messages.
|
869 | * sub.subscribe()
|
870 | * ```
|
871 | *
|
872 | * @param prefixes The prefixes of messages to subscribe to.
|
873 | */
|
874 | subscribe(...prefixes: Array<Buffer | string>): void;
|
875 | /**
|
876 | * Remove an existing message filter which was previously established with
|
877 | * {@link subscribe}(). Stops receiving messages with the given prefix.
|
878 | *
|
879 | * Unsubscribing without any filters shall unsubscribe from the "subscribe
|
880 | * all" filter that is added by calling {@link subscribe}() without arguments.
|
881 | *
|
882 | * ```typescript
|
883 | * const sub = new Subscriber()
|
884 | *
|
885 | * // Listen to all messages beginning with 'foo'.
|
886 | * sub.subscribe("foo")
|
887 | * // ...
|
888 | *
|
889 | * // Stop listening to messages beginning with 'foo'.
|
890 | * sub.unsubscribe("foo")
|
891 | * ```
|
892 | *
|
893 | * @param prefixes The prefixes of messages to subscribe to.
|
894 | */
|
895 | unsubscribe(...prefixes: Array<Buffer | string>): void;
|
896 | }
|
897 | export interface Subscriber extends Readable {
|
898 | }
|
899 | /**
|
900 | * A {@link Request} socket acts as a client to send requests to and receive
|
901 | * replies from a {@link Reply} socket. This socket allows only an alternating
|
902 | * sequence of {@link Writable.send}() and subsequent {@link Readable.receive}()
|
903 | * calls. Each request sent is round-robined among all services, and each reply
|
904 | * received is matched with the last issued request.
|
905 | *
|
906 | * If no services are available, then any send operation on the socket shall
|
907 | * block until at least one service becomes available. The REQ socket shall not
|
908 | * discard messages.
|
909 | */
|
910 | export declare class Request extends Socket {
|
911 | /**
|
912 | * ZMQ_ROUTING_ID
|
913 | *
|
914 | * The identity of the specified socket when connecting to a `Router` socket.
|
915 | */
|
916 | routingId: string | null;
|
917 | /**
|
918 | * ZMQ_PROBE_ROUTER
|
919 | *
|
920 | * When set to `true`, the socket will automatically send an empty message
|
921 | * when a new connection is made or accepted. You may set this on sockets
|
922 | * connected to a {@link Router} socket. The application must filter such
|
923 | * empty messages. This option provides the {@link Router} with an event
|
924 | * signaling the arrival of a new peer.
|
925 | *
|
926 | * *Warning:** Do not set this option on a socket that talks to any other
|
927 | * socket type except {@link Router}: the results are undefined.
|
928 | *
|
929 | * @writeonly
|
930 | */
|
931 | probeRouter: boolean;
|
932 | /**
|
933 | * ZMQ_REQ_CORRELATE
|
934 | *
|
935 | * The default behaviour of {@link Request} sockets is to rely on the ordering
|
936 | * of messages to match requests and responses and that is usually sufficient.
|
937 | * When this option is set to `true` the socket will prefix outgoing messages
|
938 | * with an extra frame containing a request id. That means the full message is
|
939 | * `[<request id>, `null`, user frames…]`. The {@link Request} socket will
|
940 | * discard all incoming messages that don't begin with these two frames.
|
941 | */
|
942 | correlate: boolean;
|
943 | /**
|
944 | * ZMQ_REQ_RELAXED
|
945 | *
|
946 | * By default, a {@link Request} socket does not allow initiating a new
|
947 | * request until the reply to the previous one has been received. When set to
|
948 | * `true`, sending another message is allowed and previous replies will be
|
949 | * discarded. The request-reply state machine is reset and a new request is
|
950 | * sent to the next available peer.
|
951 | *
|
952 | * **Note:** If set to `true`, also enable {@link correlate} to ensure correct
|
953 | * matching of requests and replies. Otherwise a late reply to an aborted
|
954 | * request can be reported as the reply to the superseding request.
|
955 | */
|
956 | relaxed: boolean;
|
957 | constructor(options?: SocketOptions<Request>);
|
958 | }
|
959 | export interface Request extends Readable, Writable {
|
960 | }
|
961 | /**
|
962 | * A {@link Reply} socket can act as a server which receives requests from and
|
963 | * sends replies to a {@link Request} socket. This socket type allows only an
|
964 | * alternating sequence of {@link Readable.receive}() and subsequent
|
965 | * {@link Writable.send}() calls. Each request received is fair-queued from
|
966 | * among all clients, and each reply sent is routed to the client that issued
|
967 | * the last request. If the original requester does not exist any more the reply
|
968 | * is silently discarded.
|
969 | */
|
970 | export declare class Reply extends Socket {
|
971 | /**
|
972 | * ZMQ_ROUTING_ID
|
973 | *
|
974 | * The identity of the specified socket when connecting to a `Router` socket.
|
975 | */
|
976 | routingId: string | null;
|
977 | constructor(options?: SocketOptions<Reply>);
|
978 | }
|
979 | export interface Reply extends Readable, Writable {
|
980 | }
|
981 | /**
|
982 | * A {@link Dealer} socket can be used to extend request/reply sockets. Each
|
983 | * message sent is round-robined among all connected peers, and each message
|
984 | * received is fair-queued from all connected peers.
|
985 | *
|
986 | * When a {@link Dealer} socket enters the mute state due to having reached the
|
987 | * high water mark for all peers, or if there are no peers at all, then any
|
988 | * {@link Writable.send}() operations on the socket shall block until the mute
|
989 | * state ends or at least one peer becomes available for sending; messages are
|
990 | * not discarded.
|
991 | *
|
992 | * When a {@link Dealer} is connected to a {@link Reply} socket, each message
|
993 | * sent must consist of an empty message part, the delimiter, followed by one or
|
994 | * more body parts.
|
995 | */
|
996 | export declare class Dealer extends Socket {
|
997 | /**
|
998 | * ZMQ_ROUTING_ID
|
999 | *
|
1000 | * The identity of the specified socket when connecting to a `Router` socket.
|
1001 | */
|
1002 | routingId: string | null;
|
1003 | /**
|
1004 | * ZMQ_PROBE_ROUTER
|
1005 | *
|
1006 | * When set to `true`, the socket will automatically send an empty message
|
1007 | * when a new connection is made or accepted. You may set this on sockets
|
1008 | * connected to a {@link Router} socket. The application must filter such
|
1009 | * empty messages. This option provides the {@link Router} with an event
|
1010 | * signaling the arrival of a new peer.
|
1011 | *
|
1012 | * *Warning:** Do not set this option on a socket that talks to any other
|
1013 | * socket type except {@link Router}: the results are undefined.
|
1014 | *
|
1015 | * @writeonly
|
1016 | */
|
1017 | probeRouter: boolean;
|
1018 | /**
|
1019 | * ZMQ_CONFLATE
|
1020 | *
|
1021 | * If set to `true`, a socket shall keep only one message in its
|
1022 | * inbound/outbound queue: the last message to be received/sent. Ignores any
|
1023 | * high water mark options. Does not support multi-part messages - in
|
1024 | * particular, only one part of it is kept in the socket internal queue.
|
1025 | */
|
1026 | conflate: boolean;
|
1027 | constructor(options?: SocketOptions<Dealer>);
|
1028 | }
|
1029 | export interface Dealer extends Readable, Writable {
|
1030 | }
|
1031 | /**
|
1032 | * A {@link Router} can be used to extend request/reply sockets. When receiving
|
1033 | * messages a {@link Router} shall prepend a message part containing the routing
|
1034 | * id of the originating peer to the message. Messages received are fair-queued
|
1035 | * from among all connected peers. When sending messages, the first part of the
|
1036 | * message is removed and used to determine the routing id of the peer the
|
1037 | * message should be routed to.
|
1038 | *
|
1039 | * If the peer does not exist anymore, or has never existed, the message shall
|
1040 | * be silently discarded. However, if {@link Router.mandatory} is set to `true`,
|
1041 | * the socket shall fail with a `EHOSTUNREACH` error in both cases.
|
1042 | *
|
1043 | * When a {@link Router} enters the mute state due to having reached the high
|
1044 | * water mark for all peers, then any messages sent to the socket shall be
|
1045 | * dropped until the mute state ends. Likewise, any messages routed to a peer
|
1046 | * for which the individual high water mark has been reached shall also be
|
1047 | * dropped. If {@link Router.mandatory} is set to `true` the socket shall block
|
1048 | * or return an `EAGAIN` error in both cases.
|
1049 | *
|
1050 | * When a {@link Request} socket is connected to a {@link Router}, in addition
|
1051 | * to the routing id of the originating peer each message received shall contain
|
1052 | * an empty delimiter message part. Hence, the entire structure of each received
|
1053 | * message as seen by the application becomes: one or more routing id parts,
|
1054 | * delimiter part, one or more body parts. When sending replies to a
|
1055 | * {@link Request} the delimiter part must be included.
|
1056 | */
|
1057 | export declare class Router extends Socket {
|
1058 | /**
|
1059 | * ZMQ_ROUTING_ID
|
1060 | *
|
1061 | * The identity of the specified socket when connecting to a `Router` socket.
|
1062 | */
|
1063 | routingId: string | null;
|
1064 | /**
|
1065 | * ZMQ_ROUTER_MANDATORY
|
1066 | *
|
1067 | * A value of `false` is the default and discards the message silently when it
|
1068 | * cannot be routed or the peer's high water mark is reached. A value of
|
1069 | * `true` causes {@link send}() to fail if it cannot be routed, or wait
|
1070 | * asynchronously if the high water mark is reached.
|
1071 | */
|
1072 | mandatory: boolean;
|
1073 | /**
|
1074 | * ZMQ_PROBE_ROUTER
|
1075 | *
|
1076 | * When set to `true`, the socket will automatically send an empty message
|
1077 | * when a new connection is made or accepted. You may set this on sockets
|
1078 | * connected to a {@link Router} socket. The application must filter such
|
1079 | * empty messages. This option provides the {@link Router} with an event
|
1080 | * signaling the arrival of a new peer.
|
1081 | *
|
1082 | * *Warning:** Do not set this option on a socket that talks to any other
|
1083 | * socket type except {@link Router}: the results are undefined.
|
1084 | *
|
1085 | * @writeonly
|
1086 | */
|
1087 | probeRouter: boolean;
|
1088 | /**
|
1089 | * ZMQ_ROUTER_HANDOVER
|
1090 | *
|
1091 | * If two clients use the same identity when connecting to a {@link Router},
|
1092 | * the results shall depend on the this option. If it set to `false`
|
1093 | * (default), the {@link Router} socket shall reject clients trying to connect
|
1094 | * with an already-used identity. If it is set to `true`, the {@link Router}
|
1095 | * socket shall hand-over the connection to the new client and disconnect the
|
1096 | * existing one.
|
1097 | */
|
1098 | handover: boolean;
|
1099 | constructor(options?: SocketOptions<Router>);
|
1100 | /**
|
1101 | * Connects to the given remote address. To specificy a specific routing id,
|
1102 | * provide a `routingId` option. The identity should be unique, from 1 to 255
|
1103 | * bytes long and MAY NOT start with binary zero.
|
1104 | *
|
1105 | * @param address The `tcp://` address to connect to.
|
1106 | * @param options Any connection options.
|
1107 | */
|
1108 | connect(address: string, options?: RouterConnectOptions): void;
|
1109 | }
|
1110 | export interface RouterConnectOptions {
|
1111 | routingId?: string;
|
1112 | }
|
1113 | export interface Router extends Readable, Writable {
|
1114 | }
|
1115 | /**
|
1116 | * A {@link Pull} socket is used by a pipeline node to receive messages from
|
1117 | * upstream pipeline nodes. Messages are fair-queued from among all connected
|
1118 | * upstream nodes. This socket cannot send messages.
|
1119 | */
|
1120 | export declare class Pull extends Socket {
|
1121 | constructor(options?: SocketOptions<Pull>);
|
1122 | }
|
1123 | export interface Pull extends Readable {
|
1124 | /**
|
1125 | * ZMQ_CONFLATE
|
1126 | *
|
1127 | * If set to `true`, a socket shall keep only one message in its
|
1128 | * inbound/outbound queue: the last message to be received/sent. Ignores any
|
1129 | * high water mark options. Does not support multi-part messages - in
|
1130 | * particular, only one part of it is kept in the socket internal queue.
|
1131 | */
|
1132 | conflate: boolean;
|
1133 | }
|
1134 | /**
|
1135 | * A {@link Push} socket is used by a pipeline node to send messages to
|
1136 | * downstream pipeline nodes. Messages are round-robined to all connected
|
1137 | * downstream nodes. This socket cannot receive messages.
|
1138 | *
|
1139 | * When a {@link Push} socket enters the mute state due to having reached the
|
1140 | * high water mark for all downstream nodes, or if there are no downstream nodes
|
1141 | * at all, then {@link Writable.send}() will block until the mute state ends or
|
1142 | * at least one downstream node becomes available for sending; messages are not
|
1143 | * discarded.
|
1144 | */
|
1145 | export declare class Push extends Socket {
|
1146 | constructor(options?: SocketOptions<Push>);
|
1147 | }
|
1148 | export interface Push extends Writable {
|
1149 | /**
|
1150 | * ZMQ_CONFLATE
|
1151 | *
|
1152 | * If set to `true`, a socket shall keep only one message in its
|
1153 | * inbound/outbound queue: the last message to be received/sent. Ignores any
|
1154 | * high water mark options. Does not support multi-part messages - in
|
1155 | * particular, only one part of it is kept in the socket internal queue.
|
1156 | */
|
1157 | conflate: boolean;
|
1158 | }
|
1159 | /**
|
1160 | * Same as {@link Publisher}, except that you can receive subscriptions from the
|
1161 | * peers in form of incoming messages. Subscription message is a byte 1 (for
|
1162 | * subscriptions) or byte 0 (for unsubscriptions) followed by the subscription
|
1163 | * body. Messages without a sub/unsub prefix are also received, but have no
|
1164 | * effect on subscription status.
|
1165 | */
|
1166 | export declare class XPublisher extends Socket {
|
1167 | /**
|
1168 | * ZMQ_XPUB_NODROP
|
1169 | *
|
1170 | * Sets the socket behaviour to return an error if the high water mark is
|
1171 | * reached and the message could not be send. The default is to drop the
|
1172 | * message silently when the peer high water mark is reached.
|
1173 | */
|
1174 | noDrop: boolean;
|
1175 | /**
|
1176 | * ZMQ_XPUB_MANUAL
|
1177 | *
|
1178 | * Sets the {@link XPublisher} socket subscription handling mode to
|
1179 | * manual/automatic. A value of `true` will change the subscription requests
|
1180 | * handling to manual.
|
1181 | */
|
1182 | manual: boolean;
|
1183 | /**
|
1184 | * ZMQ_XPUB_WELCOME_MSG
|
1185 | *
|
1186 | * Sets a welcome message that will be recieved by subscriber when connecting.
|
1187 | * Subscriber must subscribe to the welcome message before connecting. For
|
1188 | * welcome messages to work well, poll on incoming subscription messages on
|
1189 | * the {@link XPublisher} socket and handle them.
|
1190 | */
|
1191 | welcomeMessage: string | null;
|
1192 | /**
|
1193 | * ZMQ_INVERT_MATCHING
|
1194 | *
|
1195 | * Causes messages to be sent to all connected sockets except those subscribed
|
1196 | * to a prefix that matches the message.
|
1197 | */
|
1198 | invertMatching: boolean;
|
1199 | /**
|
1200 | * ZMQ_XPUB_VERBOSE / ZMQ_XPUB_VERBOSER
|
1201 | *
|
1202 | * Whether to pass any duplicate subscription/unsuscription messages.
|
1203 | * * `null` (default) - Only unique subscribe and unsubscribe messages are
|
1204 | * visible to the caller.
|
1205 | * * `"allSubs"` - All subscribe messages (including duplicates) are visible
|
1206 | * to the caller, but only unique unsubscribe messages are visible.
|
1207 | * * `"allSubsUnsubs"` - All subscribe and unsubscribe messages (including
|
1208 | * duplicates) are visible to the caller.
|
1209 | */
|
1210 | set verbosity(value: null | "allSubs" | "allSubsUnsubs");
|
1211 | constructor(options?: SocketOptions<XPublisher>);
|
1212 | }
|
1213 | export interface XPublisher extends Readable, Writable {
|
1214 | }
|
1215 | /**
|
1216 | * Same as {@link Subscriber}, except that you subscribe by sending subscription
|
1217 | * messages to the socket. Subscription message is a byte 1 (for subscriptions)
|
1218 | * or byte 0 (for unsubscriptions) followed by the subscription body. Messages
|
1219 | * without a sub/unsub prefix may also be sent, but have no effect on
|
1220 | * subscription status.
|
1221 | */
|
1222 | export declare class XSubscriber extends Socket {
|
1223 | constructor(options?: SocketOptions<XSubscriber>);
|
1224 | }
|
1225 | export interface XSubscriber extends Readable, Writable {
|
1226 | }
|
1227 | /**
|
1228 | * A {@link Stream} is used to send and receive TCP data from a non-ØMQ peer
|
1229 | * with the `tcp://` transport. A {@link Stream} can act as client and/or
|
1230 | * server, sending and/or receiving TCP data asynchronously.
|
1231 | *
|
1232 | * When sending and receiving data with {@link Writable.send}() and
|
1233 | * {@link Readable.receive}(), the first message part shall be the routing id of
|
1234 | * the peer. Unroutable messages will cause an error.
|
1235 | *
|
1236 | * When a connection is made to a {@link Stream}, a zero-length message will be
|
1237 | * received. Similarly, when the peer disconnects (or the connection is lost), a
|
1238 | * zero-length message will be received.
|
1239 | *
|
1240 | * To close a specific connection, {@link Writable.send}() the routing id frame
|
1241 | * followed by a zero-length message.
|
1242 | *
|
1243 | * To open a connection to a server, use {@link Stream.connect}().
|
1244 | */
|
1245 | export declare class Stream extends Socket {
|
1246 | /**
|
1247 | * ZMQ_STREAM_NOTIFY
|
1248 | *
|
1249 | * Enables connect and disconnect notifications on a {@link Stream} when set
|
1250 | * to `true`. When notifications are enabled, the socket delivers a
|
1251 | * zero-length message when a peer connects or disconnects.
|
1252 | */
|
1253 | notify: boolean;
|
1254 | constructor(options?: SocketOptions<Stream>);
|
1255 | /**
|
1256 | * Connects to the given remote address. To specificy a specific routing id,
|
1257 | * provide a `routingId` option. The identity should be unique, from 1 to 255
|
1258 | * bytes long and MAY NOT start with binary zero.
|
1259 | *
|
1260 | * @param address The `tcp://` address to connect to.
|
1261 | * @param options Any connection options.
|
1262 | */
|
1263 | connect(address: string, options?: StreamConnectOptions): void;
|
1264 | }
|
1265 | export interface StreamConnectOptions {
|
1266 | routingId?: string;
|
1267 | }
|
1268 | export interface Stream extends Readable<[Message, Message]>, Writable<[MessageLike, MessageLike]> {
|
1269 | }
|
1270 |
|
\ | No newline at end of file |