I have 10 clients receiving queries from a server, processing the queries and send messages to a server roughly at the same time The receive side is as such:
I first create the socket:
val commandSocket = zmqContext.createSocket(SocketType.ROUTER)
commandSocket.identity = identity.toByteArray()
commandSocket.bind(commandBindAddr)
Then send a query as a commands to all clients;
for (client in clientsArray) {
commandSocket.sendMore(client)
commandSocket.sendMore("")
commandSocket.send(queryBytes)
println("command server sent to " + client.decodeToString() )
}
Then I wait for the reply; ....
fun start(): Thread {
return thread(start=true) {
println("CommandServer")
while (true) {
val addrb = commandSocket.recv()
val empty = commandSocket.recv()
val msg = commandSocket.recv()
println("message received from ${String(addrb)}")
bq.add(Pair(addrb, msg))
}
}
}
The client side is as such: Creating the socket:
val querySocket = zmqContext.createSocket(SocketType.REQ)
querySocket.identity = identity.toByteArray()
querySocket.connect(queryAddr)
fun start(): Thread {
val serializer = Cbor()
return thread(start=true) {
println("QueryProcessor")
while (true) {
val recvBytes = querySocket.recv()
if (recvBytes != null) {
val q = serializer.load(Query.serializer(), recvBytes)
val qr = bp.process(q)
val res = serializer.dump(QueryResponse.serializer(), qr)
println("$sending query response back")
querySocket.send(res)
println("${logTS()} sent to parent")
} else {
querySocket.send(null as ByteArray?)
}
}
}
}
The queries are received and processed by the client and replies are sent back, but as I increase the number of clients, I don't receive messages at the server. It seems that they get somehow lost.
Any idea how to solve this?