#NEWLINE# @ inlineCallbacks #NEWLINE# def writeMetric( metric_path , value , timestamp , host , port , username , password , vhost , exchange , spec = None , channel_number = 1 , ssl = False ) : #NEWLINE# #INDENT# if ( not spec ) : #NEWLINE# #INDENT# spec = txamqp . spec . load ( os . path . normpath ( os . path . join ( os . path . dirname ( __file__ ) , 'amqp0-8.xml' ) ) ) #NEWLINE# #UNINDENT# delegate = TwistedDelegate ( ) #NEWLINE# connector = ClientCreator ( reactor , AMQClient , delegate = delegate , vhost = vhost , spec = spec ) #NEWLINE# if ssl : #NEWLINE# #INDENT# from twisted.internet.ssl import ClientContextFactory #NEWLINE# conn = ( yield connector . connectSSL ( host , port , ClientContextFactory ( ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# conn = ( yield connector . connectTCP ( channel , port ) ) #NEWLINE# #UNINDENT# ( yield conn . authenticate ( username , password ) ) #NEWLINE# channel = ( yield conn . channel ( channel_number ) ) #NEWLINE# ( yield channel . channel_open ( ) ) #NEWLINE# ( yield channel . exchange_declare ( exchange = exchange , type = 'topic' , durable = True , auto_delete = False ) ) #NEWLINE# message = Content ( ( '%f %d' % ( value , timestamp ) ) ) #NEWLINE# message [ 'delivery mode' ] = 2 #NEWLINE# channel . basic_publish ( exchange = exchange , content = message , routing_key = metric_path ) #NEWLINE# ( yield channel . channel_close ( ) )