Hexagonal, mejora del cliente RMQ y tipos de eventos
This commit is contained in:
50
packages/sim-entrada-eventos/index.ts
Normal file
50
packages/sim-entrada-eventos/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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 {}
|
||||
Reference in New Issue
Block a user