I'm trying to dynamically load balance a workload. To do this I am using the Req-Router pattern.
However currently it just hangs rather than any of the messages going through.
This is my workload generator code (server.py
):
import zmq
address = "ipc:///path/to/named/socket.sock"
socket = zmq.Context().socket(zmq.ROUTER)
socket.bind(address)
for i in range(1000):
addr,_,resp = socket.recv_multipart()
print(resp)
socket.send_multipart([addr, b'', "Ping: " + str(i)])
And my client code (Client.java
):
public static void main(String[] args) throws Exception {
String address = "/path/to/named/socket.sock";
System.out.println("CLIENT: Parsed Address: " + address);
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket socket = context.socket(SocketType.REQ);
address = "ipc://" + address;
socket.connect( address );
System.out.println("CLIENT: Connected to " + address);
for(int i = 0; i < 1000; i++){
socket.send("Ping " + i);
System.out.println("CLIENT: Sent.");
String rep = new String(socket.recv());
System.out.println("Reply " + i + ": " + rep);
}
socket.close();
context.term();
}
}
The issue is that this will print out Client: Sent
however on the other end the server will never print out anything.
I have this working with a basic python client:
import zmq
from sys import argv
print("CLIENT: pinging")
"""Sends ping requests and waits for replies."""
context = zmq.Context()
sock = context.socket(zmq.REQ)
print("CLIENT: Binding to ipc://"+argv[-1])
sock.bind("ipc://"+argv[-1])
print('bound')
for i in range(1000):
sock.send('ping %s' % i)
rep = sock.recv() # This blocks until we get something
print('Ping got reply:', rep)
Which to my eye appears to do the same as the java client (though since it doesn't I presume that I am missing something).
Any help would be greatly appreciated!