async def stomp_subscribe(self, topic): self.log.debug('STOMP SUBSCRIBE topic=' + topic) frame = StompFrame() frame.set_command("SUBSCRIBE") frame.set_header('destination', topic) frame.set_header('id', 'my-id') out = StringIO() frame.write(out) await self.ws.send(out.getvalue().encode('utf-8'))
async def stomp_connect(self, hostname): self.log.debug('STOMP CONNECT host=' + hostname) frame = StompFrame() frame.set_command("CONNECT") frame.set_header('accept-version', '1.2') frame.set_header('host', hostname) out = StringIO() frame.write(out) await self.ws.send(out.getvalue().encode('utf-8'))
async def stomp_send(self, topic, message): print('STOMP SEND topic=' + topic) frame = StompFrame() frame.set_command("SEND") frame.set_header('destination', topic) frame.set_content(message) out = StringIO() frame.write(out) await self.ws.send(out.getvalue().encode('utf-8'))
async def stomp_disconnect(self, receipt=None): self.log.info('STOMP DISCONNECT receipt=' + receipt) frame = StompFrame() frame.set_command("DISCONNECT") if receipt is not None: frame.set_header('receipt', receipt) out = StringIO() frame.write(out) await self.ws.send(out.getvalue().encode('utf-8'))
def on_pika_message(self, channel, method, header, body): pika.log.info('PikaCient: Got message from brocker, delivery tag #%i' % method.delivery_tag) response = StompFrame.message( message=body, headers = {'subscription': self.subscription_id} ) self.write_message(response.as_string())
async def stomp_read_message(self): while True: message = await self.ws.recv() s_in = StringIO(message.decode('utf-8')) stomp = StompFrame.parse(s_in) if stomp.get_command() == 'MESSAGE': return stomp.get_content() elif stomp.get_command() == 'CONNECTED': version = stomp.get_header('version') self.log.info('STOMP CONNECTED version=' + version) elif stomp.get_command() == 'RECEIPT': receipt = stomp.get_header('receipt-id') self.log.debug('STOMP RECEIPT id=' + receipt) elif stomp.get_command() == 'ERROR': self.log.error('STOMP ERROR content=' + stomp.get_content())
async def stomp_send(self, topic, message): logger.debug('STOMP SEND topic=' + topic) frame = StompFrame() frame.set_command("SEND") frame.set_header('destination', topic) frame.set_header('content-length', str(len(message))) frame.set_content(message) out = StringIO() frame.write(out) await self.ws.send(out.getvalue().encode('utf-8')) logger.debug('stomp_send completed')
def on_message(self, message): pika.log.info('Websocket: Got message from browser') request = StompFrame() request.from_string(message) pika.log.info('Websocket: Stomp ' + request.command) if request.is_connect(): response = StompFrame.connected() elif request.is_subscribe(): self.agent_id = '/'.join(request.get_header('destination').split('/')[1:]) self.subscription_id = request.get_header('id') pika.log.debug(self.agent_id) self.application.pika.channel.queue_declare(exclusive=True, queue=self.queue_name, callback=self.on_queue_declared) response = StompFrame.ok() elif request.is_unsubscribe(): #TODO same as on_close() but not delete queueu???? response = StompFrame.ok() elif request.is_send(): pika.log.info('Websocket: Not implemented') pika.log.debug(request.body) response = StompFrame.ok() else: pika.log.info('Websocket: Unknown command') response = StompFrame.error() self.write_message(response.as_string())