You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Gregory Bayard <gr...@gmail.com> on 2011/02/11 17:37:06 UTC

Sending a message to a custom QPID direct exchange from Python

Hello,
I am using the Apache QPID 0.8 release.  I have a C++ QPID application
using the request/response model which I would like to build a Python
client for.  The C++ listens for a response on a queue called
'masterserver.summary.queue' bound to a custom direct exchange it
declared, 'masterserver.direct'.  A C++ client can send requests
without difficulty, but the requests are not received by the server
went sent from Python.

The order of operations for the C++ server is as follows:
1. Instantiate a class derrived from MessageListener
2. Create a Session and start a SubscriptionManager on it
3. Declare direct exchange 'masterserver.direct'
4. Declare a queue for the session, 'masterserver.summary.queue' as
exclusive with auto delete
5. Bind the 'masterserver.direct' exchange to the
'masterserver.summary.queue' with binding key
'masterserver.summary.queue'
6. Subscribe the SubscriptionManager to the queue

The Python code I'm attempting to use to send a request follows:

import qpid.messaging
connection = qpid.messaging.endpoints.Connection("brokerhost")
connection.open()
session = connection.session()
requestSender =
session.sender("'masterserver.direct'/'masterserver.summary.queue'")
msg = qpid.messaging.message.Message(content="test")
requestSender.send(msg)

The server doesn't receive the request, BUT if I start a C++ server
with a topic exchange it does receive the above request (which
surprised me since I don't think the broker can handle a direct and
topic exchange with the same name).

When I attempt to specify the exchange type as direct as follows I get
an exception "error in options: node-properties: illegal key":

requestSender =
session.sender("'masterserver.direct'/'masterserver.summary.queue';
{create:always, node-properties:{type:topic, x-properties: {type:
direct}}}")

Any ideas on how to send my request to the specified queue on the
direct exchange from Python?

Thanks,
Greg

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Sending a message to a custom QPID direct exchange from Python

Posted by Gregory Bayard <gr...@gmail.com>.
I did a clean install of Python with the 0.8 module and it is working
as expected on both Windows and Linux, so I was clearly
troubleshooting the wrong things.  I previously had the 0.6 version
installed before I added the 0.8 version.  Thanks for your responses
and suggestions!

Greg

On Tue, Feb 15, 2011 at 6:32 AM, Gordon Sim <gs...@redhat.com> wrote:
> On 02/14/2011 09:45 PM, Gregory Bayard wrote:
>>
>> Hi Gordon,
>>
>> I was originally working with 0.6 and the double-quoting was a quick
>> attempt to find some problem with my exchange and queue specification.
>>  When I updated my addressing string for Qpid 0.8, I still get the
>> same result.  The message is picked up by topic listeners listening to
>> the masterserver.summary.queue' topic on the 'masterserver.direct'
>> exchange.  The string, as you specified, is now:
>>
>> "masterserver.direct/masterserver.summary.queue; {create: always,
>> node: {type:topic, x-declare:{type:direct}}}"
>
> To be clear, I don't think you need the "; {create: always, node:
> {type:topic, x-declare:{type:direct}}}" part, that was just as an example of
> the correct syntax.
>
>> Keep in mind this queue will essentially always have been created by
>> the C++ server which is essentially guaranteed to start before any
>> Python clients.  I just can't figure out anyway to get Python to send
>> messages to the 'masterserver.summary.queue' on the
>> 'masterserver.direct' exchange.
>
> Just to be clear, are you saying that creating a sender in python for the
> address "masterserver.direct/masterserver.summary.queue" and then sending a
> message with that, the messages do not get to the queue in question?
>
> That works fine for me, are you sure you don't have older python libs on
> your path?
>
>> However, I have no problem sending
>> messages to the 'amq.direct' direct exchange from Python.  This issue
>> seems to be limited to custom direct exchanges.  Any suggestions on
>> how I could get a message via the custom direct exchange created by
>> the C++ from Python to the C++ server's queue would be greatly
>> appreciated.
>
> Are you getting errors or the messages just appear to be dropped? As I say
> it works fine for me with 0.8 packages. See attached client and server. The
> server is a modified version of the old example that I think matches what
> you describe, the client is a simple python program that sends to
> "masterserver.direct/masterserver.summary.queue". Start the server first,
> then run the client and that all works for me, does it work for you?
>
> Btw, there is a messaging API in c++ as well that I think is a lot simpler
> than the old qpid/client API. It is conceptually similar to the python API
> you are using.
>
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Sending a message to a custom QPID direct exchange from Python

