import { RpcClient, RpcMsg } from '@sky-distribution/message-queue-rpc-library'; import Container, { Service } from 'typedi'; import { config } from '../../config/config'; import { TenantUtil } from '../../utils/Tenant.util'; @Service() export class Messenger { private readonly rpcClient: RpcClient; constructor() { this.rpcClient = Container.get('rpcClient'); } async send( cmd: string, inputParams: TInputType, ): Promise { type CustomRpcMessage = RpcMsg; const uaaAuthorization = TenantUtil.getAuthorizationToken(); const msgPrepared = { msg: { cmd, arg: { ...inputParams, ...(uaaAuthorization ? { uaaAuthorization } : undefined), }, } as CustomRpcMessage, exchangeName: config().queue?.cmdExchangeName as string, }; const res = await this.rpcClient.sendRpcCmd( msgPrepared, ); return res.msg; } }