Data Synchronization Config
This document focuses on how to use different data synchronization strategies. Data synchronization refers to the strategy used to synchronize data to ShenYu gateway after shenyu-admin background operation data. ShenYu gateway currently supports ZooKeeper, WebSocket, HTTP Long Polling, Nacos, Etcd and Consul for data synchronization.
For details about the data synchronization principles, see Data Synchronization Design in the design document.
#
WebSocket Synchronization Config(default strategy, recommend)Apache ShenYu
gateway configAdd these dependencies in
pom.xml
:
<!-- apache shenyu data sync start use websocket--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-sync-data-websocket</artifactId> <version>${project.version}</version> </dependency>
Add these config values in yaml file:
shenyu: sync: websocket : # urls: address of shenyu-admin,multi-address will be separated with (,). urls: ws://localhost:9095/websocket allowOrigin: ws://localhost:9195
shenyu-admin
configAdd these config values in yaml file:
shenyu: sync: websocket: enabled: true
After the connection is established, the data will be fully obtained once, and the subsequent data will be updated and added increments, with good performance. It also supports disconnection (default: 30
seconds). This mode is recommended for data synchronization and is the default data synchronization strategy of ShenYu.
#
Zookeeper Synchronization ConfigApache ShenYu
gateway configAdd these dependencies in
pom.xml
:<!-- apache shenyu data sync start use zookeeper--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-sync-data-zookeeper</artifactId> <version>${project.version}</version> </dependency>
Add these config values in yaml file:
shenyu: sync: zookeeper: url: localhost:2181 #url: config with your zk address, used by the cluster environment, separated with (,). sessionTimeout: 5000 connectionTimeout: 2000
shenyu-admin
config
Add these config values in yaml file:
shenyu: sync: zookeeper: url: localhost:2181 #url: config with your zk address, used by the cluster environment, separated with (,). sessionTimeout: 5000 connectionTimeout: 2000
It is a good idea to use ZooKeeper synchronization mechanism with high timeliness, but we also have to deal with the unstable environment of ZK, cluster brain splitting and other problems.
#
HTTP Long Polling Synchronization ConfigApache ShenYu
gateway config
Add these dependencies in pom.xml
:
<!-- apache shenyu data sync start use http--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-sync-data-http</artifactId> <version>${project.version}</version> </dependency>
Add these config values in yaml file:
shenyu: sync: http: url: http://localhost:9095 #url: config your shenyu-admin ip and port,cluster IP by split by (,)
shenyu-admin
configAdd these config values in yaml file:
shenyu: sync: http: enabled: true
HTTP long-polling makes the gateway lightweight, but less time-sensitive. It pulls according to the group key, if the data is too large, it will have some influences, a small change under a group will pull the entire group.
#
Nacos Synchronization ConfigApache ShenYu
gateway config
Add these dependencies in pom.xml
:
<!-- apache shenyu data sync start use nacos--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-sync-data-nacos</artifactId> <version>${project.version}</version> </dependency>
Add these config values in yaml file:
shenyu: sync: nacos: url: localhost:8848 # url: config with your nacos address, please use (,) to split your cluster environment. namespace: 1c10d748-af86-43b9-8265-75f487d20c6c username: password: acm: enabled: false endpoint: acm.aliyun.com namespace: accessKey: secretKey: # other configure,please refer to the naocs website.
shenyu-admin
configAdd these config values in yaml file:
shenyu: sync: nacos: url: localhost:8848 namespace: 1c10d748-af86-43b9-8265-75f487d20c6c username: password: acm: enabled: false endpoint: acm.aliyun.com namespace: accessKey: secretKey: # url: config with your nacos address, pls use (,) to split your cluster environment. # other configure,pls refer to the naocs website.
#
Etcd Synchronization ConfigApache ShenYu
gateway configAdd these dependencies in
pom.xml
:
<!-- apache shenyu data sync start use etcd--> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-sync-data-etcd</artifactId> <version>${project.version}</version> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>grpc-grpclb</artifactId> </exclusion> <exclusion> <groupId>io.grpc</groupId> <artifactId>grpc-netty</artifactId> </exclusion> </exclusions> </dependency>
Add these config values in yaml file:
shenyu: sync: etcd: url: http://localhost:2379 #url: config with your etcd address, used by the cluster environment, separated with (,).
shenyu-admin
configAdd these config values in yaml file:
shenyu: sync: etcd: url: http://localhost:2379 #url: config with your etcd address, used by the cluster environment, separated with (,).
#
Consul Synchronization ConfigApache ShenYu
gateway config
Add these dependencies in pom.xml
:
<!-- apache shenyu data sync start use consul--><dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-sync-data-consul</artifactId> <version>${project.version}</version></dependency>
Add these config values in yaml file:
shenyu: sync: consul: url: http://localhost:8500 waitTime: 1000 # query wait time watchDelay: 1000 # Data synchronization interval
shenyu-admin
configAdd these config values in yaml file:
shenyu: sync: consul: url: http://localhost:8500
After the data synchronization strategy of Apache ShenYu gateway and shenyu-admin is reconfigured, the microservice needs to be restarted.
the Apache ShenYu gateway and shenyu-admin must use the same synchronization strategy.