集群同步-》同步消费位点
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.xuxd.kafka.console.beans.dto;
|
||||
|
||||
import java.util.Properties;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-10-24 23:10:47
|
||||
**/
|
||||
@Data
|
||||
public class SyncDataDTO {
|
||||
|
||||
private String address;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String topic;
|
||||
|
||||
private Properties properties = new Properties();
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import kafka.console.ConfigConsole;
|
||||
import kafka.console.ConsumerConsole;
|
||||
import kafka.console.KafkaAclConsole;
|
||||
import kafka.console.KafkaConfigConsole;
|
||||
import kafka.console.OperationConsole;
|
||||
import kafka.console.TopicConsole;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,4 +48,10 @@ public class KafkaConfiguration {
|
||||
public ConfigConsole configConsole(KafkaConfig config) {
|
||||
return new ConfigConsole(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OperationConsole operationConsole(KafkaConfig config, TopicConsole topicConsole,
|
||||
ConsumerConsole consumerConsole) {
|
||||
return new OperationConsole(config, topicConsole, consumerConsole);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,4 +111,9 @@ public class ConsumerController {
|
||||
public Object getGroupIdList() {
|
||||
return consumerService.getGroupIdList();
|
||||
}
|
||||
|
||||
@GetMapping("/topic/list")
|
||||
public Object getSubscribeTopicList(@RequestParam String groupId) {
|
||||
return consumerService.getSubscribeTopicList(groupId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.xuxd.kafka.console.controller;
|
||||
|
||||
import com.xuxd.kafka.console.beans.dto.SyncDataDTO;
|
||||
import com.xuxd.kafka.console.service.OperationService;
|
||||
import org.apache.kafka.clients.admin.AdminClientConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-10-24 23:13:28
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/op")
|
||||
public class OperationController {
|
||||
|
||||
@Autowired
|
||||
private OperationService operationService;
|
||||
|
||||
@PostMapping("/sync/consumer/offset")
|
||||
public Object syncConsumerOffset(@RequestBody SyncDataDTO dto) {
|
||||
dto.getProperties().put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, dto.getAddress());
|
||||
return operationService.syncConsumerOffset(dto.getGroupId(), dto.getTopic(), dto.getProperties());
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,6 @@ public interface ConsumerService {
|
||||
ResponseData resetPartitionToTargetOffset(String groupId, TopicPartition partition, long offset);
|
||||
|
||||
ResponseData getGroupIdList();
|
||||
|
||||
ResponseData getSubscribeTopicList(String groupId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xuxd.kafka.console.service;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-10-24 23:12:43
|
||||
**/
|
||||
public interface OperationService {
|
||||
|
||||
ResponseData syncConsumerOffset(String groupId, String topic, Properties thatProps);
|
||||
}
|
||||
@@ -138,4 +138,8 @@ public class ConsumerServiceImpl implements ConsumerService {
|
||||
Set<String> stateGroup = consumerConsole.getConsumerGroupIdList(null);
|
||||
return ResponseData.create().data(stateGroup).success();
|
||||
}
|
||||
|
||||
@Override public ResponseData getSubscribeTopicList(String groupId) {
|
||||
return ResponseData.create().data(consumerConsole.listSubscribeTopics(groupId).keySet()).success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.service.OperationService;
|
||||
import java.util.Properties;
|
||||
import kafka.console.OperationConsole;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import scala.Tuple2;
|
||||
|
||||
/**
|
||||
* kafka-console-ui.
|
||||
*
|
||||
* @author xuxd
|
||||
* @date 2021-10-24 23:12:54
|
||||
**/
|
||||
@Service
|
||||
public class OperationServiceImpl implements OperationService {
|
||||
|
||||
@Autowired
|
||||
private OperationConsole operationConsole;
|
||||
|
||||
@Override public ResponseData syncConsumerOffset(String groupId, String topic, Properties thatProps) {
|
||||
|
||||
Tuple2<Object, String> tuple2 = operationConsole.syncConsumerOffset(groupId, topic, thatProps);
|
||||
|
||||
return (boolean) tuple2._1() ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user