import ampqlib from 'amqplib' import mongoose from 'mongoose' import app from './app' // import OrderCreatedListener from './events/listeners/order-created' // import OrderCancelledListener from './events/listeners/order-cancelled' const start = async () => { if (!process.env.JWT_KEY) throw new Error('JWT_KEY is undefined') if (!process.env.MONGO_URI) throw new Error('MONGO_URI is undefined') if (!process.env.RABBITMQ_URI) throw new Error('RABBITMQ_URI is undefined') const client = await ampqlib.connect(process.env.RABBITMQ_URI) const listenerChannel = await client.createChannel() const publisherChannel = await client.createChannel() // await listenerChannel.assertQueue('sheets') // listenerChannel.consume('sheets', msg => { // if (!msg) return console.warn('null msg') // console.log('MSG:', msg.content.toString()) // listenerChannel.ack(msg) // }) // // new TranslationCreatedListener({ client: client, listener: listenerChannel, publisher: publisherChannel }) // publisherChannel.sendToQueue('sheets', Buffer.from(Math.random().toString(36))) process.on('SIGINT', () => client.close()) process.on('SIGTERM', () => client.close()) await mongoose.connect(process.env.MONGO_URI) console.log('Database connected') const port = process.env.PORT || 3000 app.listen(port, () => console.log('Service running on port:', port)) } start()