<s> from twisted . internet . defer import inlineCallbacks <EOL> from twisted . internet import reactor <EOL> from twisted . internet . protocol import ClientCreator <EOL> from twisted . python import log <EOL> from txamqp . protocol import AMQClient <EOL> from txamqp . client import TwistedDelegate <EOL> import txamqp . spec <EOL> @ inlineCallbacks <EOL> def gotConnection ( conn , username , password ) : <EOL> print "<STR_LIT>" <EOL> yield conn . authenticate ( username , password ) <EOL> print "<STR_LIT>" <EOL> chan = yield conn . channel ( <NUM_LIT:1> ) <EOL> yield chan . channel_open ( ) <EOL> yield chan . queue_declare ( queue = "<STR_LIT>" , durable = True , exclusive = False , auto_delete = False ) <EOL> yield chan . exchange_declare ( exchange = "<STR_LIT>" , type = "<STR_LIT>" , durable = True , auto_delete = False ) <EOL> yield chan . queue_bind ( queue = "<STR_LIT>" , exchange = "<STR_LIT>" , routing_key = "<STR_LIT>" ) <EOL> yield chan . basic_consume ( queue = '<STR_LIT>' , no_ack = True , consumer_tag = "<STR_LIT>" ) <EOL> queue = yield conn . queue ( "<STR_LIT>" ) <EOL> while True : <EOL> msg = yield queue . get ( ) <EOL> print '<STR_LIT>' + msg . content . body + '<STR_LIT>' + str ( chan . id ) <EOL> if msg . content . body == "<STR_LIT>" : <EOL> break <EOL> yield chan . basic_cancel ( "<STR_LIT>" ) <EOL> yield chan . channel_close ( ) <EOL> chan0 = yield conn . channel ( <NUM_LIT:0> ) <EOL> yield chan0 . connection_close ( ) <EOL> reactor . stop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> if len ( sys . argv ) < <NUM_LIT:7> : <EOL> print "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> host = sys . argv [ <NUM_LIT:1> ] <EOL> port = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> vhost = sys . argv [ <NUM_LIT:3> ] <EOL> username = sys . argv [ <NUM_LIT:4> ] <EOL> password = sys . argv [ <NUM_LIT:5> ] <EOL> spec = txamqp . spec . load ( sys . argv [ <NUM_LIT:6> ] ) <EOL> delegate = TwistedDelegate ( ) <EOL> d = ClientCreator ( reactor , AMQClient , delegate = delegate , vhost = vhost , <EOL> spec = spec ) . connectTCP ( host , port ) <EOL> d . addCallback ( gotConnection , username , password ) <EOL> def whoops ( err ) : <EOL> if reactor . running : <EOL> log . err ( err ) <EOL> reactor . stop ( ) <EOL> d . addErrback ( whoops ) <EOL> reactor . run ( ) </s>
