mirror of
https://gitee.com/shikong-sk/springcloud-study
synced 2024-11-12 19:41:17 +08:00
测试
This commit is contained in:
parent
2bb7c6dc65
commit
4e70a57964
@ -4,10 +4,7 @@ import cn.skcks.study.springcloud.kafka.TestApplication;
|
||||
import cn.skcks.study.springcloud.utils.JsonUtils;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.admin.AdminClient;
|
||||
import org.apache.kafka.clients.admin.DescribeConfigsResult;
|
||||
import org.apache.kafka.clients.admin.ListTopicsOptions;
|
||||
import org.apache.kafka.clients.admin.ListTopicsResult;
|
||||
import org.apache.kafka.clients.admin.*;
|
||||
import org.apache.kafka.common.config.ConfigResource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -16,6 +13,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@ -79,12 +78,21 @@ public class KafkaConfigTest {
|
||||
try (AdminClient client = adminClient()) {
|
||||
ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, TOPIC);
|
||||
DescribeConfigsResult describeConfigsResult = client.describeConfigs(Collections.singletonList(resource));
|
||||
describeConfigsResult.all().get().forEach((key,config) -> {
|
||||
log.info("{} =>",key);
|
||||
describeConfigsResult.all().get().forEach((source, config) -> {
|
||||
log.info("{} =>", source.name());
|
||||
config.entries().forEach(entry -> {
|
||||
log.info("\t{} => {}", entry.name(), entry.value());
|
||||
});
|
||||
});
|
||||
|
||||
Collection<AlterConfigOp> configs = Arrays.asList(
|
||||
new AlterConfigOp(new ConfigEntry("min.cleanable.dirty.ratio", "0.5"), AlterConfigOp.OpType.SET),
|
||||
new AlterConfigOp(new ConfigEntry("unclean.leader.election.enable", "false"), AlterConfigOp.OpType.SET),
|
||||
new AlterConfigOp(new ConfigEntry("retention.ms","86400000"), AlterConfigOp.OpType.SET)
|
||||
);
|
||||
|
||||
AlterConfigsResult result = client.incrementalAlterConfigs(Collections.singletonMap(resource,configs));
|
||||
result.all().get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user