Jonathan Robie wrote:
I like what I see, I have a bunch of questions.

from qpid.api import *

# open a connection
conn = Connection.open("localhost")
conn.start()


If I start the connection before creating sessions, does that mean each connection starts as soon as it is created?

Assuming you actually mean each *session* starts as soon as it is created, then yes.

# create a session
ssn = conn.session()

# send a message
sender = ssn.sender("my-queue")
sender.send("Hello World!")
# fetch the message
receiver = ssn.receiver("my-queue")
msg = receiver.fetch(0)

print msg

# acknowledge the message
ssn.acknowledge(msg)

How does this work with Topic Exchanges? The XML Exchange?

That parts not fully fleshed out yet. The intention is you'd somehow pass something to ssn.sender that would refer to the exchange, and at the other end you'd pass something to ssn.receiver that would specify the binding, e.g.:

sender = ssn.sender("my-exchange")
receiver = ssn.receiver("my-exchange", filter="...")

Could there be a default timeout for receiverfetch()?

There could be.

# define a listener
def printer(msg):
  print "L: %r" % msg
  ssn.acknowledge(msg)

# register the listener
receiver.listen(printer)

# send a bunch more messages
for content in ["this", "is", "a", "test"]:
  sender.send(content)

# disconnect for a while
conn.stop()
conn.disconnect()

# reconnect and continue doing work
conn.connect()
conn.start()

# unregister the listener
receiver.listen(None)

Can a receiver have only one listener?

Yes

# send more messages
sender.send("Hello Again!")

# drain the queue
while True:
  try:
    msg = receiver.fetch(0)
    print "D: %r" % msg
  except Empty:
    break

# acknowledge all outstanding messages
ssn.acknowledge()
print "done"

# close the connection
conn.close()

How do I set delivery properties? Message properties?

The API doesn't expose a distinction between delivery and message properties. They way you'd set various headerish things is like this:

msg = Message("this is the <b>content</b>")
msg.content_type = "text/html; charset=utf8"
msg.properties["my-custom-property"] = "foo"

sender.send(msg)

If you pass the Sender.send method something that isn't a message, it will assume it is the content and construct the message, for you, e.g. sender.send("content") is equivalent to sender.send(Message("content")). Either one will default the content_type to "text/plain; charset=utf8".

How do I create queues? Bindings?

On the whole this API isn't intended to address creating/configuring internal broker entities, but rather just sending/receiving messages, so I wouldn't expect to see anything for general purpose queue creation/deletion/binding. Obviously there does need to be some indirect queue creating/binding for things like topics and temp queues, but beyond that I would expect people to create their queues via a distinct TBD API, possibly qmf based or something similar. That said, this area does need some more thought.

--Rafael


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

Reply via email to