def runrealtime(): try: client = Stomp(CONFIG) client.connect() # client.subscribe(QUEUE, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL}) client.subscribe(QUEUE, {StompSpec.ACK_HEADER: StompSpec.ACK_AUTO}) while True: try: frame = client.receiveFrame() # body=json.dumps(frame.body) body = json.loads(frame.body.decode())[0] insuranceType = body.get("insuranceType", [])[0] body['insuranceType'] = insuranceType companyId = body.get('companyId', []) #保险公司选择 if len(companyId) == 0 or "2" in companyId: client.send(body=json.dumps(body, ensure_ascii=False).encode(), destination=EPICC) log.info('Got %s' % json.dumps(body, ensure_ascii=False)) # client.ack(frame) body['client'] = client getSource(body) except Exception as e: log.error(e) log.error(frame.body) log.error(traceback.format_exc()) except Exception as e: log.error(e) log.error(traceback.format_exc())
class MessageClient: """ STOMP sync client """ def __init__(self, stomp_config: StompConfig): self.client = Stomp(stomp_config) def publish_model_score(self, score_date: date, score_value: float): """ Publishes the score date and value on the message queue """ self.client.connect(headers={'passcode': _MQ_PASS, 'login': _MQ_USER}) message = 'date={0}\nvalue={1}'.format(score_date, str(score_value)).encode() self.client.send(_MQ_DEST, body=message) self.client.disconnect() def close(self): """ Closes the session and transport, flushing the active subscription """ self.client.close(flush=True)
def runrealtime(): try: client = Stomp(CONFIG) client.connect() # client.subscribe(QUEUE, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL}) client.subscribe(BATCH_PROCESS_QUEUE, {StompSpec.ACK_HEADER: StompSpec.ACK_AUTO}) while True: try: frame = client.receiveFrame() body = json.loads(frame.body.decode()) client.send(body=json.dumps(body, ensure_ascii=False).encode(), destination=se.EPICC_BATCH_REPAIR_QUEUE) batch_repair_thread(body, client) except Exception, e: log.error(e) log.error(frame.body) log.error(traceback.format_exc()) except Exception as e: log.error(e) log.error(traceback.format_exc())
def send_score_to_message_queue(date, score): client = Stomp(StompConfig('tcp://fmapiclient.cs.ucl.ac.uk:7672', version=StompSpec.VERSION_1_0)) client.connect(headers={'passcode': 'admin', 'login': '******'}) message = 'date={0}\nvalue={1}'.format(date, str(score)) client.send('/queue/PubModelScore.Q', body=message) client.disconnect()