Skip to main content

MQApi

Package: @opra/common

MQApi is the runtime class that represents the message-queue transport layer of an OPRA document. When you access document.api and the transport is 'mq', the returned value is an MQApi instance. It holds all controllers and provides lookup helpers for controllers and operations.


Inheritance

DocumentElement
└── ApiBase
└── MQApi

Properties

PropertyTypeDescription
transport'mq'Always 'mq'.
platformstringThe messaging platform identifier (e.g. 'kafka', 'rabbitmq').
controllersResponsiveMap<MQController>All top-level controllers registered on this API.

Methods

findController(typeOrName)

Returns the MQController matching the given constructor or string name, or undefined if not found.

const ctrl = mqApi.findController('CustomerQueue');
const ctrl = mqApi.findController(CustomerController);
findController(typeOrName: Type | string): MQController | undefined

findOperation(controllerTypeOrName, operationName)

Locates an operation by its controller and operation name. Returns undefined if either the controller or operation does not exist.

const op = mqApi.findOperation('CustomerQueue', 'processOrder');
const op = mqApi.findOperation(CustomerController, 'processOrder');
findOperation(
controllerTypeOrName: Type | string,
operationName: string,
): MQOperation | undefined

toJSON(options?)

Returns a plain OpraSchema.MQApi object for schema export.

toJSON(options?: ApiDocument.ExportOptions): OpraSchema.MQApi

Obtaining an MQApi instance

MQApi is constructed by ApiDocumentFactory — you do not create it directly.

import { MQApi } from '@opra/common';

const document = await ApiDocumentFactory.createDocument({ ... });

if (document.api instanceof MQApi) {
console.log(document.api.transport); // 'mq'
console.log(document.api.platform); // e.g. 'kafka'

for (const [name, ctrl] of document.api.controllers) {
console.log(name, ctrl.kind); // 'MQController'
}
}

ApiDocument · MQController · MQOperation