6

This seems to be incredibly easy but I can't wrap my head around it.

I'm trying to subscribe to daemon's ZMQ events yet I don't receive any. The port is open and accessible in LAN.

const zmq = require("zeromq")

async function run() {
  const sock = new zmq.Subscriber

  sock.connect("tcp://192.168.1.8:18082")
  sock.subscribe("json-full")
  console.log("Subscriber connected")

  for await (const [topic, msg] of sock) {
    console.log("received a message related to:", topic, "containing message:", msg)
  }
}

run()

What am I missing?

0

1 Answer 1

7

ZeroMQ uses different types of sockets for request/response messages and publisher/subscriber messages.

The one you are trying to use, enabled by default on port 18082, is of type RESP, and can only be used for request/response. To use pub/sub, you need a separate socket of type PUB. This isn't enabled by default, but can be easily enabled by passing the --zmq-pub argument to monerod. For example, monerod --zmq-pub ipc://var/run/monerod.pub to use a local socket, or monerod --zmq-pub tcp://localhost:18085 to use a TCP socket.

Then simply use the same URI in your JavaScript client, and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.