fix(forest): 修复加入zookeeper作为备选注册中心后无法使用负载均衡组件
LoadBalance 默认会先夹在 Zookeeper 作为注册中心,导致 Eureka 无法正常使用,如果要使用 Eureka,就要把整个 Zookeeper 的自动加载关掉
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -21,6 +21,7 @@
|
||||
<module>service-dependencies</module>
|
||||
<module>service-cli</module>
|
||||
<module>service-loki-query</module>
|
||||
<module>service-test-query</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
spring:
|
||||
cloud:
|
||||
zookeeper:
|
||||
enabled: false
|
||||
connect-string: 127.0.0.1:2181
|
||||
discovery:
|
||||
enabled: false
|
||||
enabled: ${spring.cloud.zookeeper.enabled}
|
||||
root: /hudi-services
|
||||
instance-host: localhost
|
||||
instance-id: ${spring.application.name}-${spring.cloud.zookeeper.discovery.instance-host}-${random.uuid}-${datetime:19700101}
|
||||
connect-string: 127.0.0.1:2181
|
||||
eureka:
|
||||
instance:
|
||||
hostname: localhost
|
||||
|
||||
41
service-test-query/pom.xml
Normal file
41
service-test-query/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>hudi-service</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.eshore.odcp.hudi.connector</groupId>
|
||||
<artifactId>service-test-query</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>service-dependencies</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>service-configuration</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.lanyuanxiaoyao.service.test;
|
||||
|
||||
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||
import org.springframework.cloud.zookeeper.discovery.LoadBalancerZookeeperAutoConfiguration;
|
||||
|
||||
/**
|
||||
* 启动类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2023-07-12
|
||||
*/
|
||||
@SpringBootApplication(
|
||||
scanBasePackages = {"com.lanyuanxiaoyao.service"},
|
||||
exclude = {GsonAutoConfiguration.class, LoadBalancerZookeeperAutoConfiguration.class}
|
||||
)
|
||||
@EnableDiscoveryClient
|
||||
@EnableEncryptableProperties
|
||||
public class TestApplication implements ApplicationRunner {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TestApplication.class);
|
||||
private final DiscoveryClient discoveryClient;
|
||||
private final LoadBalancerClient loadBalancerClient;
|
||||
|
||||
public TestApplication(DiscoveryClient discoveryClient, LoadBalancerClient loadBalancerClient) {
|
||||
this.discoveryClient = discoveryClient;
|
||||
this.loadBalancerClient = loadBalancerClient;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TestApplication.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
discoveryClient.getInstances("service-hudi-query").forEach(s -> logger.info("Discovery: {}", s));
|
||||
logger.info("LoadBalance: {}", loadBalancerClient.choose("service-hudi-query"));
|
||||
}
|
||||
}
|
||||
11
service-test-query/src/main/resources/application.yml
Normal file
11
service-test-query/src/main/resources/application.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
application:
|
||||
name: service-test-query
|
||||
profiles:
|
||||
include: random-port,common,discovery,metrics
|
||||
cloud:
|
||||
zookeeper:
|
||||
enabled: false
|
||||
jasypt:
|
||||
encryptor:
|
||||
password: r#(R,P"Dp^A47>WSn:Wn].gs/+"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.
|
||||
Reference in New Issue
Block a user