用户工具

站点工具


light4j:registry

这是本文档旧的修订版!


Registry and Discovery

java -jar light-codegen/codegen-cli/target/codegen-cli.jar -f openapi -o light-example-4j/discovery/api_a/generated -m model-config/rest/openapi/aa/1.0.0/openapi.yaml -c model-config/rest/openapi/aa/1.0.0/config.json
java -jar light-codegen/codegen-cli/target/codegen-cli.jar -f openapi -o light-example-4j/discovery/api_b/generated -m model-config/rest/openapi/ab/1.0.0/openapi.yaml -c model-config/rest/openapi/ab/1.0.0/config.json
java -jar light-codegen/codegen-cli/target/codegen-cli.jar -f openapi -o light-example-4j/discovery/api_c/generated -m model-config/rest/openapi/ac/1.0.0/openapi.yaml -c model-config/rest/openapi/ac/1.0.0/config.json
java -jar light-codegen/codegen-cli/target/codegen-cli.jar -f openapi -o light-example-4j/discovery/api_d/generated -m model-config/rest/openapi/ad/1.0.0/openapi.yaml -c model-config/rest/openapi/ad/1.0.0/config.json
mvn clean install exec:exec
curl -k https://localhost:7441/v1/data #4个应用监听7441-7444端口
  • 直连配置:static、dynamic,multiple
    1. api_a:api_a.yml,a ⇒ b+c,/v1/data@get =》DataGetHandler
    2. api_c:c ⇒ d,Http2Client.connect(https://localhost:7444),ClientRequest(/v1/data@get)
    3. Cluster:SingletonServiceFactory.getBean(Cluster.class).serviceToUrl(“https”, serviceId, tag, null)
    4. parameters:配置服务映射地址,tag=ServerConfig.environment(仅用于注册中心+测试环境,通常null即可)
singletons:
  - com.networknt.registry.URL:
      - com.networknt.registry.URLImpl:
          parameters:
            com.networknt.ab-1.0.0: https://localhost:7442
            com.networknt.ac-1.0.0: https://localhost:7443
            #com.networknt.ad-1.0.0: https://localhost:7444,https://localhost:7445 #multiple示例
  - com.networknt.registry.Registry: #直连
      - com.networknt.registry.support.DirectRegistry
  - com.networknt.balance.LoadBalance:  #均衡和集群是类似的
      - com.networknt.balance.RoundRobinLoadBalance
  - com.networknt.cluster.Cluster:
      - com.networknt.cluster.LightCluster
  • 注册中心:consul,ServerConfig.enableRegistry=true
- com.networknt.registry.URL:
  - com.networknt.registry.URLImpl:
      protocol: light
      host: localhost
      port: 8080
      path: consul
      parameters:
        registryRetryPeriod: '30000'
- com.networknt.consul.client.ConsulClient:
  - com.networknt.consul.client.ConsulClientImpl
- com.networknt.registry.Registry:
  - com.networknt.consul.ConsulRegistry
#docker run -d -p 8400:8400 -p 8500:8500/tcp -p 8600:53/udp -e 'CONSUL_LOCAL_CONFIG={"acl_datacenter":"dc1","acl_default_policy":"allow","acl_down_policy":"extend-cache","acl_master_token":"the_one_ring","bootstrap_expect":1,"datacenter":"dc1","data_dir":"/usr/local/bin/consul.d/data","server":true}' consul agent -server -ui -bind=127.0.0.1 -client=0.0.0.0
#http://localhost:8500/ui #查看已注册服务
light4j/registry.1594287355.txt.gz · 最后更改: 2020/07/09 17:35 由 admin