I am practicing with the ZeroMQ module to create Socket but I am having a problem with the Proxy pattern (Router / Router), I have been able to verify that the Client connects well with the Front and the Worker with the Back but when it arrives to send the message from Front to Back or vice versa is not sent, does anyone know why? ..
Attached the Broker code, if necessary the Client or Worker code could provide it.
import * as zmq from 'zeromq'
const ipBrokerClient: string = 'tcp://*:4000'
const ipBrokerWorker: string = 'tcp://*:3000'
const idWorker: string = 'worker_proxy_${process.pid}'
let frontend= zmq.socket('router'),
backend= zmq.socket('router')
let workers: Array<string> = []
export = {
loadFrontend(): void {
frontend.identity = 'frontend_proxy' + process.pid
frontend.bind(ipBrokerClient, function (err: string) {
if (err) throw err
console.log("Frontend en escucha: " + frontend.identity)
frontend.on('message', function (...buffer: Array<Buffer>): void {
let idClient: Buffer = buffer[0],
empty: Buffer = buffer[1],
query: Buffer = buffer[2]
let interval = setInterval(function (): void {
if (workers.length > 0) {
console.log("Frontend envia: " + query)
backend.send([workers.shift(), '', idClient, '', query])
clearInterval(interval)
}
}, 10)
})
})
},
loadBackend(): void {
backend = zmq.socket('router')
backend.identity = 'backend_proxy' + process.pid
backend.bind(ipBrokerWorker, function (err: string): void {
if (err) throw err
console.log("Backend en escucha: " + backend.identity)
backend.on('message', function (...buffer: Array<Buffer>) {
console.log(buffer)
let idWorker: Buffer = buffer[0],
empty0: Buffer = buffer[1],
idClient: Buffer = buffer[2],
empty1: Buffer = buffer[3],
query: Buffer = buffer[4]
workers.push(idClient.toString())
console.log("Worker disponible: " + idClient)
frontend.send("HOLA")
if (workers[0] != "READY") {
frontend.send([idClient, empty0, query])
}
})
})
},
loadBroker(): void {
this.loadFrontend()
this.loadBackend()
}
}
Excuse me if the question is not well done, I am new to the forum.
Thanks