def delivery_success_callback(msg: Message):
    pprint({
        'topic': msg.topic(),
        'partition': msg.partition(),
        'timestamp': msg.timestamp(),
        'key': msg.key(),
        'value': msg.value(),
    })
Example #2
0
 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]
Example #3
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,
    )