Skip to content

Commit

Permalink
refactor: use an direct exchange for email verification
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseAlbDR committed Feb 16, 2024
1 parent 987caac commit 91f5c7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 0 additions & 6 deletions src/presentation/animals/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export class AnimalRoutes {
animalController.delete
);

router.post(
'/:id/add-favorite',
authMiddleware.authenticateUser,
animalController.addToFavorites
);

return router;
}
}
2 changes: 1 addition & 1 deletion src/presentation/auth/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AuthRoutes {
envs.MAILER_SECRET_KEY
);

const producer = new ProducerService(envs.RABBITMQ_URL, 'email-service');
const producer = new ProducerService(envs.RABBITMQ_URL);

const authService = new AuthService(
jwt,
Expand Down
22 changes: 15 additions & 7 deletions src/presentation/services/producer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@ import amqp, { ChannelWrapper } from 'amqp-connection-manager';

export class ProducerService {
private channelWrapper: ChannelWrapper;
private EXCHANGE: string;

constructor(
private readonly rabbitmqUrl: string,
private readonly queue: string
) {
constructor(private readonly rabbitmqUrl: string) {
this.EXCHANGE = 'email-request';
const connection = amqp.connect(this.rabbitmqUrl);
this.channelWrapper = connection.createChannel({
setup: (channel: Channel) => {
return channel.assertQueue(queue, { durable: true });
// return channel.assertQueue(queue, { durable: true });
return channel.assertExchange(this.EXCHANGE, 'direct', {
durable: true,
});
},
});
}

async addToEmailQueue(payload: any) {
try {
await this.channelWrapper.sendToQueue(
this.queue,
// await this.channelWrapper.sendToQueue(
// queue,
// Buffer.from(JSON.stringify(payload)),
// { persistent: true }
// );
await this.channelWrapper.publish(
this.EXCHANGE,
'verify-email',
Buffer.from(JSON.stringify(payload)),
{ persistent: true }
);
Expand Down

0 comments on commit 91f5c7e

Please sign in to comment.