@imqueue/rpc
Version:
RPC-like client-service implementation over messaging queue
105 lines (104 loc) • 3.45 kB
TypeScript
/*!
* IMQService implementation
*
* I'm Queue Software Project
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* If you want to use this code in a closed source (commercial) project, you can
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
import { JsonObject, ILogger, IMessageQueue } from '@imqueue/core';
import { TypesDescription, IMQRPCRequest, IMQRPCResponse, IMQServiceOptions, ICache, MethodsCollectionDescription } from '.';
import * as http from 'node:http';
export declare class Description {
service: {
name: string;
methods: MethodsCollectionDescription;
};
types: TypesDescription;
}
/**
* Class IMQService
* Basic abstract service (server-side) implementation
*/
export declare abstract class IMQService {
[property: string]: any;
protected imq: IMessageQueue;
protected logger: ILogger;
protected cache: ICache;
protected metricsServer?: http.Server<any, any>;
name: string;
options: IMQServiceOptions;
/**
* Class constructor
*
* @constructor
* @param {Partial<IMQServiceOptions>} options
* @param {string} [name]
*/
constructor(options?: Partial<IMQServiceOptions>, name?: string);
/**
* Handles incoming request and produces corresponding response
*
* @access private
* @param {IMQRPCRequest} request - request message
* @param {string} id - message unique identifier
* @return {Promise<string>}
*/
private handleRequest;
/**
* Initializes this instance of service and starts handling request
* messages.
*
* @return {Promise<IMessageQueue | undefined>}
*/
start(): Promise<IMessageQueue | undefined>;
/**
* Sends given data to service subscription channel
*
* @param {JsonObject} data
*/
publish(data: JsonObject): Promise<void>;
/**
* Stops service from handling messages
*
* @return {Promise<void>}
*/
stop(): Promise<void>;
/**
* Destroys this instance of service
*
* @return {Promise<void>}
*/
destroy(): Promise<void>;
/**
* Returns service description metadata.
*
* @returns {Promise<Description>}
*/
describe(): Description;
private startWithMetricsServer;
}
/**
* Sends IMQ response with support of after call optional hook
*
* @param {IMQRPCRequest} request - from message identifier
* @param {IMQRPCResponse} response - response to send
* @param {IMQService} service - imq service to bind
* @return {Promise<string>} - send result message identifier
*/
export declare function send(request: IMQRPCRequest, response: IMQRPCResponse, service: IMQService): Promise<string>;