Skip to content

Commit

Permalink
Custom Timeout for Message
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarmoc committed Jul 31, 2020
1 parent f893e34 commit 9f7ce1d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ Also you can use send options:
this.rmqService.send<number[], number>('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:

Expand Down
1 change: 1 addition & 0 deletions lib/interfaces/rmq-publish-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface IPublishOptions {
expiration?: number;
priority?: number;
persistent?: boolean;
timeout?: number;
}
2 changes: 1 addition & 1 deletion lib/rmq.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class RMQService {
public async send<IMessage, IReply>(topic: string, message: IMessage, options?: IPublishOptions): Promise<IReply> {
return new Promise<IReply>(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);
Expand Down

0 comments on commit 9f7ce1d

Please sign in to comment.