use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic in project kafka by apache.
the class OffsetCommitRequest method getErrorResponseTopics.
public static List<OffsetCommitResponseTopic> getErrorResponseTopics(List<OffsetCommitRequestTopic> requestTopics, Errors e) {
List<OffsetCommitResponseTopic> responseTopicData = new ArrayList<>();
for (OffsetCommitRequestTopic entry : requestTopics) {
List<OffsetCommitResponsePartition> responsePartitions = new ArrayList<>();
for (OffsetCommitRequestData.OffsetCommitRequestPartition requestPartition : entry.partitions()) {
responsePartitions.add(new OffsetCommitResponsePartition().setPartitionIndex(requestPartition.partitionIndex()).setErrorCode(e.code()));
}
responseTopicData.add(new OffsetCommitResponseTopic().setName(entry.name()).setPartitions(responsePartitions));
}
return responseTopicData;
}
use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic in project kafka by apache.
the class MessageTest method testOffsetCommitRequestVersions.
@Test
public void testOffsetCommitRequestVersions() throws Exception {
String groupId = "groupId";
String topicName = "topic";
String metadata = "metadata";
int partition = 2;
int offset = 100;
testAllMessageRoundTrips(new OffsetCommitRequestData().setGroupId(groupId).setTopics(Collections.singletonList(new OffsetCommitRequestTopic().setName(topicName).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partition).setCommittedMetadata(metadata).setCommittedOffset(offset))))));
Supplier<OffsetCommitRequestData> request = () -> new OffsetCommitRequestData().setGroupId(groupId).setMemberId("memberId").setGroupInstanceId("instanceId").setTopics(Collections.singletonList(new OffsetCommitRequestTopic().setName(topicName).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partition).setCommittedLeaderEpoch(10).setCommittedMetadata(metadata).setCommittedOffset(offset).setCommitTimestamp(20))))).setRetentionTimeMs(20);
for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
OffsetCommitRequestData requestData = request.get();
if (version < 1) {
requestData.setMemberId("");
requestData.setGenerationId(-1);
}
if (version != 1) {
requestData.topics().get(0).partitions().get(0).setCommitTimestamp(-1);
}
if (version < 2 || version > 4) {
requestData.setRetentionTimeMs(-1);
}
if (version < 6) {
requestData.topics().get(0).partitions().get(0).setCommittedLeaderEpoch(-1);
}
if (version < 7) {
requestData.setGroupInstanceId(null);
}
if (version == 1) {
testEquivalentMessageRoundTrip(version, requestData);
} else if (version >= 2 && version <= 4) {
testAllMessageRoundTripsBetweenVersions(version, (short) 5, requestData, requestData);
} else {
testAllMessageRoundTripsFromVersion(version, requestData);
}
}
}
use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic in project kafka by apache.
the class OffsetCommitRequestTest method setUp.
@BeforeEach
public void setUp() {
topics = Arrays.asList(new OffsetCommitRequestTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpoch).setCommittedMetadata(metadata))), new OffsetCommitRequestTopic().setName(topicTwo).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partitionTwo).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpoch).setCommittedMetadata(metadata))));
data = new OffsetCommitRequestData().setGroupId(groupId).setTopics(topics);
}
use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic in project kafka by apache.
the class AlterConsumerGroupOffsetsHandler method buildRequest.
@Override
public OffsetCommitRequest.Builder buildRequest(int coordinatorId, Set<CoordinatorKey> groupIds) {
validateKeys(groupIds);
Map<String, OffsetCommitRequestTopic> offsetData = new HashMap<>();
offsets.forEach((topicPartition, offsetAndMetadata) -> {
OffsetCommitRequestTopic topic = offsetData.computeIfAbsent(topicPartition.topic(), key -> new OffsetCommitRequestTopic().setName(topicPartition.topic()));
topic.partitions().add(new OffsetCommitRequestPartition().setCommittedOffset(offsetAndMetadata.offset()).setCommittedLeaderEpoch(offsetAndMetadata.leaderEpoch().orElse(-1)).setCommittedMetadata(offsetAndMetadata.metadata()).setPartitionIndex(topicPartition.partition()));
});
OffsetCommitRequestData data = new OffsetCommitRequestData().setGroupId(groupId.idValue).setTopics(new ArrayList<>(offsetData.values()));
return new OffsetCommitRequest.Builder(data);
}
Aggregations