Example #1
0
#! /usr/bin/env python
#        \file basic.py
#  
#        \author borrey
# 
#        Date Created: 2013-06-12T11:59:47-0600\n
#        Date Modified:
# 
#        Copyright  All Rights Reserved
if __name__ == '__main__':
    import sys, os
    sys.path.append( os.path.join(os.path.dirname(__file__), '../lib/') )
    from message import Module as Message
    server = { 'host' : 'localhost', 'defaultExchangeName' : 'amqp_exchange', 'port' : 5672, 'virtual_host' : '/', 'login': '******', 'password': '******', 'authMechanism': 'AMQPLAIN' }
    
    message = Message( {
        'server' : server,
        'exchange' : 'fan_exchange', 'exchange_type' : 'fanout', 'queue' : ''
    }, None, 'start' )
    listener = message.getListener()
    def callback( message ) :
        print " [x] Received %r" % (message)
    def amqp_callback(ch, method, properties, body):
        ch.basic_ack(delivery_tag = method.delivery_tag)
        print " [x] Received %r" % (body)
    listener.on( 'message', callback )
    #listener.emit('start')
    
    message.listen( server, amqp_callback, '','direct', 'worker');
Example #2
0
#! /usr/bin/env python
#        \file basic.py
#  
#        \author borrey
# 
#        Date Created: 2013-06-12T11:59:47-0600\n
#        Date Modified:
# 
#        Copyright  All Rights Reserved
if __name__ == '__main__':
    import sys, os
    sys.path.append( os.path.join(os.path.dirname(__file__), '../lib/') )
    from message import Module as Message
    server = { 'host' : 'localhost', 'defaultExchangeName' : 'amqp_exchange', 'port' : 5672, 'virtual_host' : '/', 'login': '******', 'password': '******', 'authMechanism': 'AMQPLAIN' }

    message = Message( {
        'server' :  server,
        'exchange' : 'fan_exchange', 'queue' : ''
    }, None, 'start' )
    message.writeToExchange( server, 
                             'fan_exchange', 'fanout', '', 'Fanout Python Hello World!'
                             )
    #Direct
    if len(sys.argv) == 2 :
        message.writeToExchange( server, 
                                 '', 'direct', sys.argv[1], 'Direct Python Hello World!')