Last active
October 7, 2015 17:28
-
-
Save abargnesi/f7e028295a3df3ef6888 to your computer and use it in GitHub Desktop.
Greenline Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [[rail]] | |
| name = "broadcast" | |
| pattern = "pub/sub" | |
| ingress = 5000 | |
| egress = 6000 | |
| [[rail]] | |
| name = "conversation" | |
| pattern = "req/rep" | |
| ingress = 7000 | |
| egress = 8000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from zmq import Context, PUB | |
| from zmq.log.handlers import PUBHandler | |
| import time | |
| # setup | |
| ctx = Context() | |
| pub_sock = ctx.socket(PUB) | |
| # publisg msg to channel | |
| pub_sock.connect('tcp://localhost:5000') | |
| pub_sock.send_multipart([b'', b'Hello']) | |
| time.sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from zmq import Context, SUB, SUBSCRIBE | |
| ctx = Context() | |
| s = ctx.socket(SUB) | |
| s.connect('tcp://localhost:6000') | |
| s.setsockopt(SUBSCRIBE, b'') | |
| topic, msg = s.recv_multipart() | |
| print("on topic: %s, %s" % (topic, msg)) |
Author
Blocking and non-blocking variants of subscriber:
#!/usr/bin/env python
import os
import zmq
from contextlib import suppress
ctxt = zmq.Context()
s = ctxt.socket(zmq.SUB)
s.connect('tcp://localhost:6000')
s.setsockopt(zmq.SUBSCRIBE, b'')
print(os.getpid())
def blocking_recv():
topic, msg = s.recv_multipart()
return topic, msg
def nonblocking_recv():
iters = 0
while True:
iters += 1
with suppress(zmq.error.Again):
topic, msg = s.recv_multipart(zmq.NOBLOCK)
break
print('%d iterations before receipt' % (iters))
return topic, msg
while True:
print(nonblocking_recv())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The publisher's send does not appear in the greenline standard out log nor does the subscriber receive a message. However, if I am not running greenline and allow publish.py to bind then it works.