Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
fix(rpc): use different routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazmi35 authored Feb 23, 2024
1 parent 920961e commit d270c39
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions services/kanao-cache/src/Structures/KanaoCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,20 @@ export class KanaoCache extends EventEmitter {
this.logger.info(`Successfully bind queue ${queue} to exchange kanao-gateway with routing key ${routingKey.key}`);

// Used for Counts RPC
const rpc = new RoutedQueue(GatewayExchangeRoutes.REQUEST, clientId, "cache-rpc");
const rpc = new RoutedQueue(`${GatewayExchangeRoutes.REQUEST}.stats`, clientId, "cache-rpc");
await channel.assertQueue(rpc.queue, { durable: false });
await channel.bindQueue(rpc.queue, RabbitMQ.GATEWAY_EXCHANGE, rpc.key);

await channel.consume(rpc.queue, async message => {
if (message) {
const content = JSON.parse(message.content.toString()) as { replyTo: string; request: "counts" | "stats"; };
if (content.request !== "counts") return;

const content = JSON.parse(message.content.toString()) as { replyTo: string; };
const guilds = await this.drizzle.select({ count: count(schema.guilds.id) }).from(schema.guilds).execute();
const users = await this.drizzle.select({ count: count(schema.users.id) }).from(schema.users).execute();
const channels = await this.drizzle.select({ count: count(schema.channels.id) }).from(schema.channels).execute();

channel.ack(message);
await this.amqp.sendToQueue(content.replyTo, Buffer.from(
JSON.stringify({ request: content.request, clientId, guilds, users, channels })
JSON.stringify({ route: rpc.key, clientId, guilds, users, channels })
), { correlationId: message.properties.correlationId as string });
}
});
Expand Down

0 comments on commit d270c39

Please sign in to comment.