Search code examples
capacheqpid

about qpid exchange,queue


every one:
i am new to qpid and encounter some problem. the exchange created by me can’t route message to the queue, as follows:
first i create a durbale queue “test-queue-1” in the qpid use the quid-config command:

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

next i create a durable direct exchange “test-exchange-1" in the qpid also use the qpid-config command:

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

the last, in bind them as follow command:

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

everything seems ok in the qpid-tool:

Object Summary:
ID   Created   Destroyed  Index
========================================================================================
128  12:28:28  -          org.apache.qpid.broker:queue:qmfc-v2-hb-iZ23c6sri0pZ.12680.1
129  12:28:28  -          org.apache.qpid.broker:queue:qmfc-v2-iZ23c6sri0pZ.12680.1
130  12:28:28  -          org.apache.qpid.broker:queue:qmfc-v2-ui-iZ23c6sri0pZ.12680.1
131  12:28:28  -          org.apache.qpid.broker:queue:reply-iZ23c6sri0pZ.12680.1
132  12:24:17  -          org.apache.qpid.broker:queue:test-queue-1
133  12:28:28  -          org.apache.qpid.broker:queue:topic-iZ23c6sri0pZ.12680.1  
116  12:27:20  -   

and

org.apache.qpid.broker:binding:org.apache.qpid.broker:exchange:test-exchange-1,org.apache.qpid.broker:queue:test-queue-1,test-queue-1  

now i am ready to test them, start the recv/send demo program:

[devel@iZ23c6sri0pZ build]$ ./recv amqp://127.0.0.1/test-queue-1

send the message:

[devel@iZ23c6sri0pZ build]$ ./send -a amqp://127.0.0.1/test-exchange-1 hi,everyone

but the "recv program” can’t recv any message.
if i send message like this :

[devel@iZ23c6sri0pZ build]$ ./send -a amqp://127.0.0.1/test-queue-1 hi,everyone

the “recv program” can recv the message:

Address: amqp://127.0.0.1/test-queue-1
Subject: Hello Subject
Content: "hi,everyone"

who can tell me why?i read the amqp protocol, maybe the routing-key in the message don’t match the binding-key, but if this, how could i set the routing-key? my recv/send writed by proton-c , version 0.8. qpidd is 0.32 version.


Solution

  • When you send a message to a qpid direct exchange, it gets routed to a bound queue based on the routing-key of the message. In proton-c you can set the routing key by setting the message-subject using the function

    PN_EXTERN int pn_message_set_subject (pn_message_t* msg,const char* subject)
    

    Unfortunately this is not implemented in the example send.c that is shipped with proton-c v0.8 You can insert the following line somewhere around here and rebuild your send executable

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

    You can also with some effort, add a new command-line option to accept and use a routing-key from ./send

    The java example implements a -s option to set the message subject.