diff --git a/README.md b/README.md index 396e00d..f163a88 100644 --- a/README.md +++ b/README.md @@ -162,12 +162,14 @@ Also you can use send options: this.rmqService.send('sum.rpc', [1, 2, 3], { expiration: 1000, priority: 1, - persistent: true + persistent: true, + timeout: 30000 }) ``` - **expiration** - if supplied, the message will be discarded from a queue once it’s been there longer than the given number of milliseconds. - **priority** - a priority for the message. - **persistent** - if truthy, the message will survive broker restarts provided it’s in a queue that also survives restarts. +- **timeout** - if supplied, the message will have its own timeout. If you want to just notify services: diff --git a/lib/interfaces/rmq-publish-options.interface.ts b/lib/interfaces/rmq-publish-options.interface.ts index 5272926..cad1337 100644 --- a/lib/interfaces/rmq-publish-options.interface.ts +++ b/lib/interfaces/rmq-publish-options.interface.ts @@ -2,4 +2,5 @@ export interface IPublishOptions { expiration?: number; priority?: number; persistent?: boolean; + timeout?: number; } \ No newline at end of file diff --git a/lib/rmq.service.ts b/lib/rmq.service.ts index be82d73..eb1c566 100644 --- a/lib/rmq.service.ts +++ b/lib/rmq.service.ts @@ -98,7 +98,7 @@ export class RMQService { public async send(topic: string, message: IMessage, options?: IPublishOptions): Promise { return new Promise(async (resolve, reject) => { const correlationId = this.getUniqId(); - const timeout = this.options.messagesTimeout ?? DEFAULT_TIMEOUT; + const timeout = options.timeout ?? this.options.messagesTimeout ?? DEFAULT_TIMEOUT; const timerId = setTimeout(() => { reject(new RMQError(`${ERROR_TIMEOUT}: ${timeout}`, ERROR_TYPE.TRANSPORT)); }, timeout);