注册中心配置

本篇将介绍如何将网关实例注册到注册中心。Apache ShenYu 网关目前支持注册到 zookeeperetcd

添加Maven依赖

首先,在网关的 pom.xml 文件中引入如下依赖。

  1. <!--shenyu instance start-->
  2. <dependency>
  3. <groupId>org.apache.shenyu</groupId>
  4. <artifactId>shenyu-spring-boot-starter-instance</artifactId>
  5. <version>${project.version}</version>
  6. </dependency>
  7. <!--shenyu instance end-->

使用zookeeper

在网关的 yml 文件中添加如下配置:

  1. instance:
  2. enabled: true
  3. registerType: zookeeper
  4. serverLists: localhost:2181 #配置成你的 zookeeper 地址,集群环境请使用(,)分隔
  5. props:
  6. sessionTimeout: 3000 #可选,默认3000
  7. connectionTimeout: 3000 #可选,默认3000

使用etcd

在网关的 yml 文件中添加如下配置:

  1. instance:
  2. enabled: true
  3. registerType: etcd
  4. serverLists: http://localhost:2379 #配置成你的 etcd 地址,集群环境请使用(,)分隔。
  5. props:
  6. etcdTimeout: 3000 #可选,默认3000
  7. etcdTTL: 5 #可选,默认5

配置完成后,启动网关,就会成功注册到相应注册中心。