use of org.apache.kafka.common.protocol.types.Struct in project starlight-for-kafka by datastax.
the class GroupMetadataConstants method groupMetadataKey.
/**
* Generates the key for group metadata message for given group.
*
* @return key bytes for group metadata message
*/
static byte[] groupMetadataKey(String group) {
Struct key = new Struct(CURRENT_GROUP_KEY_SCHEMA);
key.set(GROUP_KEY_GROUP_FIELD, group);
ByteBuffer byteBuffer = ByteBuffer.allocate(2 + /* version */
key.sizeOf());
byteBuffer.putShort(CURRENT_GROUP_KEY_SCHEMA_VERSION);
key.writeTo(byteBuffer);
return byteBuffer.array();
}
use of org.apache.kafka.common.protocol.types.Struct in project starlight-for-kafka by datastax.
the class KafkaCommandDecoder method byteBufToRequest.
protected KafkaHeaderAndRequest byteBufToRequest(ByteBuf msg, SocketAddress remoteAddress) {
checkArgument(msg.readableBytes() > 0);
ByteBuffer nio = msg.nioBuffer();
RequestHeader header = RequestHeader.parse(nio);
if (isUnsupportedApiVersionsRequest(header)) {
ApiVersionsRequest apiVersionsRequest = new ApiVersionsRequest((short) 0, header.apiVersion());
return new KafkaHeaderAndRequest(header, apiVersionsRequest, msg, remoteAddress);
} else {
ApiKeys apiKey = header.apiKey();
short apiVersion = header.apiVersion();
Struct struct = apiKey.parseRequest(apiVersion, nio);
AbstractRequest body = AbstractRequest.parseRequest(apiKey, apiVersion, struct);
return new KafkaHeaderAndRequest(header, body, msg, remoteAddress);
}
}
use of org.apache.kafka.common.protocol.types.Struct in project starlight-for-kafka by datastax.
the class TransactionLogKey method decode.
public static TransactionLogKey decode(ByteBuffer byteBuffer, short schemaVersion) {
Schema schema = getSchema(schemaVersion);
// skip version
byteBuffer.getShort();
Struct struct = schema.read(byteBuffer);
return new TransactionLogKey(struct.getString(TXN_ID_FIELD));
}
use of org.apache.kafka.common.protocol.types.Struct in project starlight-for-kafka by datastax.
the class TransactionLogValue method toByteBuffer.
public ByteBuffer toByteBuffer(short schemaVersion) {
if (this.getTransactionStatus() == TransactionState.EMPTY.getValue() && !transactionPartitions.isEmpty()) {
throw new IllegalStateException("Transaction is not expected to have any partitions since its state is " + transactionStatus);
}
Struct struct = new Struct(getSchema(schemaVersion));
struct.set(PRODUCER_ID_FIELD, producerId);
struct.set(PRODUCER_EPOCH_FIELD, producerEpoch);
struct.set(TXN_TIMEOUT_MS_FIELD, transactionTimeoutMs);
struct.set(TXN_STATUS_FIELD, transactionStatus);
struct.set(TXN_PARTITIONS_FIELD, transactionPartitions.stream().map(PartitionsSchema::toStruct).toArray());
struct.set(TXN_LAST_UPDATE_TIMESTAMP_FIELD, transactionLastUpdateTimestampMs);
struct.set(TXN_START_TIMESTAMP_FIELD, transactionStartTimestampMs);
ByteBuffer byteBuffer = ByteBuffer.allocate(2 + /* version */
struct.sizeOf());
byteBuffer.putShort(schemaVersion);
struct.writeTo(byteBuffer);
byteBuffer.flip();
return byteBuffer;
}
use of org.apache.kafka.common.protocol.types.Struct in project starlight-for-kafka by datastax.
the class TransactionMarkerChannelHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
ByteBuffer nio = ((ByteBuf) o).nioBuffer();
ResponseHeader responseHeader = ResponseHeader.parse(nio);
InFlightRequest inFlightRequest = inFlightRequestMap.remove(responseHeader.correlationId());
if (inFlightRequest != null) {
inFlightRequest.onComplete(nio);
return;
}
PendingGenericRequest genericRequest = genericRequestMap.remove(responseHeader.correlationId());
if (genericRequest != null) {
Struct responseBody = genericRequest.apiKeys.parseResponse(genericRequest.apiVersion, nio);
AbstractResponse response = AbstractResponse.parseResponse(genericRequest.apiKeys, responseBody);
genericRequest.response.complete(response);
return;
}
log.error("Miss the inFlightRequest with correlationId {}.", responseHeader.correlationId());
}
Aggregations