Posted by Gordon Sim <gs...@redhat.com>.
On 02/14/2011 09:45 PM, Gregory Bayard wrote:
> Hi Gordon,
>
> I was originally working with 0.6 and the double-quoting was a quick
> attempt to find some problem with my exchange and queue specification.
>   When I updated my addressing string for Qpid 0.8, I still get the
> same result.  The message is picked up by topic listeners listening to
> the masterserver.summary.queue' topic on the 'masterserver.direct'
> exchange.  The string, as you specified, is now:
>
> "masterserver.direct/masterserver.summary.queue; {create: always,
> node: {type:topic, x-declare:{type:direct}}}"

To be clear, I don't think you need the "; {create: always, node: 
{type:topic, x-declare:{type:direct}}}" part, that was just as an 
example of the correct syntax.

> Keep in mind this queue will essentially always have been created by
> the C++ server which is essentially guaranteed to start before any
> Python clients.  I just can't figure out anyway to get Python to send
> messages to the 'masterserver.summary.queue' on the
> 'masterserver.direct' exchange.

Just to be clear, are you saying that creating a sender in python for 
the address "masterserver.direct/masterserver.summary.queue" and then 
sending a message with that, the messages do not get to the queue in 
question?

That works fine for me, are you sure you don't have older python libs on 
your path?

> However, I have no problem sending
> messages to the 'amq.direct' direct exchange from Python.  This issue
> seems to be limited to custom direct exchanges.  Any suggestions on
> how I could get a message via the custom direct exchange created by
> the C++ from Python to the C++ server's queue would be greatly
> appreciated.

Are you getting errors or the messages just appear to be dropped? As I 
say it works fine for me with 0.8 packages. See attached client and 
server. The server is a modified version of the old example that I think 
matches what you describe, the client is a simple python program that 
sends to "masterserver.direct/masterserver.summary.queue". Start the 
server first, then run the client and that all works for me, does it 
work for you?

Btw, there is a messaging API in c++ as well that I think is a lot 
simpler than the old qpid/client API. It is conceptually similar to the 
python API you are using.

Re: Sending a message to a custom QPID direct exchange from Python

Posted by Alan Conway <ac...@redhat.com>.
On 02/14/2011 04:45 PM, Gregory Bayard wrote:
> Hi Gordon,
>
> I was originally working with 0.6 and the double-quoting was a quick
> attempt to find some problem with my exchange and queue specification.
>   When I updated my addressing string for Qpid 0.8, I still get the
> same result.  The message is picked up by topic listeners listening to
> the masterserver.summary.queue' topic on the 'masterserver.direct'
> exchange.  The string, as you specified, is now:
>
> "masterserver.direct/masterserver.summary.queue; {create: always,
> node: {type:topic, x-declare:{type:direct}}}"
>

I think you may be missing the "bind" step where your exchange is bound to your 
queue. This works for me on trunk, should work on 0.8 also:


#!/bin/env python 

from qpid.messaging import *

c = Connection("localhost")
c.open()
s = c.session()
send = s.sender("foo.direct/foo.key; {create:always,node:{type:topic, 
x-declare:{type:di\
rect}}}")
recv = s.receiver("foo.queue;{create:always, 
node:{x-bindings:[{exchange:'foo.direct',qu\
eue:'foo.queue',key:'foo.key'}]}}")

send.send(Message("hello"))
print recv.fetch()




---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Sending a message to a custom QPID direct exchange from Python

Posted by Gregory Bayard <gr...@gmail.com>.
Hi Gordon,

I was originally working with 0.6 and the double-quoting was a quick
attempt to find some problem with my exchange and queue specification.
 When I updated my addressing string for Qpid 0.8, I still get the
same result.  The message is picked up by topic listeners listening to
the masterserver.summary.queue' topic on the 'masterserver.direct'
exchange.  The string, as you specified, is now:

"masterserver.direct/masterserver.summary.queue; {create: always,
node: {type:topic, x-declare:{type:direct}}}"

Keep in mind this queue will essentially always have been created by
the C++ server which is essentially guaranteed to start before any
Python clients.  I just can't figure out anyway to get Python to send
messages to the 'masterserver.summary.queue' on the
'masterserver.direct' exchange.  However, I have no problem sending
messages to the 'amq.direct' direct exchange from Python.  This issue
seems to be limited to custom direct exchanges.  Any suggestions on
how I could get a message via the custom direct exchange created by
the C++ from Python to the C++ server's queue would be greatly
appreciated.

Thanks,
Greg

