Support redis cluster

This commit is contained in:
hongqiaowei
2022-07-06 10:26:19 +08:00
parent 6c81977f4d
commit 825959e5d6
4 changed files with 26 additions and 20 deletions

View File

@@ -4,18 +4,16 @@
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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.13.RELEASE</version>
<relativePath/>
<artifactId>fizz-gateway-community</artifactId>
<groupId>com.fizzgate</groupId>
<version>2.6.6-beta1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.fizzgate</groupId>
<artifactId>fizz-bootstrap</artifactId>
<version>2.6.6-beta1</version>
<properties>
<java.version>1.8</java.version>
<!--<java.version>1.8</java.version>
<spring-framework.version>5.2.22.RELEASE</spring-framework.version>
<spring-session-bom.version>Dragonfruit-SR3</spring-session-bom.version>
<reactor-bom.version>Dysprosium-SR25</reactor-bom.version>
@@ -37,15 +35,15 @@
<netty-tcnative.version>2.0.53.Final</netty-tcnative.version>
<spring-cloud.version>2.2.9.RELEASE</spring-cloud.version>
<snakeyaml.version>1.30</snakeyaml.version>
<spring-data-releasetrain.version>Moore-SR13</spring-data-releasetrain.version>
<spring-data-releasetrain.version>Moore-SR13</spring-data-releasetrain.version>-->
</properties>
<dependencies>
<dependency>
<!--<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.4</version>
</dependency>
</dependency>-->
<dependency>
<groupId>com.fizzgate</groupId>
@@ -65,7 +63,7 @@
<version>${project.version}</version>
</dependency> -->
<dependency>
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>${spring-cloud.version}</version>
@@ -92,7 +90,7 @@
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.1</version>
</dependency>
</dependency>-->
</dependencies>
<profiles>
@@ -145,6 +143,8 @@
<include>application.yml</include>
<include>bootstrap.yml</include>
<include>log4j2-spring.xml</include>
<include>log4j2-kafka.json</include>
<include>log4j2.component.properties</include>
<filtering>true</filtering>
</resource>
</resources>

View File

@@ -51,6 +51,7 @@ spring:
# Must use the same Redis as fizz-manager
aggregate:
redis:
# standalone redis config
# need replace
host: 1.1.1.1 #please input the redis host (default:localhost)
# need replace
@@ -59,6 +60,12 @@ aggregate:
password: 123456 #please input the redis password (default:123456)
# need replace
database: 10 #please input the redis database (default:9)
# redis cluster config
# type: cluster # type can be standalone or cluster, standalone is default
# password: 123456
# clusterNodes: 172.1.1.181:7001,172.1.1.181:7002,172.1.1.181:7003,172.1.1.182:7001,172.1.1.182:7002,172.1.1.182:7003
proxy-webclient:
name: proxy
trust-insecure-SSL: false

View File

@@ -29,7 +29,6 @@ import java.security.SecureRandom;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
/**
@@ -38,7 +37,7 @@ import java.util.Set;
public class NetworkUtils {
private static final Logger log = LoggerFactory.getLogger(NetworkUtils.class);
private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
private static final int maxServerId = 1023;
@@ -50,13 +49,13 @@ public class NetworkUtils {
private static final String SERVER_IP = "SERVER_IP";
private static final String LOCAL_IP = "127.0.0.1";
private static final String LOCAL_IP = "127.0.0.1";
private NetworkUtils() {
}
/**
* @return user settings, or the first non local IP of IP address list.
* @return user settings, or the first non-local IP of IP address list.
*/
public static String getServerIp() {
if (serverIp == null) {
@@ -98,7 +97,7 @@ public class NetworkUtils {
} else {
serverIps.add(ip);
}
log.info("server ip: {}", serverIps);
LOGGER.info("server ip: {}", serverIps);
} catch (SocketException | UnknownHostException e) {
throw new RuntimeException(e);
}
@@ -123,10 +122,10 @@ public class NetworkUtils {
serverId = b.toString().hashCode();
} catch (Exception e) {
serverId = (new SecureRandom().nextInt());
log.error(null, e);
LOGGER.error(null, e);
}
serverId = serverId & maxServerId;
log.info("server id: {}", serverId);
LOGGER.info("server id: {}", serverId);
}
return serverId;
}

View File

@@ -44,7 +44,7 @@
<module>fizz-common</module>
<module>fizz-core</module>
<module>fizz-plugin</module>
<!--<module>fizz-bootstrap</module>-->
<module>fizz-bootstrap</module>
<module>fizz-spring-boot-starter</module>
<!--<module>fizz-input-mysql</module>-->
</modules>