1

I'm trying to use ZeroMQ but I don't seem to be able push any messages to try anything else.

My producer is

import time, json, zmq

def producer():
    context = zmq.Context.instance()
    zmq_socket = context.socket(zmq.PUSH)
    zmq_socket.bind("tcp://*:9555")
    # Start your result manager and workers before you start your producers
    for num in xrange(200):
        work_message = { 'num' : num }
        print work_message
        zmq_socket.send(json.dumps(work_message))

producer()

All I get is the message of the first print and then just waiting.

Freek Wiekmeijer
  • 4,556
  • 30
  • 37
Dorin Rusu
  • 1,095
  • 2
  • 13
  • 26

1 Answers1

2

You have no listener on the other side, and socket.send() is a blocking method on PUSH sockets.

You need to start your consumer and check if everything starts working.

Here is the documentation: https://zeromq.github.io/pyzmq/api/zmq.html#zmq.Socket.send

As a side note: The waiting queues are created when the PULL side connects, so the NOBLOCK flag will be of no use in this case.

Check this question for more info about the flag: zmq send with NOBLOCK raise Resource temporarily unavailable

Community
  • 1
  • 1
Eloims
  • 5,106
  • 4
  • 25
  • 41
  • Ok I think I'm starting to understand. Coming from RabbitMQ it takes a while to get how ZeroMQ works – Dorin Rusu Aug 10 '15 at 13:31
  • Always remember: ZeroMQ is NOT a message queue, it's sockets on steroids! You will need to implement most messaging patterns yourself (even basic req/rep is unsafe to use "as-is") – Eloims Aug 10 '15 at 13:32