Beispiel #1
0
 def publish(self, event_name: str, msg: Any) -> Any:
     exchange = self.event_map.get_exchange_name(event_name)
     queue = self.event_map.get_queue_name(event_name)
     body = jsons.dumps(msg)
     ch = self.connection.channel()
     ch.exchange_declare(exchange=exchange, exchange_type='fanout', durable=True)
     log_info('PUBLISH EVENT', exchange=exchange, routing_key=queue, body=body)
     ch.basic_publish(
         exchange=exchange,
         routing_key=queue,
         body=body.encode()
     )
Beispiel #2
0
 def on_rpc_request(ch, method, props, body):
     decoded_body = body.decode()
     log_info('GET RPC REQUEST', queue=queue, body=decoded_body)
     args = jsons.loads(decoded_body)
     result = handler(*args)
     body = jsons.dumps(result)
     # send reply
     log_info('SEND RPC REPLY', exchange=exchange, routing_key=props.reply_to, correlation_id=props.correlation_id, body=body)
     ch.basic_publish(
         exchange='',
         routing_key=props.reply_to,
         properties=pika.BasicProperties(correlation_id=props.correlation_id),
         body=body.encode()
     )
     if not auto_ack:
         ch.basic_ack(delivery_tag=method.delivery_tag)
Beispiel #3
0
 def publish(self, event_name: str, msg: Any) -> Any:
     if event_name not in self.event_handler:
         raise Exception(
             'Event handler for "{}" is not found'.format(event_name))
     log_info('PUBLISH EVENT', event_name=event_name, msg=msg)
     self.event_handler[event_name](msg)
Beispiel #4
0
 def on_rpc_response(ch: BlockingChannel, method, props, body):
     if props.correlation_id == self.corr_id:
         decoded_body = body.decode()
         log_info('GET RPC REPLY', queue=reply_queue, correlation_id=self.corr_id, body=decoded_body)
         self.result = jsons.loads(decoded_body)
     ch.basic_ack(delivery_tag=method.delivery_tag)