[rabbitmq-discuss] Channel Cost

Ben Hyde bhyde at pobox.com
Tue Jan 27 20:54:09 GMT 2009


On Jan 27, 2009, at 2:34 PM, Jason J. W. Williams wrote:
> Hi Barry,
>
> chan_send
> .basic_publish
> (msg,exchange=args.exchange,routing_key=args.routing_key)
> to an exchange that doesn't exist.


Sometime ago, as Dmitriy had pointed out, Matthias suggested that a  
synchronous call to RabbitMQ is a good way to see if it has consumed  
the frames we previously dispatched to it.  And presumably that also  
allows amqplib a chance to see any errors that consumption sent back.   
Dmitriy suggested using declare_exchange as possible choice for a  
synchronous call to the broker, and Matthias made some other  
suggestions.

So in the following ping_channel does a meaningless exchange_declare.

Jason's example of how to get basic_publish to have an error:

On Jan 27, 2009, at 2:34 PM, Jason J. W. Williams wrote:
> ...chan_send 
> .basic_publish 
> (msg,exchange=args.exchange,routing_key=args.routing_key)
> to an exchange that doesn't exist. ..

So the following code does that, followed by calling ping_channel.   
The transcript below shows amqplib reporting the error as soon as it  
reads off that the channel is closing.

The source:

#!/usr/bin/env python
import amqplib.client_0_8 as amqp
import logging
from os import environ

def ping_channel(channel):
     channel.exchange_declare("RANDOMTEXT",type='topic', passive=True)


if __name__ == '__main__':
     logger = logging.getLogger('amqplib')
     logger.addHandler(logging.StreamHandler())
     logger.setLevel(logging.DEBUG)
     def trace(m): logger.debug('TRACE: ' + m)
     vhost=environ.get('AMQP_USERID','/')
     trace('create connection')
     connection = conn =  
amqp.Connection(environ.get('AMQP_SERVER','localhost'),
                                               
userid=environ.get('AMQP_USERID','guest'),
                                               
password=environ.get('AMQP_USERID','guest'),
                                              virtual_host=vhost)
     trace('create channel')
     channel = connection.channel()
     trace('access_request')
     channel.access_request(vhost, active=True, write=True)
     exchange_name = environ.get('AMQP_EXCHANGE','ampq.topic')
#    exchange = channel.exchange_declare(exchange_name,
#                                         
environ.get('AMQP_EXCHANGE_KIND','topic'))
     trace('make message')
     msg = amqp.Message("Hi there", content_type='text/plain')
     trace('basic_publish')
     channel.basic_publish(msg, exchange_name,  
routing_key=environ.get('AMQP_ROUTING_KEY',''))
     trace('ping')
     ping_channel(channel)
     trace('done')


The transcript:
bash-3.2$ env - PATH=$PATH AMQP_SERVER=192.168.1.2 AMQP_EXCHANGE=bogus  
bin/foo.py
TRACE: create connection
 > (10, 10): Connection.start
Start from server, version: 8.0, properties: {u'platform': 'Erlang/ 
OTP', u'product': 'RabbitMQ', u'version': '1.5.0', u'copyright':  
'Copyright (C) 2007-2009 LShift Ltd., Cohesive Financial Technologies  
LLC., and Rabbit Technologies Ltd.', u'information': 'Licensed under  
the MPL.  See http://www.rabbitmq.com/'}, mechanisms: ['PLAIN',  
'AMQPLAIN'], locales: ['en_US']
< (10, 11): Connection.start_ok
 > (10, 30): Connection.tune
< (10, 31): Connection.tune_ok
< (10, 40): Connection.open
 > (10, 41): Connection.open_ok
Open OK! known_hosts [elm.cozy.org:5672]
TRACE: create channel
using channel_id: 1
< (20, 10): Channel.open
 > (20, 11): Channel.open_ok
Channel open
TRACE: access_request
< (30, 10): Channel.access_request
 > (30, 11): Channel.access_request_ok
TRACE: make message
TRACE: basic_publish
< (60, 40): Channel.basic_publish
TRACE: ping
< (40, 10): Channel.exchange_declare
 > (20, 40): Channel.close
< (20, 41): Channel.close_ok
Closed channel #1
Traceback (most recent call last):
   File "bin/foo.py", line 34, in <module>
     ping_channel(channel)
   File "bin/foo.py", line 8, in ping_channel
     channel.exchange_declare("RANDOMTEXT",type='topic', passive=True)
   File "/opt/local/lib/python2.5/site-packages/amqplib/ 
client_0_8.py", line 1814, in exchange_declare
     (40, 11),    # Channel.exchange_declare_ok
   File "/opt/local/lib/python2.5/site-packages/amqplib/ 
client_0_8.py", line 203, in wait
     return self._dispatch(method_sig, args, content)
   File "/opt/local/lib/python2.5/site-packages/amqplib/ 
client_0_8.py", line 115, in _dispatch
     return amqp_method(self, args)
   File "/opt/local/lib/python2.5/site-packages/amqplib/ 
client_0_8.py", line 1244, in _close
     raise AMQPChannelException(reply_code, reply_text, (class_id,  
method_id))
amqplib.client_0_8.AMQPChannelException: (404, u"NOT_FOUND - no  
exchange 'bogus' in vhost '/'", (60, 40), 'Channel.basic_publish')
bash-3.2$ 




More information about the rabbitmq-discuss mailing list