org.apache.kafka.common.protocol.types.Struct Java Examples
The following examples show how to use
org.apache.kafka.common.protocol.types.Struct.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroupMetadataConstants.java From kop with Apache License 2.0 | 5 votes |
static byte[] offsetCommitKey(String group, TopicPartition topicPartition, short versionId) { Struct key = new Struct(CURRENT_OFFSET_KEY_SCHEMA); key.set(OFFSET_KEY_GROUP_FIELD, group); key.set(OFFSET_KEY_TOPIC_FIELD, topicPartition.topic()); key.set(OFFSET_KEY_PARTITION_FIELD, topicPartition.partition()); ByteBuffer byteBuffer = ByteBuffer.allocate(2 /* version */ + key.sizeOf()); byteBuffer.putShort(CURRENT_OFFSET_KEY_SCHEMA_VERSION); key.writeTo(byteBuffer); return byteBuffer.array(); }
Example #2
Source File: GroupMetadataConstants.java From kop with Apache License 2.0 | 5 votes |
/** * 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(); }
Example #3
Source File: GroupMetadataConstants.java From kop with Apache License 2.0 | 5 votes |
/** * Generates the payload for offset commit message from given offset and metadata. * * @param offsetAndMetadata consumer's current offset and metadata * @return payload for offset commit message */ static byte[] offsetCommitValue(OffsetAndMetadata offsetAndMetadata) { Struct value = new Struct(CURRENT_OFFSET_VALUE_SCHEMA); value.set(OFFSET_VALUE_OFFSET_FIELD_V1, offsetAndMetadata.offset()); value.set(OFFSET_VALUE_METADATA_FIELD_V1, offsetAndMetadata.metadata()); value.set(OFFSET_VALUE_COMMIT_TIMESTAMP_FIELD_V1, offsetAndMetadata.commitTimestamp()); value.set(OFFSET_VALUE_EXPIRE_TIMESTAMP_FIELD_V1, offsetAndMetadata.expireTimestamp()); ByteBuffer byteBuffer = ByteBuffer.allocate(2 /* version */ + value.sizeOf()); byteBuffer.putShort(CURRENT_GROUP_VALUE_SCHEMA_VERSION); value.writeTo(byteBuffer); return byteBuffer.array(); }
Example #4
Source File: Response.java From DataLink with Apache License 2.0 | 5 votes |
private ByteBuffer serialize(ResponseHeader header, Struct body) { ByteBuffer buffer = ByteBuffer.allocate(header.sizeOf() + body.sizeOf()); header.writeTo(buffer); body.writeTo(buffer); buffer.rewind(); return buffer; }
Example #5
Source File: TestBrokerAdminClient.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** Analysis of struct data structure in metadata in Kafka. */ private static MessageValueStructAndVersionInfo readMessageValueStruct(ByteBuffer buffer) { MessageValueStructAndVersionInfo mvs = new MessageValueStructAndVersionInfo(); if (buffer == null) { mvs.setValue(null); mvs.setVersion(Short.valueOf("-1")); } else { short version = buffer.getShort(); Schema valueSchema = schemaFor(version).getValueSchema(); Struct value = (Struct) valueSchema.read(buffer); mvs.setValue(value); mvs.setVersion(version); } return mvs; }
Example #6
Source File: TestKafkaOffsetGetter.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** Analysis of struct data structure in metadata in Kafka. */ private static MessageValueStructAndVersionInfo readMessageValueStruct(ByteBuffer buffer) { MessageValueStructAndVersionInfo mvs = new MessageValueStructAndVersionInfo(); if (buffer == null) { mvs.setValue(null); mvs.setVersion(Short.valueOf("-1")); } else { short version = buffer.getShort(); Schema valueSchema = schemaFor(version).getValueSchema(); Struct value = (Struct) valueSchema.read(buffer); mvs.setValue(value); mvs.setVersion(version); } return mvs; }
Example #7
Source File: KafkaOffsetGetter.java From Kafka-Insight with Apache License 2.0 | 5 votes |
/** Analysis of Kafka data in topic in buffer. */ private static GroupTopicPartition readMessageKey(ByteBuffer buffer) { short version = buffer.getShort(); Schema keySchema = schemaFor(version).getKeySchema(); Struct key = (Struct) keySchema.read(buffer); String group = key.getString(KEY_GROUP_FIELD); String topic = key.getString(KEY_TOPIC_FIELD); int partition = key.getInt(KEY_PARTITION_FIELD); return new GroupTopicPartition(group, new TopicPartition(topic, partition)); }
Example #8
Source File: KafkaOffsetGetter.java From Kafka-Insight with Apache License 2.0 | 5 votes |
/** Analysis of struct data structure in metadata in Kafka. */ private static MessageValueStructAndVersionInfo readMessageValueStruct(ByteBuffer buffer) { MessageValueStructAndVersionInfo mvs = new MessageValueStructAndVersionInfo(); if (buffer == null) { mvs.setValue(null); mvs.setVersion(Short.valueOf("-1")); } else { short version = buffer.getShort(); Schema valueSchema = schemaFor(version).getValueSchema(); Struct value = (Struct) valueSchema.read(buffer); mvs.setValue(value); mvs.setVersion(version); } return mvs; }
Example #9
Source File: GroupMetadataConstants.java From kop with Apache License 2.0 | 4 votes |
static GroupMetadata readGroupMessageValue(String groupId, ByteBuffer buffer) { if (null == buffer) { // tombstone return null; } short version = buffer.getShort(); Schema valueSchema = schemaForGroup(version); Struct value = valueSchema.read(buffer); if (version == 0 || version == 1) { int generationId = value.getInt(GENERATION_KEY); String protocolType = value.getString(PROTOCOL_TYPE_KEY); String protocol = value.getString(PROTOCOL_KEY); String leaderId = value.getString(LEADER_KEY); Object[] memberMetadataArray = value.getArray(MEMBERS_KEY); GroupState initialState; if (memberMetadataArray.length == 0) { initialState = GroupState.Empty; } else { initialState = GroupState.Stable; } List<MemberMetadata> members = Lists.newArrayList(memberMetadataArray) .stream() .map(memberMetadataObj -> { Struct memberMetadata = (Struct) memberMetadataObj; String memberId = memberMetadata.getString(MEMBER_ID_KEY); String clientId = memberMetadata.getString(CLIENT_ID_KEY); String clientHost = memberMetadata.getString(CLIENT_HOST_KEY); int sessionTimeout = memberMetadata.getInt(SESSION_TIMEOUT_KEY); int rebalanceTimeout; if (version == 0) { rebalanceTimeout = sessionTimeout; } else { rebalanceTimeout = memberMetadata.getInt(REBALANCE_TIMEOUT_KEY); } ByteBuffer subscription = memberMetadata.getBytes(SUBSCRIPTION_KEY); byte[] subscriptionData = new byte[subscription.remaining()]; subscription.get(subscriptionData); Map<String, byte[]> protocols = new HashMap<>(); protocols.put(protocol, subscriptionData); return new MemberMetadata( memberId, groupId, clientId, clientHost, rebalanceTimeout, sessionTimeout, protocolType, protocols ); }).collect(Collectors.toList()); return GroupMetadata.loadGroup( groupId, initialState, generationId, protocolType, protocol, leaderId, members ); } else { throw new IllegalStateException("Unknown group metadata message version"); } }
Example #10
Source File: Response.java From DataLink with Apache License 2.0 | 4 votes |
Response(ResponseHeader header, Struct body) { this.buffers = sizeDelimit(serialize(header, body)); }
Example #11
Source File: MessageValueStructAndVersionInfo.java From kafka-eagle with Apache License 2.0 | 4 votes |
public Struct getValue() { return value; }
Example #12
Source File: MessageValueStructAndVersionInfo.java From kafka-eagle with Apache License 2.0 | 4 votes |
public void setValue(Struct value) { this.value = value; }
Example #13
Source File: MessageValueStructAndVersionInfo.java From Kafka-Insight with Apache License 2.0 | 4 votes |
public Struct getValue() { return value; }
Example #14
Source File: MessageValueStructAndVersionInfo.java From Kafka-Insight with Apache License 2.0 | 4 votes |
public void setValue(Struct value) { this.value = value; }