[zeromq-dev] amqp client mode from C

Martin Sustrik sustrik at fastmq.com
Tue Jun 16 15:15:31 CEST 2009


Hi Michael,

> thanks for your swift reply.
> 
>  > If you don't mind working with branches of both RabbitMQ and 0MQ, let 
> us know and let's give it a try.
> 
> I don't mind working with branches, but working with unstable branches 
> from two different projects would just mean too much uncertainty. 
> Although I like the sound of that dj branch.
> 
> Within zmq, however, I tried running a simple test using global scope 
> and it fails -- am I using the C API in the right way?
> (fails here means the bye program never receives/prints any messages) -- 
> I am using the 0.6.1 zmq release

Few minor changes are needed.

zmq_server is actually a directory service that maps symbolic names to 
IP addresses. Your config file let's the zmq_server know where are the 
individual endpoints located. You've specified it correctly:

<root>
    <node name = "rabbit_E" location = "amqp://localhost:5672"/>
    <node name = "rabbit_Q" location = "amqp://localhost:5672"/>
</root>

Once that's done, you can send messages to the AMQP server this way:

Sender:

eid = zmq_create_exchange (object, "E", ZMQ_SCOPE_LOCAL, "", 
ZMQ_STYLE_DATA_DISTRIBUTION);
zmq_bind (object, "E", "rabbit_Q", NULL, "MyQueue");
... send a message ...

Receiver:

qid = zmq_create_queue (object, "Q", ZMQ_SCOPE_GLOBAL, "", ZMQ_NO_LIMIT, 
ZMQ_NO_LIMIT, ZMQ_NO_SWAP);
zmq_bind (object, "rabbit_E", "Q", "MyQueue", NULL);
... receive a message ...

Note following points:

1. Your client's objects are defined with ZMQ_SCOPE_LOCAL. Nobody is 
going to bind to the from outside, so there's no need to declare them as 
global.

2. When binding to global exchange/queue you have to specify the name of 
AMQP queue ("MyQueue"). The goal is to be able to access multiple queues 
  with a single endpoint specified in the config file, however, it's 
possible to use "rabbit_Q", if no queue is explicitly specified - it's a 
trivial patch so just shout if that's what you want.

Martin



More information about the zeromq-dev mailing list