Skip to content

Commit

Permalink
Add example for zmq streams
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Feb 14, 2015
1 parent c878bb6 commit eaf44ba
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/stream_dealer_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import asyncio
import aiozmq
import zmq


@asyncio.coroutine
def go():
router = yield from aiozmq.create_zmq_stream(
zmq.ROUTER,
bind='tcp://127.0.0.1:*')

addr = list(router.transport.bindings())[0]
dealer = yield from aiozmq.create_zmq_stream(
zmq.DEALER,
connect=addr)

for i in range(10):
msg = (b'data', b'ask', str(i).encode('utf-8'))
dealer.write(msg)
data = yield from router.read()
router.write(data)
answer = yield from dealer.read()
print(answer)
dealer.close()
router.close()


def main():
asyncio.get_event_loop().run_until_complete(go())
print("DONE")


if __name__ == '__main__':
main()

0 comments on commit eaf44ba

Please sign in to comment.