Backend Development 21 min read

Microservice Ecosystem Overview with Spring Cloud Alibaba: Components, Configuration, and Code Examples

This article provides a comprehensive overview of the microservice ecosystem built on Spring Cloud Alibaba, detailing essential modules such as service registration, discovery, load balancing, configuration, messaging, gateway, circuit breaking, distributed tracing, and transaction management, and includes practical code snippets and configuration examples for each component.

Wukong Talks Architecture
Wukong Talks Architecture
Wukong Talks Architecture
Microservice Ecosystem Overview with Spring Cloud Alibaba: Components, Configuration, and Code Examples

In the era of complex internet applications, breaking a monolithic system into independent microservices enables single-responsibility design and vertical scaling, but these services must be connected to realize their full value.

Service registration & discovery : producers register themselves so consumers can locate them via a registry.

Service invocation : multiple protocols (e.g., HTTP) are used for remote calls.

Load balancing : various algorithms select instances in a cluster.

Stability : circuit breaking, rate limiting, degradation.

Distributed configuration : unified management of config with dynamic refresh.

Message queue : async processing to decouple core logic.

Gateway : unified handling of flow control, authentication, routing, etc.

Monitoring & tracing : health checks and distributed link tracing.

Automated deployment : CI/CD for rapid releases.

Spring Cloud Alibaba offers a one‑stop solution for building such a microservice system with minimal Spring annotations and yaml configuration.

1. Spring Boot (service base)

Provides rich annotations, "convention over configuration", and auto‑configuration via Starter and AutoConfiguration , embedding Tomcat/Jetty/Undertow and integrating mainstream open‑source libraries.

2. Nacos (registry & configuration center)

Open‑source naming and configuration service that replaces Eureka, Config, and Bus. Supports Java, Go, Python, C#, C++ clients.

Cluster configuration example (place in nacos/conf/cluster.conf ):

# ip:port
200.8.9.16:8848
200.8.9.17:8848
200.8.9.18:8848

3. RestTemplate + Ribbon (remote call)

Custom load‑balancing rule example:

public class CustomRule extends AbstractLoadBalancerRule {
    private AtomicInteger count = new AtomicInteger(0);
    @Override
    public Server choose(Object key) {
        return choose(getLoadBalancer(), key);
    }
    private Server choose(ILoadBalancer loadBalancer, Object key) {
        List
allServers = loadBalancer.getAllServers();
        int requestNumber = count.incrementAndGet();
        if (requestNumber >= Integer.MAX_VALUE) {
            count = new AtomicInteger(0);
        }
        if (allServers != null) {
            int size = allServers.size();
            if (size > 0) {
                int index = requestNumber % size;
                Server server = allServers.get(index);
                if (server == null || !server.isAlive()) {
                    return null;
                }
                return server;
            }
        }
        return null;
    }
}

Simple RestTemplate usage:

// registered service name
private final String SERVER_URL = "http://nacos-provider-demo";
@Resource
private RestTemplate restTemplate;
@RequestMapping("/hello")
public String hello() {
    return restTemplate.getForObject(SERVER_URL + "/hello", String.class);
}

4. OpenFeign (remote call)

Lightweight HTTP client that embeds Ribbon. Define an interface with @FeignClient :

@FeignClient(value = "${provider.name}")
public interface OrderService {
    @RequestMapping(value = "/create_order", method = RequestMethod.GET)
    String createOrder();
}

Dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

5. Dubbo Spring Cloud (TCP remote call)

Integrates Dubbo into Spring Cloud, offering interface‑based services, multiple registries, and pluggable load‑balancing strategies.

Key configuration items:

dubbo.scan.base-packages = com.example.service
dubbo.protocol.name = dubbo
dubbo.protocol.port = -1
dubbo.registry.address = nacos://127.0.0.1:8848

6. Spring Cloud Gateway (gateway)

Replaces Zuul with a WebFlux‑based gateway offering routing, predicates, and filters.

Sample YAML configuration:

spring:
  cloud:
    gateway:
      routes:
        - id: user_route
          uri: lb://user-server-sample
          order: 1
          predicates:
            - Path=/user/**
          filters:
            - AddRequestHeader=X-Request-token, 12345678

7. Sentinel (circuit breaking, rate limiting, degradation)

Provides flow control, system protection, and fallback mechanisms. Example of a block handler:

// resource name: handle1
@RequestMapping("/handle1")
@SentinelResource(value = "handle1", blockHandler = "blockHandlerTestHandler")
public String handle1(String params) {
    return "success";
}
public String blockHandlerTestHandler(String params, BlockException ex) {
    return "fallback response";
}

8. Seata (distributed transaction)

Supports AT, TCC, SAGA, XA modes. Core components: Transaction Manager (TM), Transaction Coordinator (TC), Resource Manager (RM). Transaction flow: TM creates XID → RM registers branch → TM commits/rolls back via TC.

9. Spring Cloud Stream (asynchronous messaging)

Unified programming model for RabbitMQ, Kafka, RocketMQ, etc.

Define output channel:

public interface CustomSource {
    @Output("output1")
    MessageChannel output1();
}

Send a message:

@Service
public class SendMessageService {
    @Resource
    private CustomSource customSource;
    public String sendMessage() {
        String message = "test message";
        customSource.output1().send(MessageBuilder.withPayload(message).build());
        return "sent";
    }
}

10. SkyWalking (distributed tracing)

APM system for microservices and cloud‑native architectures. Consists of Agent (collects trace data), OAP server (analysis & storage), and UI (visualization). Supports Java, .NET Core, Node.js.

11. XXL‑JOB (distributed task scheduling)

Lightweight scheduler with visual console, fault tolerance, sharding, and retry.

YAML example:

server:
  port: 8082
xxl:
  job:
    admin:
      addresses: http://127.0.0.1:8002/xxl-job-admin
    executor:
      appname: xxl-job-executor-sample
      ip: 127.0.0.1
      port: 9989
      logpath: D:/logs
      logretentiondays: 30

Executor bean initialization:

@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
    XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
    executor.setAdminAddresses(adminAddresses);
    executor.setAppname(appname);
    executor.setIp(ip);
    executor.setPort(port);
    executor.setLogPath(logPath);
    executor.setLogRetentionDays(logRetentionDays);
    return executor;
}

The article concludes that the "Spring Cloud Alibaba Microservice Practice" book provides deeper guidance for building such ecosystems.

MicroservicesLoad BalancingService DiscoveryDistributed Tracingdistributed transactionSpring Cloud Alibabacircuit breaker
Wukong Talks Architecture
Written by

Wukong Talks Architecture

Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.

0 followers
Reader feedback

How this landed with the community

login 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.