|
49 | 49 | import org.apache.kafka.clients.admin.DescribeClusterOptions; |
50 | 50 | import org.apache.kafka.clients.admin.DescribeClusterResult; |
51 | 51 | import org.apache.kafka.clients.admin.DescribeConfigsOptions; |
| 52 | +import org.apache.kafka.clients.admin.ListConsumerGroupOffsetsOptions; |
52 | 53 | import org.apache.kafka.clients.admin.ListConsumerGroupOffsetsSpec; |
53 | 54 | import org.apache.kafka.clients.admin.ListOffsetsResult; |
54 | 55 | import org.apache.kafka.clients.admin.ListTopicsOptions; |
|
74 | 75 | import org.apache.kafka.common.errors.ClusterAuthorizationException; |
75 | 76 | import org.apache.kafka.common.errors.GroupIdNotFoundException; |
76 | 77 | import org.apache.kafka.common.errors.GroupNotEmptyException; |
| 78 | +import org.apache.kafka.common.errors.GroupSubscribedToTopicException; |
77 | 79 | import org.apache.kafka.common.errors.InvalidRequestException; |
78 | 80 | import org.apache.kafka.common.errors.SecurityDisabledException; |
79 | 81 | import org.apache.kafka.common.errors.TopicAuthorizationException; |
@@ -436,6 +438,23 @@ public Mono<Void> deleteConsumerGroups(Collection<String> groupIds) { |
436 | 438 | th -> Mono.error(new IllegalEntityStateException("The group is not empty"))); |
437 | 439 | } |
438 | 440 |
|
| 441 | + public Mono<Void> deleteConsumerGroupOffsets(String groupId, String topicName) { |
| 442 | + return listConsumerGroupOffsets(List.of(groupId), null) |
| 443 | + .flatMap(table -> { |
| 444 | + // filter TopicPartitions by topicName |
| 445 | + Set<TopicPartition> partitions = table.row(groupId).keySet().stream() |
| 446 | + .filter(tp -> tp.topic().equals(topicName)) |
| 447 | + .collect(Collectors.toSet()); |
| 448 | + return toMono(client.deleteConsumerGroupOffsets(groupId, partitions).all()); |
| 449 | + }) |
| 450 | + .onErrorResume(GroupIdNotFoundException.class, |
| 451 | + th -> Mono.error(new NotFoundException("The group id does not exist"))) |
| 452 | + .onErrorResume(UnknownTopicOrPartitionException.class, |
| 453 | + th -> Mono.error(new NotFoundException("The topic or partition is unknown"))) |
| 454 | + .onErrorResume(GroupSubscribedToTopicException.class, |
| 455 | + th -> Mono.error(new IllegalEntityStateException("The group is not empty"))); |
| 456 | + } |
| 457 | + |
439 | 458 | public Mono<Void> createTopic(String name, |
440 | 459 | int numPartitions, |
441 | 460 | @Nullable Integer replicationFactor, |
|
0 commit comments