[zeromq-dev] How could I set hwm in the push/pull pattern of zmq?

flyer flyer103 at gmail.com
Thu Mar 27 07:56:58 CET 2014


I have found a similar question, ZeroMQ: HWM on PUSH does not
work<http://stackoverflow.com/questions/21133535/zeromq-hwm-on-push-does-not-work>,
but it couldn't solve my problem.

I want to control the number of messages that the push socket queues, but
it doesn't work.
So I want to know how to set the hwm of the push socket. Thanks in advance.

My environment is: libzmq 4.0.4, pyzmq 14.1.0, python 3.3

Here's my code:

server.py

> #!/usr/bin/env python3# -*- coding: utf-8 -*-
> import random
> import zmq
>
> class TestPush(object):
>
>     def __init__(self):
>         self.ctx = zmq.Context()
>
>         random.seed()
>
>     def run(self):
>         task_snd = self.ctx.socket(zmq.PUSH)
>         task_snd.setsockopt(zmq.SNDHWM, 10)
>         task_snd.bind('tcp://*:53000')
>
>         while True:
>             workload = str(random.randint(1, 100))
>             task_snd.send(workload.encode('utf-8'))
>             print('Send {0}'.format(workload))
>
> if __name__ == '__main__':
>     test_push = TestPush()
>     test_push.run()
>
> client.py

> #!/usr/bin/env python3# -*- coding: utf-8 -*-
> import timeimport random
> import zmq
>
> class TestPull(object):
>
>     def __init__(self):
>         self.ctx = zmq.Context()
>
>     def run(self):
>         task_rcv = self.ctx.socket(zmq.PULL)
>         task_rcv.setsockopt(zmq.RCVHWM, 1)
>         task_rcv.connect('tcp://localhost:53000')
>
>         while True:
>             msg = task_rcv.recv()
>             print('Receive msg: {0}'.format(msg))
>
>             time.sleep(random.randint(2, 3))
>
> if __name__ == '__main__':
>     test_pull = TestPull()
>     test_pull.run()
>
>
-- 
宠辱不惊,闲看庭前花开花落;去留无意,漫随天边云卷云舒。
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140327/4a7e08c4/attachment.htm>


More information about the zeromq-dev mailing list