How to Build Lightweight Service Discovery & Config with Govern Service and Redis
This article introduces Govern Service, a low‑cost SDK for service registration, discovery, and configuration built on Redis, and walks through Maven dependencies, provider and consumer implementations, YAML configuration, and configuration management with code examples.
Service Discovery
Maven dependency (add spring-cloud-starter-loadbalancer)
<dependency>
<groupId>me.ahoo.govern</groupId>
<artifactId>spring-cloud-starter-discovery</artifactId>
</dependency>Service Provider
Provider interface
public class DemoController {
@GetMapping("/get")
public String demo() {
return "hello provider";
}
}application.yml – specify Redis address
spring:
cloud:
govern:
redis:
mode: standalone
url: redis://127.0.0.1:6379
application:
name: providerService Consumer
application.yml – specify Redis address
spring:
cloud:
govern:
redis:
mode: standalone
url: redis://127.0.0.1:6379
application:
name: consumerInterface call demonstration
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 worldConfiguration 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:6379Code injection of configuration key
@RefreshScope
public class DemoController {
@Value("${config.key}")
private String key;
@GetMapping
public String demo() {
return key;
}
}Summary
The author uses Redis as a registration and configuration center, implementing Spring Cloud Commons‑based service discovery and configuration management; Govern Service’s source is concise and helpful for beginners studying Spring Cloud core design.
The author also built pig‑mesh , a full implementation of Spring Cloud abstractions (service discovery, configuration, load balancing, language heterogeneity) that can be studied alongside Govern Service.
References
Govern Service: https://github.com/Ahoo-Wang/govern-service
pig‑mesh: https://github.com/pig-mesh/spring-cloud-pig-mesh
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
