[zeromq-dev] amqp client mode from C

Michael Nacos m.nacos at gmail.com
Tue Jun 16 12:31:29 CEST 2009


according to the docs, there should be a way of connecting from zmq to
an AMQP broker. I've been trying to achieve this using the zmq C API
and things work fine, except that the AMQP broker, in this case
RabbitMQ, is not used in the process
(my message gets delivered whether RabbitMQ is running or not)
zmq_server listens on its default 5682 port and the rabbit broker
listens on 5672

am I doing something wrong (except trying to use something besides
zmq, as well :-)

this is what I have got in the zmq_server config file:

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

and this is my C test code:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "zmq.h"

int main() {

    void *object;
    void *message;
    uint64_t message_size;
    int eid;
    int qid;

    /* Initialise 0MQ infrastructure. */

    object = zmq_create("localhost:5682");
    eid = zmq_create_exchange (object, "rabbit_E", ZMQ_SCOPE_GLOBAL,
    qid = zmq_create_queue (object, "rabbit_Q", ZMQ_SCOPE_GLOBAL,
    zmq_bind (object, "rabbit_E", "rabbit_Q", NULL, NULL);

    /* Send a message. */
    message_size = strlen("This is a test");
    message = malloc (message_size + 1);
    strcpy(message, "This is a test");
    zmq_send (object, eid, message, message_size, ZMQ_TRUE);
    free (message);

    /* Receive a message */
    zmq_receive (object, &message, &message_size, NULL, ZMQ_TRUE);
    printf("%s\n", message);
    zmq_free (message);

    return 1;

More information about the zeromq-dev mailing list