Ejemplo n.º 1
0
class RequestListener(object):
    
    def __init__(self, host='localhost', port=61613, destination='mq1', user='******', password='******'):
        'init publisher controller to manage sending'
        self.publisherController = PublisherController()
        'create a connection to the command message queue'
        self.conn = stomp.Connection(host_and_ports = [(host,port)])        
        self.conn.set_listener('',self)
        self.conn.start()
        self.conn.connect(login=user,passcode=password)
        self.conn.subscribe(destination=destination,id='station-101',ack='auto')

    def on_message(self, headers, message):        
        if message != None:
            print(message)
            msg = json.loads(message)        
            requestType = msg['RequestType']
            if requestType == 'login':
                pass
            elif requestType == 'data':
                dataId = msg['DataId']            
                #sending data to queue specified by dataid
                self.publisherController.send(dataId,'sending data to %s'%dataId)            
        else:
            print('wrong message format...')
            
    def close(self):
        self.publisherController.close()
Ejemplo n.º 2
0
 def __init__(self, host='localhost', port=61613, destination='mq1', user='******', password='******'):
     'init publisher controller to manage sending'
     self.publisherController = PublisherController()
     'create a connection to the command message queue'
     self.conn = stomp.Connection(host_and_ports = [(host,port)])        
     self.conn.set_listener('',self)
     self.conn.start()
     self.conn.connect(login=user,passcode=password)
     self.conn.subscribe(destination=destination,id='station-101',ack='auto')