51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
import { env } from "#config/env"
|
|
import { SimEvents } from "#shared/domain/SimEvents"
|
|
import { RabbitMQEventBus, RMQConnectionParams } from "#shared/infrastructure/RabbitMQEventBus"
|
|
|
|
const rmqUser = env.RABBITMQ_USER
|
|
const rmqPass = env.RABBITMQ_PASSWORD
|
|
const rmqHost = env.RABBITMQ_HOST
|
|
const rmqPort = Number(env.RABBITMQ_PORT)
|
|
const rmqSecure = false
|
|
const rmqVhost = env.RABBITMQ_VHOST
|
|
|
|
|
|
|
|
async function test() {
|
|
const connOptions = <RMQConnectionParams>{
|
|
username: rmqUser,
|
|
password: rmqPass,
|
|
vhost: rmqVhost,
|
|
hostname: rmqHost,
|
|
port: rmqPort,
|
|
secure: rmqSecure,
|
|
}
|
|
|
|
const event = <SimEvents.activation>{
|
|
key: "sim.activation",
|
|
payload: {
|
|
iccid: "1234"
|
|
},
|
|
options: {
|
|
|
|
}
|
|
}
|
|
|
|
const rmqCli = new RabbitMQEventBus({
|
|
connectionParams: connOptions
|
|
})
|
|
|
|
await rmqCli.connect()
|
|
|
|
console.log("publicando", event)
|
|
rmqCli.publish([event])
|
|
.then(e => {
|
|
console.log("Mensaje publicado", e)
|
|
})
|
|
.catch(err => console.error)
|
|
}
|
|
|
|
test()
|
|
|
|
export default {}
|