IMQClient class

Base class for service clients.

Subclass it and declare every remote method as @remote() async m(...args) \{ return await this.remoteCall<T>(...arguments); \}, or let IMQClient.create() generate the subclass from a running service's description.

Signature:

export declare abstract class IMQClient extends EventEmitter 

Extends: EventEmitter

Remarks

Abstractness is enforced at runtime as well as by the type system: constructing IMQClient directly throws a TypeError.

Instances are EventEmitters. Besides ordinary calls, any response that no longer has a pending caller is emitted as an event named after the remote method, carrying the raw IMQRPCResponse — the escape hatch for replies to calls made by a process that has since died.

The identity properties pair up as follows: IMQClient.serviceName is where calls go, IMQClient.queueName is where answers come back, IMQClient.name identifies this client, IMQClient.hostName identifies the machine plus instance, and IMQClient.id is the per-host instance slot.

Constructors

Constructor

Modifiers

Description

(constructor)(options, serviceName, name)

Constructs a client.

Properties

Property

Modifiers

Type

Description

hostName

readonly

string

Machine-scoped identity, "<osUuid>-<id>:client", where osUuid is a hash of the OS machine id.

id

readonly

number

Per-host instance slot number — not an OS process id.

name

readonly

string

This client's unique identity, "<baseName>-<hostName>".

options

readonly

IMQClientOptions

The effective options for this client: DEFAULT_IMQ_CLIENT_OPTIONS merged with the values passed to the constructor.

queueName

readonly

string

The local side: the queue replies come back on, and the value placed in request.from.

serviceName

readonly

string

The remote side: the queue every request is addressed to, and the pub/sub channel IMQClient.subscribe() listens on.

Methods

Method

Modifiers

Description

broadcast(payload)

Publishes the given payload on this client's own queue channel (IMQClient.queueName).

create(name, options)

static

Generates a client for the service registered under the given queue name and resolves to the generated namespace object — not to a client instance, and not to an IMQClient.

describe(_delay)

Returns service description metadata.

destroy()

Destroys client

remoteCall(args)

protected

Sends a call to the remote service method.

Intended to be invoked as this.remoteCall<T>(...arguments) from a method decorated with remote(), which appends the method name for you.

start()

Initializes client work

stop()

Stops client work

subscribe(handler)

Subscribes to the service's event channel, named after IMQClient.serviceName — the same channel a service's publish() writes to, so every client of that service receives every published payload.

unsubscribe()

Stops receiving service events: unsubscribes the channel, discards every handler registered through IMQClient.subscribe(), and closes the dedicated subscription connection.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.