Difference between revisions of "Cfengine3 Messaging"

From PostgreSQL_wiki
Jump to: navigation, search
(Synchronous Request/Response)
(Publish/Subscribe)
Line 40: Line 40:
 
== Asynchronous Request/Response ==
 
== Asynchronous Request/Response ==
 
== Publish/Subscribe ==
 
== Publish/Subscribe ==
  +
<pre>
  +
socket = context.socket(zmq.PUB)
  +
socket.bind("tcp://10.68.71.184:8080")
  +
  +
# Wait for next request from client
  +
message = socket.recv()
  +
print("Received request: %s" % message)
  +
  +
# Send reply back to client
  +
socket.send(b"World")
  +
</pre>
  +
 
== Push/Pull ==
 
== Push/Pull ==
 
== Exclusive Pair ==
 
== Exclusive Pair ==

Revision as of 20:27, 6 December 2015

> what would be killer is a combination of the latest cfengine
> (with promise theory) and 0mq.
http://lists.zeromq.org/pipermail/zeromq-dev/2011-February/009491.html

0mq

ZeroMQ comes with 5 basic patterns

  • Synchronous Request/Response
  • Asynchronous Request/Response
  • Publish/Subscribe
  • Push/Pull
  • Exclusive Pair

Synchronous Request/Response

Client Requests

socket = context.socket(zmq.REQ)
socket.connect("tcp://wbhs-pkg.webhuis.nl:8080")

#  Do 10 requests, waiting each time for a response
print("Sending request %s ..." % request)
socket.send(b"Hello")

#  Get the reply.
message = socket.recv()
print("Received reply %s [ %s ]" % (request, message))

Server Replies

socket = context.socket(zmq.REP)
socket.bind("tcp://10.68.71.184:8080")

#  Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)

#  Send reply back to client
socket.send(b"World")

Asynchronous Request/Response

Publish/Subscribe

socket = context.socket(zmq.PUB)
socket.bind("tcp://10.68.71.184:8080")

#  Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)

#  Send reply back to client
socket.send(b"World")

Push/Pull

Exclusive Pair