重置消费位点

This commit is contained in:
许晓东
2021-10-22 19:58:27 +08:00
parent 36bb140c79
commit e0e8e027d8
6 changed files with 114 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Set;
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
import org.apache.kafka.common.ConsumerGroupState;
import org.apache.kafka.common.TopicPartition;
/**
* kafka-console-ui.
@@ -25,4 +26,6 @@ public interface ConsumerService {
ResponseData addSubscription(String groupId, String topic);
ResponseData resetOffsetToEndpoint(String groupId, String topic, OffsetResetStrategy strategy);
ResponseData resetPartitionToTargetOffset(String groupId, TopicPartition partition, long offset);
}

View File

@@ -21,6 +21,7 @@ import org.apache.kafka.clients.admin.ConsumerGroupDescription;
import org.apache.kafka.clients.admin.MemberDescription;
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
import org.apache.kafka.common.ConsumerGroupState;
import org.apache.kafka.common.TopicPartition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scala.Tuple2;
@@ -127,4 +128,9 @@ public class ConsumerServiceImpl implements ConsumerService {
Tuple2<Object, String> tuple2 = consumerConsole.resetOffsetToEndpoint(groupId, topic, strategy);
return (boolean) tuple2._1() ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2());
}
@Override public ResponseData resetPartitionToTargetOffset(String groupId, TopicPartition partition, long offset) {
Tuple2<Object, String> tuple2 = consumerConsole.resetPartitionToTargetOffset(groupId, partition, offset);
return (boolean) tuple2._1() ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2());
}
}