Govern Service is a lightweight, low-cost service registration, service discovery, and configuration service SDK. By using Redis in the existing infrastructure (I believe you have already deployed Redis), there is no need to bring extra to the operation and maintenance deployment Cost and burden. With the high performance of Redis, Govern Service provides ultra-high TPS&QPS. Govern Service combines the local process caching strategy + Redis PubSub to achieve real-time process cache refresh, with unparalleled QPS performance and real-time consistency between process caching and Redis.

Service discovery

  • maven depends on, the following inter-service calls also need to add spring-cloud-starter-loadbalancer
<dependency>
    <groupId>me.ahoo.govern</groupId>
    <artifactId>spring-cloud-starter-discovery</artifactId>
</dependency>

Service provider

  • Service provider interface
public class DemoController {

    @GetMapping("/get")
    public String demo() {
        return "hello provider";
    }
}
  • application.yml configuration file, specify the redis address
spring:
  cloud:
    govern:
      redis:
        mode: standalone
        url: redis://127.0.0.1:6379
  application:
    name: provider

Service consumer

  • application.yml configuration file, specify the redis address
spring:
  cloud:
    govern:
      redis:
        mode: standalone
        url: redis://127.0.0.1:6379
  application:
    name: consumer
  • Interface call demo
public class DemoController {
    private final RestTemplate restTemplate;

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

Call test

curl http://localhost:8090

hello world

Configuration management

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

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

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

}
  • New configuration management

to sum up

  • The author uses the infrastructure redis as the registration and configuration center to realize microservice registration discovery and configuration management based on the Spring Cloud Commons standard. The source code of Govern Service is very concise, which is very helpful for beginners to learn and refer to the Spring Cloud core source code design.
  • During the Spring Festival, the author implemented a set of pig-mesh based on Spring Cloud Commons during the Spring Festival, which basically realized all the Spring Cloud abstractions (service discovery, configuration management, load balancing, language heterogeneity), which can be studied together with Govern Service.

冷冷
300 声望87 粉丝