Ryan Caskey
Ryan Caskey

Reputation: 607

zeromq broadcast to entire network

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

Answers (3)

John Pearcey
John Pearcey

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

SRC
SRC

Reputation: 435

You may want to do it like this with UDP:

  1. All nodes listen to a fixed UDP port for newcomers
  2. When a new node comes up it sends a UDP message to the network (or broadcast if available) and all others get it thus knowing its presence
  3. You can now use fixed endpoints i.e. zmq to take the communication forward.

There is a C example you may want to look at https://github.com/stanwu/udp-broadcast

  • If you have three machines with IP 192.168.1.10/11/12
  • On 192.168.1.10 and 192.168.1.11 start ./udpServer
  • On 192.168.1.12 run ./udpClient 192.168.1.0 I-AM-HERE-192.168.1.12-PORT-7777
  • Now 192.168.1.10/11 knows there is a newcomer on 192.168.1.12 running some listener on 7777

Upvotes: 1

g19fanatic
g19fanatic

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

Related Questions