Exemplo n.º 1
0
 def produce(self,
             sql: str,
             topic: str,
             data: Dict[str, Any],
             sync: bool = True):
     if self.send_to_kafka:
         self.producer.produce(topic=topic, data=data)
     else:
         if sync:
             sync_execute(sql, data)
         else:
             async_execute(sql, data)
Exemplo n.º 2
0
 def produce_proto(self,
                   sql: str,
                   topic: str,
                   data: Any,
                   sync: bool = True):
     if self.send_to_kafka:
         self.producer.produce(
             topic=topic,
             data=data,
             value_serializer=self.proto_length_serializer)
     else:
         dict_data = json.loads(
             MessageToJson(data,
                           including_default_value_fields=True,
                           preserving_proto_field_name=True))
         if sync:
             sync_execute(sql, dict_data)
         else:
             async_execute(sql, dict_data)