On Mon, Feb 14, 2011 at 12:53 PM, Gordon Sim <gs...@redhat.com> wrote:
> On 02/11/2011 04:37 PM, Gregory Bayard wrote:
>>
>> Hello,
>> I am using the Apache QPID 0.8 release.  I have a C++ QPID application
>> using the request/response model which I would like to build a Python
>> client for.  The C++ listens for a response on a queue called
>> 'masterserver.summary.queue' bound to a custom direct exchange it
>> declared, 'masterserver.direct'.  A C++ client can send requests
>> without difficulty, but the requests are not received by the server
>> went sent from Python.
>>
>> The order of operations for the C++ server is as follows:
>> 1. Instantiate a class derrived from MessageListener
>> 2. Create a Session and start a SubscriptionManager on it
>> 3. Declare direct exchange 'masterserver.direct'
>> 4. Declare a queue for the session, 'masterserver.summary.queue' as
>> exclusive with auto delete
>> 5. Bind the 'masterserver.direct' exchange to the
>> 'masterserver.summary.queue' with binding key
>> 'masterserver.summary.queue'
>> 6. Subscribe the SubscriptionManager to the queue
>>
>> The Python code I'm attempting to use to send a request follows:
>>
>> import qpid.messaging
>> connection = qpid.messaging.endpoints.Connection("brokerhost")
>> connection.open()
>> session = connection.session()
>> requestSender =
>> session.sender("'masterserver.direct'/'masterserver.summary.queue'")
>
> Is the double quoting intentional? Why not just:
>
>  session.sender("masterserver.direct/masterserver.summary.queue")
>
>> msg = qpid.messaging.message.Message(content="test")
>> requestSender.send(msg)
>>
>> The server doesn't receive the request, BUT if I start a C++ server
>> with a topic exchange it does receive the above request (which
>> surprised me since I don't think the broker can handle a direct and
>> topic exchange with the same name).
>>
>> When I attempt to specify the exchange type as direct as follows I get
>> an exception "error in options: node-properties: illegal key":
>>
>> requestSender =
>> session.sender("'masterserver.direct'/'masterserver.summary.queue';
>> {create:always, node-properties:{type:topic, x-properties: {type:
>> direct}}}")
>
> There is no longer a node-properties option. Was this code you originally
> wrote against 0.6? The addressing was changed for 0.8 (should now be more
> stable).
>
> To have the exchange created on demand you would do:
>
>  "masterserver.direct/masterserver.summary.queue; {create: always, node:
> {type:topic, x-declare:{type:direct}}}"
>
> However I wouldn't recommend that as it tends to only add to the confusion.
>
>> Any ideas on how to send my request to the specified queue on the
>> direct exchange from Python?
>>
>> Thanks,
>> Greg
>>
>> ---------------------------------------------------------------------
>> Apache Qpid - AMQP Messaging Implementation
>> Project:      http://qpid.apache.org
>> Use/Interact: mailto:users-subscribe@qpid.apache.org
>>
>
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Sending a message to a custom QPID direct exchange from Python

Posted by Gordon Sim <gs...@redhat.com>.
On 02/11/2011 04:37 PM, Gregory Bayard wrote:
> Hello,
> I am using the Apache QPID 0.8 release.  I have a C++ QPID application
> using the request/response model which I would like to build a Python
> client for.  The C++ listens for a response on a queue called
> 'masterserver.summary.queue' bound to a custom direct exchange it
> declared, 'masterserver.direct'.  A C++ client can send requests
> without difficulty, but the requests are not received by the server
> went sent from Python.
>
> The order of operations for the C++ server is as follows:
> 1. Instantiate a class derrived from MessageListener
> 2. Create a Session and start a SubscriptionManager on it
> 3. Declare direct exchange 'masterserver.direct'
> 4. Declare a queue for the session, 'masterserver.summary.queue' as
> exclusive with auto delete
> 5. Bind the 'masterserver.direct' exchange to the
> 'masterserver.summary.queue' with binding key
> 'masterserver.summary.queue'
> 6. Subscribe the SubscriptionManager to the queue
>
> The Python code I'm attempting to use to send a request follows:
>
> import qpid.messaging
> connection = qpid.messaging.endpoints.Connection("brokerhost")
> connection.open()
> session = connection.session()
> requestSender =
> session.sender("'masterserver.direct'/'masterserver.summary.queue'")

Is the double quoting intentional? Why not just:

   session.sender("masterserver.direct/masterserver.summary.queue")

> msg = qpid.messaging.message.Message(content="test")
> requestSender.send(msg)
>
> The server doesn't receive the request, BUT if I start a C++ server
> with a topic exchange it does receive the above request (which
> surprised me since I don't think the broker can handle a direct and
> topic exchange with the same name).
>
> When I attempt to specify the exchange type as direct as follows I get
> an exception "error in options: node-properties: illegal key":
>
> requestSender =
> session.sender("'masterserver.direct'/'masterserver.summary.queue';
> {create:always, node-properties:{type:topic, x-properties: {type:
> direct}}}")

There is no longer a node-properties option. Was this code you 
originally wrote against 0.6? The addressing was changed for 0.8 (should 
now be more stable).

To have the exchange created on demand you would do:

   "masterserver.direct/masterserver.summary.queue; {create: always, 
node: {type:topic, x-declare:{type:direct}}}"

However I wouldn't recommend that as it tends to only add to the confusion.

> Any ideas on how to send my request to the specified queue on the
> direct exchange from Python?
>
> Thanks,
> Greg
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org