Exemplo n.º 1
0
class SocketConnection(tornadio2.conn.SocketConnection):
    # Class level variable
    participants = set()
    AMQP_HOST="localhost"
    AMQP_PORT=5672 
    # Get this file out of the txamqp distribution.
    AMQP_SPEC="specs/rabbitmq/amqp0-8.stripped.rabbitmq.xml"

    def on_open(self, info):
        self.send("Welcome from the server.")
        self.participants.add(self)

    def on_message(self, message):
        # Pong message back
        # loop over participants to deliver to each of them 
        #for p in self.participants:
            #p.send(message)
        pass

    def writeToSocket(self, msg):
        #self.send( amqpMsg )
        self.emit('amqpMsg', msg[3] + " " + msg[4] + " " + msg[5].body )

    def on_close(self):
        """dilute this client connection - Century Dictionary and Cyclopedia
           To render more liquid; make thin or more fluid, as by mixture of a fluid of less 
           with one of greater consistence; attenuate the strength or consistence of: often 
           used figuratively: as, to dilute a narrative with weak reflections.
           Hence To weaken, as spirit or an acid, by an admixture of water or other liquid, 
           which renders the spirit or acid less concentrated. """
        logging.log( logging.DEBUG, 'on_close:: close connection - client hanghup')
        self.participants.remove(self)
        self.amqpVhost = None
        self.amqpUser = None
        self.amqpPassw = None
        self.amqpFactory.clientConnectionLost(self.amqpFactory.connector, "client hangup") # .connectionLost( "client hangup")       #.close("client hangup")
        self.amqpFactory = None
        self = None # dilute into the void 
    
    @event('amqpMsg')    
    def amqpMsg(self, amqpMsg):
        #self.send('HERE within the message BULK: ' + amqpMsg)
        self.amqpFactory.send_message(exchange='messaging/', type='topic', routing_key='amqpMsg', msg=amqpMsg)
        
    @event('openAmqp')
    def openAmqp(self, amqpSessionId):
        logging.log(logging.DEBUG,'new client\n')
        amqpDB = AmqpDB()
        self.amqpVhost = amqpDB.getVhost(amqpSessionId)
        self.amqpUser  = amqpDB.getUser(amqpSessionId)
        self.amqpPassw = amqpDB.getPassw(amqpSessionId)
        
        #print(self.amqpVhost, self.amqpUser, self.amqpPassw)
        self.amqpFactory = AmqpFactory(host=self.AMQP_HOST, port=self.AMQP_PORT, vhost=self.amqpVhost, user=self.amqpUser, password=self.amqpPassw, spec_file=self.AMQP_SPEC)
        self.amqpFactory.read(exchange='messaging/', type="topic", queue="", routing_key='#', callback=self.writeToSocket)
Exemplo n.º 2
0
 def openAmqp(self, amqpSessionId):
     logging.log(logging.DEBUG,'new client\n')
     amqpDB = AmqpDB()
     self.amqpVhost = amqpDB.getVhost(amqpSessionId)
     self.amqpUser  = amqpDB.getUser(amqpSessionId)
     self.amqpPassw = amqpDB.getPassw(amqpSessionId)
     
     #print(self.amqpVhost, self.amqpUser, self.amqpPassw)
     self.amqpFactory = AmqpFactory(host=self.AMQP_HOST, port=self.AMQP_PORT, vhost=self.amqpVhost, user=self.amqpUser, password=self.amqpPassw, spec_file=self.AMQP_SPEC)
     self.amqpFactory.read(exchange='messaging/', type="topic", queue="", routing_key='#', callback=self.writeToSocket)