Library ZMQ to Java does not work

0

I am trying to connect to a bitcoin node using the ZMQ library for Java. the problem is that when I try to receive a response the code remains frozen. Returns nothing.

This is my code:

public class CBETest {

    private static final String TEST_URL = "obelisk.airbitz.co";

    public static void main(String[] args) {

       System.out.println("\t--- ZMQ ---");
       Ctx c = zmq.ZMQ.createContext();
       SocketBase s = c.createSocket(zmq.ZMQ.ZMQ_DEALER);

       zmq.ZMQ.connect(s, "tcp://"+TEST_URL+":9091");
       System.out.println("Connected!");
       int sent = zmq.ZMQ.send(s, "blockchain.fetch_last_height", 0);

       System.out.println("Sent: " + sent);
       Msg msg = zmq.ZMQ.recv(s, 0);
       System.out.println("Response " + Arrays.toString(msg.data()));
    }
}

The code freezes in the line Msg msg = zmq.ZMQ.recv(s, 0);. I am using the calls described here for the full node implemetation. Thanks in advance!

Ander Acosta

Posted 2016-01-04T08:49:36.107

Reputation: 372

Double check, if you have started bitcoind with -zmqpubhashtx=tcp://<ip>:<port> and or -zmqpubhashblock=tcp://<ip>:<port>.Jonas Schnelli 2016-01-04T12:17:10.850

Also check https://github.com/bitcoin/bitcoin/blob/master/qa/rpc-tests/zmq_test.py and keep in mind: zmq.ZMQ.recv does block your thread until bitcoind sends a block or tx.

Jonas Schnelli 2016-01-04T12:17:43.630

No answers