Skip to content

Commit

Permalink
Merge pull request #89 from thanhdanh27600/staging
Browse files Browse the repository at this point in the history
fix export
  • Loading branch information
thanhdanh27600 authored Jul 23, 2023
2 parents 0e6885f + e7d22f9 commit be3be94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ next-env.d.ts
*.env.production
prisma/*.db*
/logs
*.log
50 changes: 25 additions & 25 deletions rabbitmq/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
//@ts-nocheck
// @ts-nocheck
export = {};
// const { AMQPClient } = require('@cloudamqp/amqp-client');

const { AMQPClient } = require('@cloudamqp/amqp-client');
// async function initRabbitMQ() {
// try {
// const amqp = new AMQPClient(process.env.RABBITMQ_URL);
// const conn = await amqp.connect();
// const channel = await conn.channel();
// const queue = await channel.queue('shortened'); // RabbitMQChannel.SHORTENED
// await queue.subscribe({ noAck: true }, consumer);
// console.log('RabittMQ is running');
// } catch (error) {
// console.error('RabittMQ', error);
// error.connection.close();
// }
// }

async function initRabbitMQ() {
try {
const amqp = new AMQPClient(process.env.RABBITMQ_URL);
const conn = await amqp.connect();
const channel = await conn.channel();
const queue = await channel.queue('shortened'); // RabbitMQChannel.SHORTENED
await queue.subscribe({ noAck: true }, consumer);
console.log('RabittMQ is running');
} catch (error) {
console.error('RabittMQ', error);
error.connection.close();
}
}

const consumer = async (msg) => {
// console.log('RabittMQ received: ', msg.bodyToString());
console.log(JSON.parse(msg.bodyToString()));
await setTimeout(() => {
console.log('processed', msg.bodyToString());
}, 5000);
// await consumer.cancel();
};
module.exports = { initRabbitMQ };
// const consumer = async (msg) => {
// // console.log('RabittMQ received: ', msg.bodyToString());
// console.log(JSON.parse(msg.bodyToString()));
// await setTimeout(() => {
// console.log('processed', msg.bodyToString());
// }, 5000);
// // await consumer.cancel();
// };
// module.exports = { initRabbitMQ };

0 comments on commit be3be94

Please sign in to comment.