Skip to content

Commit

Permalink
feat(rabbitmq): add publish options
Browse files Browse the repository at this point in the history
  • Loading branch information
isuvorov committed Feb 19, 2024
1 parent f98df3a commit 0347180
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libs/rabbitmq/src/RmqService.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
import { createLogger } from '@lsk4/log';
import { Injectable } from '@nestjs/common';
import { Options } from 'amqplib';

import { RmqRequestPayload } from './types';

@Injectable()
export class RmqService {
constructor(private readonly amqpConnection: AmqpConnection) {}

async publish(exchange: string, routingKey: string, payload: RmqRequestPayload) {
async publish(
exchange: string,
routingKey: string,
payload: RmqRequestPayload,
options?: Options.Publish,
) {
const { pattern, ...other } = payload || {};
const ns = ['rmq:publish', exchange, routingKey].filter(Boolean).join(':');
// TODO: add cache
const log = createLogger(ns);
log.trace(`[${pattern}]`, other);
const time = Date.now();
const res = await this.amqpConnection.publish(exchange, routingKey, payload);
const res = await this.amqpConnection.publish(exchange, routingKey, payload, options);
const ms = Date.now() - time;
log.debug(`[${pattern}]`, other, res || 'OK', `${ms}ms`);
return res;
Expand Down

0 comments on commit 0347180

Please sign in to comment.