[zeromq-dev] amqp client mode from C

Michael Nacos m.nacos at gmail.com
Tue Jun 16 14:24:36 CEST 2009


Dear Martin,

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

hello.c
----------------------------------------------------------------------------------------------------------------------
#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, "E", ZMQ_SCOPE_GLOBAL, "lo",
ZMQ_STYLE_DATA_DISTRIBUTION);
qid = zmq_create_queue (object, "Q", ZMQ_SCOPE_GLOBAL, "lo", ZMQ_NO_LIMIT,
ZMQ_NO_LIMIT, ZMQ_NO_SWAP);
zmq_bind (object, "E", "Q", NULL, NULL);

/* Send a message. */

message_size = strlen("This is a test") + 1;
message = malloc (message_size);
strcpy(message, "This is a test");

zmq_send (object, eid, message, message_size, ZMQ_TRUE);
free (message);

zmq_destroy(object);

return 0;

}
----------------------------------------------------------------------------------------------------------------------

bye.c
----------------------------------------------------------------------------------------------------------------------
#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, "E", ZMQ_SCOPE_GLOBAL, "lo",
ZMQ_STYLE_DATA_DISTRIBUTION);
qid = zmq_create_queue (object, "Q", ZMQ_SCOPE_GLOBAL, "lo", ZMQ_NO_LIMIT,
ZMQ_NO_LIMIT, ZMQ_NO_SWAP);
zmq_bind (object, "E", "Q", NULL, NULL);

/* Receive a message */
zmq_receive (object, &message, &message_size, NULL, ZMQ_TRUE);

if (message_size > 0) {
    printf("%s\n", message);
    zmq_free (message);
}

zmq_destroy(object);

return 0;

}
----------------------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20090616/b41f5b30/attachment.htm>


More information about the zeromq-dev mailing list