今天看啥  ›  专栏  ›  一起成为全栈工程师

Springcloud集成Sidecar实现跨语言微服务调用

一起成为全栈工程师  · 简书  ·  · 2019-08-07 21:02
什么是Sidecar

项目大了, 团队中除了Java, 可以还会有其他语言的后端工程师, 这个时候我们就会有一个需求,那就是能否在非Java语言做的项目整合到我们基于Springcloud的微服务项目中来, 为解决这个问题, Springcloud推出来Sidecar

Sidecar怎么使用
  • 添加依赖
// sidecar项目也是一个eureka-client
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-sidecar</artifactId>
    <version>2.1.1.RELEASE</version>
</dependency>
  • application.yml配置
spring:
  application:
    name: node-sidecar
server:
  port: 8767
eureka:
  client:
    service-url:
      # eureka服务端地址
      defaultZone: http://localhost:8761/eureka/
sidecar:
  port: 9001
  // 在你的非java语言提供一个接口, 接口返回值{"status":"UP"}
  health-uri: 非Java项目提供的接口地址
Springboot项目启动类
@SpringBootApplication
@EnableSidecar
public class SidecarApplication {
    public static void main(String[] args) {
        SpringApplication.run(SidecarApplication.class, args);
    }
}

到这里项目就配置好了, 你的非Java项目现在就可以像Java项目一样为微服务提供服务了
有不懂的记得留言哦!!!




原文地址:访问原文地址
快照地址: 访问文章快照