Is there a way to change the binding to zmq pub / sub?

I have server code on one field that needs to be listened to in a state coming from another block, with about 10 tokens with linux embedded in them. The 10 chips have their own IP addresses, and each will send a health status to the server that could (possibly) do something with it.

I would like the server to just listen passively and not have to send a response. So this looks like a job for zmq pub / sub. Where each of the 10 chips has its own publication and the server will subscribe to each one.

However, the server needs to know the known address to which each chip bound its publication. But in the field, these chips can be swapped out or replaced with a different IP address.

Instead, it is safer to know that the chips know the server's ip adddress code.

What I would like is a pub / sub where the recipient is a known address. Or a request / response pattern where clients (chips) send messages to the server (requests), but neither the server nor the chips should send / receive a response.

Now there are currently two servers in a separate window. So if possible, I would like to get a solution for one server and multiple servers.

Is this possible in zmq? And what is the template?

thank.

+3


source to share


2 answers


Yes, you can do it exactly as you expected. Just link to your subscriber, then connect to that subscriber with your publishers. ZMQ does not specify which end should be a "server" or more reliable end, and it is for this reason that it should be a "client" or more transitory end, and this is a great reason to switch the normal paradigm.

Edit to answer the new clarification -



It should work fine with multiple servers. In general, this will work as follows (the order of operations in this case is not to lose messages, which is possible if the socket PUB

starts sending messages before it is ready SUB

):

  • Twist server 1. Create a socket SUB

    and bind it at: port.
  • Twist the server 2. Create a socket SUB

    and bind it at: port.
  • Unscrew the chip. This chip will create a socket PUB

    and connect to [server 1]: port and connect to [server 2] address: port.
  • Repeat step (3) for the remaining nine chips.
+2


source


Dual model .SUB

Oh yes, each .PUB

-style object can have multiple .SUB

-s listeners, so having two <serverNode> -s matches the .PUB/.SUB

-primitive format of a formal relationship (one says - many listen)

As stated above each of your <serverNode> links

.bind( aFixServer{A|B}_ipAddress_portNumber )

so that every .PUB

-lishing <chipNode> is



.connect( anAprioriKnownServer{A|B}_bindingNode_ipAddress_portNumber )

And both <serverNode {A | B}> than .SUB

-s to receive any messages from them.

Multi-server model

As seen above, the grammar is freely extensible to , so the basic messaging model will support any reasonable multi-server extension{

A

|

B

}

{A|B|C|D|...}

QED

+1


source







All Articles