Just reading the rabbit docs and it turns out (with rabbitmq specifically)
the access_request call is deprecated and does nothing. No need for it.
>
> I finally found a way to get what I want, basically declare an exchange
> per message group, it requires both stomp and amqp, but thats fine by me
>
>
> In the sending code:
>
> conn.send(str(i), exchange=exchange, destination='')
>
> The blank destination is required, all I care about is sending to that
> exchange
>
> To recieve
>
> import stomp
> import sys
> from amqplib import client_0_8 as amqp
> #read in the exchange name so I can set up multiple recievers for
> different exchanges to tset
> exchange = sys.argv[1]
> conn = amqp.Connection(host="localhost:5672", userid="username",
> password="password",
> virtual_host="/", insist=False)
>
> chan = conn.channel()
>
> chan.access_request('/', active=True, write=True, read=True)
>
> #declare my exchange
> chan.exchange_declare(exchange, 'topic')
> #not passing a queue name means I get a new unique one back
> qname,_,_ = chan.queue_declare()
> #bind the queue to the exchange
> chan.queue_bind(qname, exchange=exchange)
>
> 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="username", password="password")
> headers = {}
>
> #subscribe to the queue
> conn.subscribe(destination=qname, ack='auto')
>
> while True:
> pass
> conn.disconnect()
>
>
>
>>
>> A great reference document on using RabbitMQ with python:
>>
>> http://blogs.digitar.com/jjww/2009/01/rabbits-and-warrens/
>>
>> I think the topic is cool enough that it warrants me doing a
>> presentation
>> on it.
>>
>> On Thu, Jun 11, 2009 at 12:36 PM, <[email protected]> wrote:
>>>
>>> Thank you very much
>>>
>>> You are a god amoung men
>>>
>>>>
>>>> Sean O'Donnell asked how to get a broadcast exchange working with
>>>> RabbitMQ, which might be of interest to the community in general.
>>>> Here's how I would do it with py-amqplib with a running RabbitMQ. Now,
>>>> this code works on an older wersion of py-amqplib using version 0.8,
>>>> so if you're using the lastest version, you may have to spend some
>>>> time forward porting this code, but the base principles are the same.
>>>>
>>>> First of all, get a channel into amqp to create your exchange
>>>>
>>>> import amqplib.client_0_8 as amqp
>>>> conn = amqp.Connection(host, userid, password)
>>>> channel = connection.channel()
>>>>
>>>> This is where things get a bit funky. You should only worry about your
>>>> realm if you have a boatload of exchanges and etc. Just use the
>>>> default one ('/') and everything should be hunky-dory. One of the big
>>>> problems with py-amqplib and rabbitmq in general is that it really
>>>> doesn't do defaults well. Also, you have to explicitely set write to
>>>> False and read to True, even if they're (logically) mutually
>>>> exclusive, because of the way the bit protocol in amqp works.
>>>>
>>>> channel.access_request(realm, active=True, write=False, read=True)
>>>> channel.declare_exchange('name.of.exchange', "topic",
>>>> auto_delete=False, durable=True)
>>>>
>>>> Now, on your one or multiple receivers, run the following:
>>>>
>>>> [... create a channel like above right before declaring the exchange]
>>>> queue = channel.queue_declare(exclusive=True)[0] # exclusive means
>>>> nobody else can use this queue, which is good
>>>> channel.queue_bind(queue, 'name.of.exchange', rounting_key="#") #
>>>> The
>>>> '#' rounting key is a catch all. Read up on rounting keys if you want
>>>> something more fancy
>>>> channel.basic_consume(queue,
>>>> fancy_callback_function_that_consumes_your_message) # This starts an
>>>> event loop that will pass every incoming message to your callback
>>>> function
>>>>
>>>> To send a message (or publish, in AMQP speak), run the following:
>>>> [ ... create your channel, much like above, but stop right before you
>>>> do the access request thingy]
>>>> channel.access_request(realm, active=True, write=True, read=False)
>>>> message = amqp.Message( "A string containing your message",
>>>> content_type="text/plain")
>>>> channel.basic_publish(message, exchange="name.of.exchange",
>>>> rounting_key="a.rounting.key")
>>>>
>>>> And, magically, everything should just work(tm) and every client
>>>> should receive the message you just published. There is much too much
>>>> boilerplate for my liking, but, trust me, py-amqplib is actually
>>>> hiding you away from a lot of the details of the protocol (if you can
>>>> believe it). I suspect more modern versions of the library make things
>>>> easier, but the base principles are the same:
>>>>
>>>> * 1 topic exchange
>>>> * bind as many queues to it, each with their own routing key
>>>> * send to the exchange with a routing key
>>>> * receive from the queues
>>>>
>>>> --Rory Geoghegan
>>>>
>>>> >
>>>>
>>>
>>>
>>>
>>> >
>>>
>>
>> >
>>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---