This Python program works for me, using the same data as the XML Exchange example in the Python examples directory.

Make sure you create an instance of the XML exchange with qpid-config first:

$ ./qpid-config add exchange xml xml

Jonathan



import sys
from qpid.messaging import *

broker =  "localhost:5672"
query = """
   let $w := ./weather
   return $w/station = 'Raleigh-Durham International Airport (KRDU)'
      and $w/temperature_f > 50
      and $w/temperature_f - $w/dewpoint > 5
      and $w/wind_speed_mph > 7
      and $w/wind_speed_mph < 20
"""

address = "subscription; {create: always, delete:always, link: { x-bindings: [{ exchange: xml, queue: subscription, key: xml, arguments: { xquery: %r} }] } }" % query


connection = Connection(broker)

try:
  connection.open()
  session = connection.session()

  sender = session.sender(address)
  receiver = session.receiver(address)

sender.send(Message("<weather><station>Raleigh-Durham International Airport (KRDU)</station><wind_speed_mph>16</wind_speed_mph><temperature_f>70</temperature_f><dewpoint>35</dewpoint></weather>"));

  message = receiver.fetch(timeout=1)
  print message.content
  session.acknowledge()

except MessagingError,m:
  print m
finally:
  connection.close()

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to