How to Use Spring Cloud Alibaba Sidecar to Integrate Go Services with Spring Boot
This guide explains how Spring Cloud Alibaba Sidecar enables zero‑intrusion integration of Go services into a Spring Cloud ecosystem, covering module setup, Maven dependency, YAML configuration, sample Go code, and testing with a Nacos‑based consumer.
Spring Cloud Alibaba Sidecar Introduction
Since version Spring Cloud Alibaba 2.1.1, the spring-cloud-alibaba-sidecar module acts as a proxy service allowing other‑language services to use Spring Cloud Alibaba components. It routes through the gateway, enabling service discovery and indirect calls via Ribbon.
As shown, a Spring Cloud application requests the sidecar, which forwards to modules written in other languages with zero intrusion, without needing to register directly with Nacos or other registries.
Getting Started
Build an Interface Service in Another Language
Create a simple service interface in Go.
Endpoint:
http://127.0.0.1:8089/sidecar package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/sidecar", sidecar)
http.HandleFunc("/health", health)
log.Fatal(http.ListenAndServe(":8089", nil))
}
func sidecar(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, "hello spring cloud alibaba sidecar")
}
func health(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
actuator := make(map[string]string)
actuator["status"] = "UP"
_ = json.NewEncoder(w).Encode(actuator)
}Build the Sidecar Application
Add the sidecar dependency.
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sidecar</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>Configure application.yml .
server:
port: 8088
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
application:
name: go-provider
# Configure heterogeneous service
sidecar:
ip: localhost
port: 8089
health-check-url: http://localhost:8089/healthBuild the Nacos Consumer Application
Configure application.yml .
server:
port: 8087
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
application:
name: nacos-consumerConsumer logic.
@RestController
@EnableDiscoveryClient
@SpringBootApplication
public class NacosConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(NacosConsumerApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Autowired
private RestTemplate restTemplate;
@GetMapping("/test")
public String test() {
return restTemplate.getForObject("http://go-provider/sidecar", String.class);
}
}Testing
Call the Spring Cloud consumer application: curl http://localhost:8087/test Output from the Go provider application:
hello spring cloud alibaba sidecarSigned-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.
