Skip to content

Commit

Permalink
fix(orders): solve RPC handlers issue
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Dec 13, 2023
1 parent be9672f commit 48a5d7e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
16 changes: 10 additions & 6 deletions apps/orders/src/app/orders/orders-ms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class OrdersMSController {
) {}

@ApiExcludeEndpoint()
@EventPattern(Patterns.ExpirationCompleted, Transport.NATS)
@EventPattern(Patterns.ExpirationCompleted, Transport.RMQ)
async onExpiration(
@Payload() data: ExpirationCompletedEvent['data'],
@Ctx() context: RmqContext,
Expand All @@ -38,16 +38,18 @@ export class OrdersMSController {
this.logger.debug(`received message on ${pattern}`, {
data,
});
// TODO: conditional ack
try {
await this.ordersService.expireById(data.id);
} finally {
channel.ack(message);
} catch (e) {
// TODO: requeue when error is timeout or connection error
channel.nack(message);
throw e;
}
}

@ApiExcludeEndpoint()
@EventPattern(Patterns.PaymentCreated, Transport.NATS)
@EventPattern(Patterns.PaymentCreated, Transport.RMQ)
async onPaymentCreated(
@Payload(
new ValidationPipe({
Expand All @@ -66,11 +68,13 @@ export class OrdersMSController {
this.logger.debug(`received message on ${pattern}`, {
data,
});
// TODO: conditional ack
try {
await this.ordersService.complete(data);
} finally {
channel.ack(message);
} catch (e) {
// TODO: requeue when error is timeout or connection error
channel.nack(message);
throw e;
}
}
}
12 changes: 8 additions & 4 deletions apps/orders/src/app/tickets/tickets-ms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export class TicketsMSController {
this.logger.debug(`received message on ${pattern}`, {
data,
});
// TODO: conditional ack
try {
await this.ticketsService.create(data);
} finally {
channel.ack(message);
} catch (e) {
// TODO: requeue when error is timeout or connection error
channel.nack(message);
throw e;
}
}

Expand All @@ -73,11 +75,13 @@ export class TicketsMSController {
this.logger.debug(`received message on ${pattern}`, {
data,
});
// TODO: conditional ack
try {
await this.ticketsService.updateById(data.id, data);
} finally {
channel.ack(message);
} catch (e) {
// TODO: requeue when error is timeout or connection error
channel.nack(message);
throw e;
}
}
}
12 changes: 8 additions & 4 deletions apps/tickets/src/app/orders/orders-ms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export class OrdersMSController {
this.logger.debug(`received message on ${pattern}`, {
data,
});
// TODO: conditional ack
try {
await this.ticketsService.createOrder(data);
} finally {
channel.ack(message);
} catch (e) {
// TODO: requeue when error is timeout or connection error
channel.nack(message);
throw e;
}
}

Expand All @@ -73,11 +75,13 @@ export class OrdersMSController {
this.logger.debug(`received message on ${pattern}`, {
data,
});
// TODO: conditional ack
try {
await this.ticketsService.cancelOrder(data);
} finally {
channel.ack(message);
} catch (e) {
// TODO: requeue when error is timeout or connection error
channel.nack(message);
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ErrorResponseDto extends ErrorResponse {
declare statusCode: number;

@ApiProperty({
description: 'HTTP path or NATS subject',
description: 'HTTP path or RMQ routing key',
})
declare path: string;

Expand Down

0 comments on commit 48a5d7e

Please sign in to comment.