Skip to content

Commit

Permalink
fix(topicdata): display __transaction_state data
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Oct 24, 2021
1 parent 6489780 commit 25a50ca
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/main/java/org/akhq/models/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.confluent.kafka.schemaregistry.json.JsonSchema;
import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema;
import kafka.coordinator.group.GroupMetadataManager;
import kafka.coordinator.transaction.TransactionLog;
import kafka.coordinator.transaction.TxnKey;
import lombok.*;
import org.akhq.configs.SchemaRegistryType;
import org.akhq.utils.AvroToJsonDeserializer;
Expand Down Expand Up @@ -191,26 +193,36 @@ private String convertToString(byte[] payload, Integer schemaId, boolean isKey)
return new String(payload);
}
} else if (topic.isInternalTopic() && topic.getName().equals("__consumer_offsets")) {
if (isKey) {
try {
try {
if (isKey) {
return GroupMetadataManager.readMessageKey(ByteBuffer.wrap(payload)).key().toString();
} catch (Exception exception) {
this.exceptions.add(Optional.ofNullable(exception.getMessage())
.filter(msg -> !msg.isBlank())
.orElseGet(() -> exception.getClass().getCanonicalName()));

return new String(payload);
}
} else {
try {
} else {
return GroupMetadataManager.readOffsetMessageValue(ByteBuffer.wrap(payload)).toString();
} catch (Exception exception) {
this.exceptions.add(Optional.ofNullable(exception.getMessage())
}
} catch (Exception exception) {
this.exceptions.add(Optional.ofNullable(exception.getMessage())
.filter(msg -> !msg.isBlank())
.orElseGet(() -> exception.getClass().getCanonicalName()));

return new String(payload);
return new String(payload);
}
} else if (topic.isInternalTopic() && topic.getName().equals("__transaction_state")) {
try {
if (isKey) {
TxnKey txnKey = TransactionLog.readTxnRecordKey(ByteBuffer.wrap(payload));
return avroToJsonSerializer.getMapper().writeValueAsString(
Map.of("transactionalId", txnKey.transactionalId(), "version", txnKey.version())
);
} else {
TxnKey txnKey = TransactionLog.readTxnRecordKey(ByteBuffer.wrap(this.bytesKey));
return avroToJsonSerializer.getMapper().writeValueAsString(TransactionLog.readTxnRecordValue(txnKey.transactionalId(), ByteBuffer.wrap(payload)));
}
} catch (Exception exception) {
this.exceptions.add(Optional.ofNullable(exception.getMessage())
.filter(msg -> !msg.isBlank())
.orElseGet(() -> exception.getClass().getCanonicalName()));

return new String(payload);
}
} else {
if (protobufToJsonDeserializer != null) {
Expand Down

0 comments on commit 25a50ca

Please sign in to comment.