Govern Service || 新的服务发现、配置管理实现

2021-05-19  本文已影响0人  冷冷zz

Govern Service 是一个轻量级、低成本的服务注册、服务发现、 配置服务 SDK,通过使用现有基础设施中的 Redis (相信你已经部署了 Redis),不用给运维部署带来额外的成本与负担。 借助于 Redis 的高性能, Govern Service 提供了超高 TPS&QPS。Govern Service 结合本地进程缓存策略 + Redis PubSub,实现实时进程缓存刷新,兼具无与伦比的 QPS 性能、进程缓存与 Redis 的实时一致性。

服务发现

image
<dependency>
    <groupId>me.ahoo.govern</groupId>
    <artifactId>spring-cloud-starter-discovery</artifactId>
</dependency>

服务提供方

public class DemoController {

    @GetMapping("/get")
    public String demo() {
        return "hello provider";
    }
}
spring:
  cloud:
    govern:
      redis:
        mode: standalone
        url: redis://127.0.0.1:6379
  application:
    name: provider

服务消费方

spring:
  cloud:
    govern:
      redis:
        mode: standalone
        url: redis://127.0.0.1:6379
  application:
    name: consumer
public class DemoController {
    private final RestTemplate restTemplate;

    @GetMapping
    public String req() {
        String url = "http://provider/get";
        return restTemplate.getForEntity(url, String.class).getBody();
    }
}

调用测试

curl http://localhost:8090

hello world

配置管理

image
<dependency>
  <groupId>me.ahoo.govern</groupId>
  <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
spring:
  application:
    name: config
  cloud:
    govern:
      config:
        config-id: config.yml
      redis:
        mode: standalone
        url: redis://localhost:6379
@RefreshScope
public class DemoController {

    @Value("${config.key}")
    private String key;

    @GetMapping
    public String demo(){
        return key;
    }

}
image

总结

上一篇 下一篇

猜你喜欢

热点阅读