I am getting this exception:
org.zeromq.ZMQException: Errno 4
at org.zeromq.ZMQ$Socket.mayRaise(ZMQ.java:3732) ~[jeromq-0.5.3.jar:na]
at org.zeromq.ZMQ$Socket.recv(ZMQ.java:3530) ~[jeromq-0.5.3.jar:na]
at com.forexassistant.service.zeromq.CurrencyStrengthZeroMQ.sendCurrencyStrengthRequest(CurrencyStrengthZeroMQ.java:30) ~[classes/:na]
at com.forexassistant.service.algorithmlogic.AlgorithmLogic.getCurrencyStrength(AlgorithmLogic.java:209) ~[classes/:na]
at sun.reflect.GeneratedMethodAccessor111.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_241]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_241]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.22.jar:5.3.22]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_241]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_241]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_241]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_241]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_241]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_241]
Suppressed: org.zeromq.ZMQException: Errno 4
at zmq.Ctx.terminate(Ctx.java:304) ~[jeromq-0.5.3.jar:na]
at org.zeromq.ZMQ$Context.term(ZMQ.java:671) ~[jeromq-0.5.3.jar:na]
at org.zeromq.ZContext.destroy(ZContext.java:136) ~[jeromq-0.5.3.jar:na]
at org.zeromq.ZContext.close(ZContext.java:463) ~[jeromq-0.5.3.jar:na]
at com.forexassistant.service.zeromq.CurrencyStrengthZeroMQ.sendCurrencyStrengthRequest(CurrencyStrengthZeroMQ.java:37) ~[classes/:na]
... 13 common frames omitted
I have no idea why it is happening, the logic in question is this that communicates with the socket:
public String sendCurrencyStrengthRequest() {
try (ZContext context = new ZContext()) {
ZMQ.Socket socket = context.createSocket(SocketType.PUSH);
socket.connect("tcp://localhost:32868");
ZMQ.Socket socket2 = context.createSocket(SocketType.PULL);
socket2.connect("tcp://localhost:32869");
String msg = "GET_CURRENCY_STRENGTHS";
socket.send(msg,1);
while (!Thread.currentThread().isInterrupted()) {
byte[] reply = socket2.recv(0);
if(reply!=null) {
currencyStrengths= new String(reply, ZMQ.CHARSET);
}
context.close();
break;
}
}
return currencyStrengths;
}
Am I doing this wrong? sendCurrencyStrengthRequest() is scheduled in Spring to be called every 5 seconds and there is another function that will be called every 30mins that uses a different pull and push socket within a different context, all this works for a while and then this error gets thrown, any idea?