44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import client, { ChannelModel, connect, Connection } from "amqplib"
|
|
import { env } from "config/env"
|
|
import { Channel } from "node:diagnostics_channel"
|
|
|
|
const rmqUser = env.RABBITMQ_USER
|
|
const rmqPass = env.RABBITMQ_PASSWORD
|
|
const rmqHost = env.RABBITMQ_HOST
|
|
const rmqPort = Number(env.RABBITMQ_PORT)
|
|
const rmqSecure = env.RABBITMQ_SECURE
|
|
|
|
class RabbitConnection {
|
|
connection?: Connection
|
|
channel?: Channel
|
|
connected: Boolean = false
|
|
|
|
|
|
protected async createConnection(): Promise<ChannelModel> {
|
|
const { hostname, port, secure } = { hostname: rmqHost, port: rmqPort, secure: rmqSecure }
|
|
const { username, password } = { username: rmqUser, password: rmqPass };
|
|
const protocol = secure ? 'amqps' : 'amqp';
|
|
|
|
const connection = await connect({
|
|
protocol,
|
|
hostname,
|
|
port,
|
|
username,
|
|
password
|
|
});
|
|
|
|
connection.on('error', (error: unknown) => {
|
|
console.error(`[EVENT BUS] Rabbitmq connection error :: ${error}`);
|
|
Promise.reject(error);
|
|
});
|
|
|
|
return connection;
|
|
}
|
|
}
|
|
|
|
while (true) {
|
|
console.log("test")
|
|
}
|
|
|
|
export default {}
|