11d6cf90bf
* fix spring-cloud-alibaba-examples grammar * fix 地 => 的 * fix 地 => 的 and to => the * fix |
2 years ago | |
---|---|---|
.. | ||
spring-cloud-alibaba-sidecar-consul-example | 5 years ago | |
spring-cloud-alibaba-sidecar-nacos-example | 5 years ago | |
node-service.js | 5 years ago | |
readme-zh.md | 2 years ago | |
readme.md | 2 years ago |
readme.md
Spring Cloud Alibaba Sidecar Example
Project Instruction
This project demonstrates how to use Nacos + Spring Cloud Alibaba Sidecar
to access heterogeneous language microservices.
Spring Cloud Alibaba Sidecar is a framework for fast and seamless integration of Spring Cloud with heterogeneous language microservices.
Preparation
Download and Startup Nacos
You should startup Nacos Server before using Sidecar
-
Download Nacos and unzip it.
-
Startup Name Server
startup.cmd -m standalone
-
Sign in Nacos
Open you browser then input
localhost:8848/nacos
,you can see the Nacos dashboard ui . The default username and password arenacos
Simple example
In this paper, Sidecar accesses a non-Java language service using Nacos as a registry as an example.
Step1: Declare dependency
Add dependency spring-cloud-starter-alibaba-sidecar to the pom.xml
file in your Sidecar project.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sidecar</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
Step2: Configure sidecar
Then add necessary configurations to file /src/main/resources/application.yml
.
server:
port: 8070
spring:
cloud:
nacos:
username: nacos
password: nacos
discovery:
server-addr: 127.0.0.1:8848
group: test
gateway:
discovery:
locator:
enabled: true
application:
name: node-service
sidecar:
# heterogeneous service‘s ip
ip: 127.0.0.1
# heterogeneous service's port
port: 8060
# heterogeneous service's health check URL
health-check-url: http://localhost:8060/health.json
Note: localhost:8060
here, is my local machine started a nginx proxy for this health.json
request. In actual use it can be any REST service, just need to return the correct JSON format health detection data.
{
"status": "DOWN"
}
Step3: Start Application
After that, start the Sidecar
service and the local heterogeneous service respectively.
Start in IDE: Find main class com.alibaba.cloud.sidecar.DemoApplication
, and execute the main method.
Note: This article takes the spring-cloud-alibaba-sidecar-nacos-example
project as an example, so it starts the DemoApplication
startup class under it.
Step4: View service registration
Step4: Accessing services
After completing the above 4 steps, we find that the corresponding service node-service
has been successfully registered to the registry. At this point, the service has been successfully integrated into the Spring Cloud microservice. For Spring Cloud microservices, accessing it is no different from accessing any other Java microservice.
This is where the beauty of Spring Cloud Alibaba Sidecar comes in. Next, we will continue to demonstrate how to access this service.
Browser Access below address: http://127.0.0.1:8070/node-service/health.json If you see the following message, the access was successful.
More
If you have any ideas or suggestions for Spring Cloud Alibaba Sidecar
, please don't hesitate to tell us by submitting GitHub issues.