Created
March 24, 2014 09:21
-
-
Save flyer103/9737000 to your computer and use it in GitHub Desktop.
sender-->worker-->collector 形式,本例是 sender
This file contains 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 | |
# -*- coding: utf-8 -*- | |
"""sender-->worker-->collector 形式,本例是 sender | |
""" | |
import time | |
import random | |
import zmq | |
class TaskSender(object): | |
"""向 workder 发送任务""" | |
def __init__(self): | |
self.ctx = zmq.Context() | |
random.seed() | |
def run(self): | |
task_snd = self.ctx.socket(zmq.PUSH) | |
task_snd.bind('tcp://*:53000') | |
while True: | |
workload = str(random.randint(1, 100)) | |
task_snd.send(workload.encode('utf-8')) | |
print('Send task: {0}'.format(workload)) | |
time.sleep(random.randint(1, 3)) | |
if __name__ == '__main__': | |
task_sender = TaskSender() | |
task_sender.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment