Template del servicio de SIM
This commit is contained in:
43
packages/sim-gestor-eventos/index.ts
Normal file
43
packages/sim-gestor-eventos/index.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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 {}
|
||||
Reference in New Issue
Block a user