Backend Development 8 min read

Mastering Spring Cloud Alibaba Sidecar: Integrate Heterogeneous Microservices Seamlessly

This guide explains how to use Spring Cloud Alibaba Sidecar to integrate heterogeneous microservices, covering its principles, configuration, health‑check setup, and a complete hands‑on example with Spring Boot services, Sidecar registration, Nacos discovery, and RestTemplate calls, while guaranteeing permanent updates for subscribers.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Mastering Spring Cloud Alibaba Sidecar: Integrate Heterogeneous Microservices Seamlessly

Environment: Spring Boot 2.7.18 + Spring Cloud Alibaba Sidecar.

1. Introduction

Spring Cloud Alibaba Sidecar (SCA Sidecar) integrates heterogeneous microservices, solving compatibility and communication issues in microservice architectures. Typical scenarios include:

Multi‑language microservice integration.

Cross‑platform service integration.

Service governance and monitoring (registration, discovery, load balancing, circuit breaking, unified logging).

Legacy project integration without a full registry like Nacos.

2. Sidecar Principle

SCA Sidecar registers the IP/port of the heterogeneous service to the service‑discovery component.

It performs health checks; if the target service becomes unhealthy, the Sidecar instance is deregistered, and re‑registered when health is restored.

3. Practical Example

3.1 Prepare the heterogeneous service

For simplicity we use a Spring Boot project as the target service.

Business API:

<code>@RestController
@RequestMapping("/users")
public class UsersController {
    @GetMapping("normal")
    public Object index() {
        return "正常请求";
    }
}
</code>

Health‑check API (required when sidecar.health‑check‑url is configured):

<code>@RestController
@RequestMapping("/health")
public class HealthController {
    @GetMapping("")
    public Object health() {
        System.out.println("服务状态...");
        Map<String, Object> status = new HashMap<>();
        status.put("status", "UP");
        return status;
    }
}
</code>

Configuration (application.properties):

<code>server.port=8080
</code>

3.2 Prepare the Sidecar service

Add dependency:

<code>&lt;dependency&gt;
    &lt;groupId&gt;com.alibaba.cloud&lt;/groupId&gt;
    &lt;artifactId&gt;spring-cloud-starter-alibaba-sidecar&lt;/artifactId&gt;
&lt;/dependency&gt;
</code>

Service configuration (application.yml):

<code>spring:
  application:
    name: pack-car
---
spring:
  cloud:
    nacos:
      server-addr: localhost:8848
      username: nacos
      password: xxxooo
      discovery:
        enabled: true
        group: cloudApp
---
management:
  health:
    sidecar:
      enabled: true
---
sidecar:
  ip: localhost
  port: 8088
  health-check-interval: 5000
  health-check-url: http://${sidecar.ip}:${sidecar.port}/health
</code>

Note: The Nacos discovery address and port are overridden by the Sidecar configuration.

3.3 Call the heterogeneous service

Register another Spring Boot service (e.g., myapp) to Nacos and configure a load‑balanced RestTemplate:

<code>@Bean
@LoadBalanced
RestTemplate lbRestTemplate(RestTemplateBuilder builder) {
    return builder.build();
}
</code>

Use RestTemplate to invoke the heterogeneous service:

<code>@Resource
private RestTemplate lbRestTemplate;

@GetMapping("/lb")
@ResponseBody
public Object lb() {
    return lbRestTemplate.getForObject("http://pack-car/users/normal", String.class);
}
</code>

Running the Sidecar, the heterogeneous service, and the consumer service shows successful registration in Nacos and successful request responses.

Thus, the Sidecar pattern enables seamless integration of heterogeneous systems without modifying the legacy service code.

MicroservicesService DiscoveryNacosSpring BootSpring Cloud AlibabaSidecar
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

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.