Seeing as there's no talks this week, I can procrastinate a tad bit
more on my presentation. However, I just wanted to show these two
samples of code, which don't use stomp and which I am pretty sure was
working on my machine (WOMM(tm)).
cahoon.py:
import amqplib.client_0_8 as amqp
connection = amqp.Connection()
channel = amqp.channel.Channel(connection)
try:
channel.exchange_declare('rory.topic', 'topic', passive=True)
except amqp.AMQPChannelException:
print "Declating exchange"
channel = amqp.channel.Channel(connection)
channel.exchange_declare('rory.topic', 'topic', auto_delete=False)
channel.basic_publish(
amqp.basic_message.Message("{'rory': 'cool'}"),
exchange='rory.topic'
)
calvillo.py:
import amqplib.client_0_8 as amqp
connection = amqp.Connection()
channel = amqp.channel.Channel(connection)
channel.basic_publish(
amqp.basic_message.Message("Billy Mays Here"),
exchange='rory.topic'
)
I had this working with a rabbitmq server running on the same machine.
For the record, rabbitmq is pretty easy to get up and running once
you've installed erlang.
--Rory Geoghegan
On Fri, Jun 12, 2009 at 5:31 PM, <[email protected]> wrote:
>
> With a little more experimentation, creating a new exchange is not
> neccessary, they key part is to create a new queue for each reciever,
> heres the same effect using a routing key and just one exchange.
>
> Sending.
>
> conn.send(str(i), exchange="myexchange", destination='users.'+ user)
>
>
> Recieving
>
>
> import stomp
> from amqplib import client_0_8 as amqp
> import sys
>
>
> conn = amqp.Connection(host="localhost:5672", userid="guest",
> password="guest",
> virtual_host="/", insist=False)
>
>
> user = sys.argv[1]
> chan = conn.channel()
>
> chan.exchange_declare("myexchange", 'topic', durable=True)
> qname,_,_ = chan.queue_declare(auto_delete=True, durable=True)
> chan.queue_bind(qname, exchange="myexchange", routing_key="users." + user)
> chan.close()
> conn.close()
>
> class MyListener(object):
> def on_error(self, headers, message):
> print 'recieved an error %s' % message
>
> def on_message(self, headers, message):
> print 'recieved a message %s' % message
>
> conn = stomp.Connection([('0.0.0.0', 61613), ('127.0.0.1', 61613)],
> 'browser', 'browser')
> conn.set_listener('', MyListener())
> conn.start()
> conn.connect(username="guest", password="guest")
> headers = {}
>
> conn.subscribe(destination=qname, ack='auto')
>
> while True:
> pass
> conn.disconnect()
>
>
>
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---