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.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
How to Build Lightweight Service Discovery & Config with Govern Service and Redis

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: provider

Service Consumer

application.yml – specify Redis address

spring:
  cloud:
    govern:
      redis:
        mode: standalone
        url: redis://127.0.0.1:6379
  application:
    name: consumer

Interface 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 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 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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Microservicesredisservice discoveryConfiguration ManagementSpring Cloud
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.