示例#1
0
class StompClient(StompClientFactory):
    status = {}
    def recv_connected(self, msg):
        print "Connected with stomp"
        self.timer = None
        
    def stop_statuses(self):
        self.timer.stop()
        self.timer = None

    def restart_statuses(self):
        self.subscribe("/flumotion/poll")
        self.subscribe("/flumotion/command")

        self.timer = LoopingCall(self.send_status)
        self.timer.start(5)

    def recv_message(self, msg):
        print "Message received %r" % (msg,)
        if msg["headers"]["destination"] == "/flumotion/poll":
            try:
                component = msg["body"]
                global main
                main.poll_uistate(component)

            except Exception, e:
                print "Broken Total Request %r" % (e,)
        elif msg["headers"]["destination"] == "/flumotion/command":
            try:
                message = json.decode(msg["body"])
                global main
                main.run_command(message)
            except Exception, e:
                print "Broken request %r" % (e,)
 def recv_message(self, msg):
     message = json.decode(msg['body'])
     if msg['headers']['destination'] == CHANNEL_MINIDO_WRITE:
         if type(message) is list:
             print(str(datetime.datetime.now()), ": STOMP to RS485 :", message)
             for conn in self.minidoFactory.connections:
                 conn.send_data(message)
             # Also copy it for other listeners.
             self.send(CHANNEL_MINIDO_READ, json.encode(message))
示例#3
0
文件: hub.py 项目: lmacken/moksha
    def consume_stomp_message(self, message):
        topic = message['headers'].get('destination')
        if not topic:
            log.debug("Got message without a topic: %r" % message)
            return

        # FIXME: only do this if the consumer wants it `jsonified`
        try:
            body = json.decode(message['body'])
        except Exception, e:
            log.warning('Cannot decode message from JSON: %s' % e)
            #body = {}
            body = message['body']
示例#4
0
	def on_message(self, headers, message):
		print 'received a message %s' % message

		msg = json.decode(message)
		command = msg.get('command')

		if command == 'get_channels':
			print 'sending channels!'

			IRCClient.get_instance().send_channels()

		else:
			print 'command ', command, ' not understood'
示例#5
0
文件: hub.py 项目: lmacken/moksha
    def consume_stomp_message(self, message):
        topic = message['headers'].get('destination')
        if not topic:
            log.debug("Got message without a topic: %r" % message)
            return

        # FIXME: only do this if the consumer wants it `jsonified`
        try:
            body = json.decode(message['body'])
        except Exception, e:
            log.warning('Cannot decode message from JSON: %s' % e)
            #body = {}
            body = message['body']
 def recv_message(self, msg):
     message = json.decode(msg['body'])
     if msg['headers']['destination'] == CHANNEL_DISPLAY_NAME:
         print(message)
         if 'ButtonClicked' in message and message['ButtonClicked'] == '1':
             self.send_data({'ButtonClicked': '2'})
         if 'ListGroups' in message and message['ListGroups'] == '1':
             self.send_data({'Group1': 'RDC', 
                 'Group2': 'Etage', 'Group3': 'Grenier'})
     elif msg['headers']['destination'] == CHANNEL_MINIDO_READ:
         self.mpd.recv_minido_packet(message)
     elif msg['headers']['destination'] == CHANNEL_MINIDO_LAYOUT:
         if 'query' in message.keys():
             if message['query'] == 'getLayout':
                 self.send(CHANNEL_MINIDO_LAYOUT, 
                     json.encode({'layout': self.mpd.devdict.keys()}))
             elif message['query'] == 'getStatus':
                 self.send(CHANNEL_MINIDO_LAYOUT, 
                     json.encode({'status': 'This is a status line'}))