You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-cloud-alibaba/spring-cloud-alibaba-examples/spring-cloud-alibaba-sideca...
YuLuo 2530f0400a
Updated yml format in 2.2.x branch (#3100)
Updated yml format in 2.2.x branch
2 years ago
..
spring-cloud-alibaba-sidecar-consul-example Update pom.xml 5 years ago
spring-cloud-alibaba-sidecar-nacos-example Updated yml format in 2.2.x branch (#3100) 2 years ago
node-service.js add module Spring Cloud Alibaba Sidecar 5 years ago
readme-zh.md docs:polished the readme docs 2 years ago
readme.md fix: spring-cloud-alibaba-examples grammar from branch 2.2.x (#2793) 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

  1. Download Nacos and unzip it.

  2. Startup Name Server

startup.cmd -m standalone
  1. Sign in Nacos

    Open you browser then input localhost:8848/nacos ,you can see the Nacos dashboard ui . The default username and password are nacos

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 services 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. idea.png

Step4: View service registration

nacos.png

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.