Skip to content

Commit a440a79

Browse files
committed
Use publish to select exchange and async await
1 parent 045c419 commit a440a79

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/common/rabbitmq/rabbitmq.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ export class RabbitMQService implements OnModuleDestroy, OnApplicationShutdown {
6969
}
7070
}
7171

72-
private connect(queue: string, exchange: string, key: string) {
72+
private async connect(queue: string, exchange: string, key: string) {
7373
try {
74-
this.channel.assertQueue(queue, { durable: true });
75-
this.channel.assertExchange(exchange, "topic", {
74+
await this.channel.assertQueue(queue, { durable: true });
75+
await this.channel.assertExchange(exchange, "topic", {
7676
durable: true,
7777
});
78-
this.channel.bindQueue(queue, exchange, key);
78+
await this.channel.bindQueue(queue, exchange, key);
7979
} catch (error) {
8080
throw new Error(
8181
`Could not connect to RabbitMQ queue ${queue} with exchange ${exchange} and key ${key}.`,
@@ -84,10 +84,10 @@ export class RabbitMQService implements OnModuleDestroy, OnApplicationShutdown {
8484
}
8585
}
8686

87-
sendMessage(queue: string, exchange: string, key: string, message: string) {
87+
async sendMessage(queue: string, exchange: string, key: string, message: string) {
8888
try {
89-
this.connect(queue, exchange, key);
90-
this.channel.sendToQueue(queue, Buffer.from(message), {
89+
await this.connect(queue, exchange, key);
90+
await this.channel.publish(exchange, key, Buffer.from(message), {
9191
persistent: true,
9292
});
9393
} catch (error) {

src/config/job-config/actions/rabbitmqaction/rabbitmqaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class RabbitMQJobAction<T extends JobDto> implements JobAction<T> {
4040
"Performing RabbitMQJobAction: " + JSON.stringify(job),
4141
"RabbitMQJobAction",
4242
);
43-
this.rabbitMQService.sendMessage(
43+
await this.rabbitMQService.sendMessage(
4444
this.queue,
4545
this.exchange,
4646
this.key,

0 commit comments

Comments
 (0)