Reputation: 607
I'm new to ZeroMQ, (and programming with sockets in general), but am trying to implement (in Java) a peer-to-peer model in ZeroMQ. What I would like is for when a node comes on-line, it broadcasts to the entire network an "I'm here, and you can reach me at this address:..." message.
I'm thinking that if 2 or more nodes appear on the network, they would be able to find each other without having to go through a known endpoint.
Does anyone have any ideas on how I could achieve this? Is this even possible with ZeroMQ?
Upvotes: 5
Views: 4520
Reputation: 1
I use UDP for this in an existing system on a LAN. It works well. The only problems you must watch are that UDP packets are not guaranteed delivery. They will actually get lost so you need to factor in a repeat broadcasts. You also get packet fragmentation, so make sure that messages are small but you only have to send enough information to establish a connection for ZMQ, or TCP or RabbitMQ
or anything else. Other potential issues are firewalls and VPNs.
Upvotes: 0
Reputation: 435
You may want to do it like this with UDP:
There is a C example you may want to look at https://github.com/stanwu/udp-broadcast
Upvotes: 1
Reputation: 10941
What you're asking for cannot be done with zmq. There is no mechanism (without a known and defined endpoint) that allows you to 'know' when a publisher comes online and its messages are ready for subscribing to.
That being said, it is quite trivial to set something of this sort up using a XPub and XSub router(which requires a known endpoint). You can also create your own 'endpoint' that all clients connect to using a REQ/REP socket. This will allow you to have a central (essentially a directory service) that you can then connect point to point subscribe/publish connections (which will keep your network duplication at its lowest).
Upvotes: 4