コード例 #1
0
ファイル: avromessage.py プロジェクト: Temikus/esque
 def decode_message_from_avro(self, message: Message):
     key_schema_id, decoded_key = self.decode_bytes(message.key())
     value_schema_id, decoded_value = self.decode_bytes(message.value())
     headers = []
     if message.headers():
         for header_key, header_value in message.headers():
             headers.append(
                 MessageHeader(key=header_key,
                               value=header_value.decode("utf-8")
                               if header_value else None))
     decoded_message = DecodedAvroMessage(decoded_key,
                                          decoded_value,
                                          message.partition(),
                                          key_schema_id,
                                          value_schema_id,
                                          headers=headers)
     schema_version = it.count(1)
     serializable_message = {
         "key":
         decoded_message.key,
         "value":
         decoded_message.value,
         "partition":
         decoded_message.partition,
         "schema_directory_name":
         f"{next(schema_version):04}_{key_schema_id}_{value_schema_id}",
     }
     return key_schema_id, value_schema_id, decoded_message, serializable_message
コード例 #2
0
def delivery_success_callback(msg: Message):
    pprint({
        'topic': msg.topic(),
        'partition': msg.partition(),
        'timestamp': msg.timestamp(),
        'key': msg.key(),
        'value': msg.value(),
    })
コード例 #3
0
ファイル: utils.py プロジェクト: real-digital/esque
 def update_callback(self, err: Optional[cimpl.KafkaError],
                     msg: cimpl.Message):
     assert err is None, f"Received KafkaError {err}."
     self.binary_value = msg.value()
     self.binary_key = msg.key()
     self.partition = msg.partition()
     self.offset = msg.offset()
     self.timestamp = msg.timestamp()[1]
コード例 #4
0
def decode_message(message: Message) -> DecodedMessage:
    if message.key() is None:
        decoded_key = None
    else:
        decoded_key = message.key().decode("utf-8")
    decoded_value = message.value().decode("utf-8")
    headers = []
    if message.headers():
        for header_key, header_value in message.headers():
            headers.append(MessageHeader(key=header_key, value=header_value.decode("utf-8") if header_value else None))
    return DecodedMessage(
        key=decoded_key,
        value=decoded_value,
        partition=message.partition(),
        offset=message.offset(),
        timestamp=str(message.timestamp()),
        headers=headers,
    )
コード例 #5
0
ファイル: consume.py プロジェクト: TinDang97/DPS_Util
    def _deserializer_msg(self, msg: Message):
        if self._value_deserializer:
            try:
                msg.set_value(self._value_deserializer(msg.value()))
            except Exception as se:
                raise ValueDeserializationError(exception=se, message=msg)

        if self._key_deserializer:
            try:
                msg.set_key(self._key_deserializer(msg.key()))
            except Exception as se:
                raise KeyDeserializationError(exception=se, message=msg)
        return msg
コード例 #6
0
    def write_message_to_file(self, message: Message):
        key_schema_id, decoded_key = self.decode_bytes(message.key())
        value_schema_id, decoded_value = self.decode_bytes(message.value())
        decoded_message = DecodedAvroMessage(decoded_key, decoded_value,
                                             message.partition(),
                                             key_schema_id, value_schema_id)

        if self.schema_changed(
                decoded_message) or self.schema_dir_name is None:
            self.schema_dir_name = f"{next(self.schema_version):04}_{key_schema_id}_{value_schema_id}"
            self.current_key_schema_id = key_schema_id
            self.current_value_schema_id = value_schema_id
            self._dump_schemata(key_schema_id, value_schema_id)

        serializable_message = {
            "key": decoded_message.key,
            "value": decoded_message.value,
            "partition": decoded_message.partition,
            "schema_directory_name": self.schema_dir_name,
        }
        pickle.dump(serializable_message, self.file)
コード例 #7
0
ファイル: message.py プロジェクト: garrettthomaskth/esque
def decode_message(message: Message) -> DecodedMessage:
    decoded_key = message.key().decode("utf-8")
    decoded_value = message.value().decode("utf-8")

    return DecodedMessage(decoded_key, decoded_value, message.partition())
コード例 #8
0
 def on_message_received(self, msg: Message) -> None:
     # noinspection PyArgumentList
     self.message_buffer.append((msg.key(), msg.value()))
     self.__idle_count = 0