Simple example writing to the Qpid Java broker with Qpid Proton not working

4k views Asked by At

I'm new to AMQP and am trying to write a simple application that writes to the Qpid Java Broker with the Qpid Proton Messenger API. Out of the box the Qpid Java broker has four default exchanges (amq.match, amq.fanout, amq.topic, amq.direct), an AMQP "port" on port 5672 with a passwordFile auth povider. To take security out of the picture for this test I changed the auth provider to Anonymous.

For writing to the broker I am following this example. The example does not show how to write to a particular exchange or queue and I think my problem is somewhere in that domain. Here is my slimmed down version.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <Windows.h>
#include "proton\message.h"
#include "proton\messenger.h"

int main(int argc, const char* argv[])
{
    while (true)
    {
        pn_message_t * message;
        pn_messenger_t * messenger;
        pn_data_t * body;

        message = pn_message();
        messenger = pn_messenger(NULL);

        pn_messenger_start(messenger);

        printf("set address result: %i\n", pn_message_set_address(message, "amqp://xxx.xxx.xxx.xxx:5672"));

        body = pn_message_body(message);

        char* msgtext = "howdy";
        pn_data_put_string(body, pn_bytes(strlen(msgtext), msgtext));
        pn_messenger_put(messenger, message);

        printf("\nSent: %i\n", pn_messenger_send(messenger, 1));

        pn_messenger_stop(messenger);
        pn_messenger_free(messenger);
        pn_message_free(message);

        Sleep(10);
    }
}

pn_messenger_send returns 0 (success). From the client machine I can see that the client is sending the messages over the wire. However in the broker management portal it shows zero client connections and the default virtual host shows 0 msg/s (0.00 B/s) inbound. I would expect this to show the bytes coming in from my test client. If I run the client with the broker down or point it to the wrong port the client will fail on the pn_messenger_send call so I know I am at least talking to the broker.

My question is where are these messages going? How do I define the exchange type and queue in my connection string for the message? I've searched and searched and haven't found anything. Any links to documentation or tutorials that I may have missed are welcome.

Here are some broker configuration screenshots for reference.

enter image description here

enter image description here

Thanks!

1

There are 1 answers

0
RaGe On BEST ANSWER

If you are attempting to send messages to a specific queue, your address needs to be of the form:

amqp://host:port/test-queue-1

You can also send a message to an exchange:

amqp://host:port/test-exchange-1

In your case, you're sending your messages without a destination specified in the address. So the messages go to the default direct exchange. All queues are bound to the default direct, with the queue name as the binding key. But you are not setting a routing-key on your messages either. They're likely being discarded as un-routable - I don't remember if qpid has a dead-letter-queue implementation.

EDIT: Unrouteable messages could be discarded

In order to specify a routing-key on your message use:

pn_message_set_subject(message, "my-routing-key");

If you have a custom exchange and queue setup in mind, you have to predefine the exchange and queue-bindings to ensure the messages are routed correctly. I imagine c-bindings exist to define and configure exchanges programmatically, but I am not familiar with it.

You can create exchanges, queues and bindings using the qpid-config command on the commandline, or REST API through the webadmin app for example:

Create a durable queue using qpid-config:

qpid-config add queue test-queue-1 --durable 

or the REST API

#create a durable queue
curl -X PUT  -d '{"durable":true}' http://localhost:8080/rest/queue/<vhostname>/test-queue-1

Creating an exchange

qpid-config add exchange direct test-exchange-1 --durable

Creating a binding between queue and exchange:

qpid-config bind test-exchange-1 test-queue-1 test-queue-binding-key

Any message you send to the exchange with routing key test-queue-binding-key will eventually end up in test-queue-1.

ref: qpid-config
ref: REST API