After reading benchmark results of zeromq , I was wondering if I can give it a try for accessing a ReSTFul API via HTTP GET calls over zeromq. I want to test if zeromq can provide a Low-Latency Request-Reply mechanism as compared other alternatives like jersey client API, HTTPurl , Apache hc etc. I want to have this implemented in java so here is what I am trying, as per a tutorial
XREP -> HTTP client With this you could re-use existing web-applications running on a HTTP server as backend workers for a work queue. This is like a reverse HTTP proxy which load-balances across multiple backend HTTP servers.
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket requester2 = context.socket(ZMQ.XREP);
requester2.connect("http://domainURL/path");
But this is wrong as I am getting
java.lang.UnsupportedOperationException: http
I know I haven't coded this properly but it will be helpful if any guidelines or code snippets in java are provided ?
EDIT I found a resource where a python code is calling remote web service as
import json
import zmq
# set up zmq socket
sock = zmq.Context.instance().socket(zmq.REQ)
sock.connect('ipc:///tmp/zurl-req')
# send request
req = {
'method': 'GET',
'uri': 'http://example.com/path'
}
sock.send('J' + json.dumps(req))
# print response
print json.loads(sock.recv()[1:])
So I am trying to modify my java code as below:
import org.zeromq.ZMQ;
public class hwclient {
public static void main(String[] args) {
ZMQ.Context context2 = ZMQ.context(1);
ZMQ.Socket sock = context2.socket(ZMQ.REQ);
sock.connect("ipc:///tmp/zurl-req");
String req = "{\n" +
" 'method': 'GET',\n" +
" 'uri': 'http://domainURI/path/" +
"}\n";
sock.send(req);
System.out.println("-->" + new String(sock.recv(0)));
context2.term();
}
}
But now the problem is I do not know what should be the value in place of "ipc:///tmp/zurl-req"