Spring Clould Sidecar整合异构服务

Spring Clould Sidecar整合php接口服务

因公司业务需求,需要将php接口服务注册到eureka中,通过网关统一调用,所以需要使用sidecar实现该功能。

1、新建springboot项目,导入以下包

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <groupId>com.xxxx</groupId>
    <artifactId>portal_news_sidecar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>portal_news_sidecar</name>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-sidecar</artifactId>
        </dependency>
    </dependencies>

2、applicaiton.yml

spring:
  application:
    name: PORTAL-NEWS-SIDECAR  #服务名
server:
  port: 8070 #端口
eureka:
  instance:
    instance-id: ${spring.application.name}:${server.port}
    lease-expiration-duration-in-seconds: 3
    lease-renewal-interval-in-seconds: 3
    preferIpAddress: true
  client:
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://127.0.0.1:3423/eureka
sidecar:
  port: 9998     #异构微服务的端口
  healthUri: http://192.168.100.15:9998/document/uri  #第三方程序提供的标准health接口
  ip-address: 192.168.100.15 #异构微服务的IP地址

sidecar.healthUri 说明
官方译文
在这里插入图片描述
3、在启动类中添加如下注解

@SpringBootApplication
@EnableEurekaClient
@EnableSidecar
@EnableFeignClients(basePackages = "com.ztgm.sidecar_server")
public class SidecarServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SidecarServerApplication.class, args);
    }

}

以上代码即可实现将php接口服务注册到eureka中。
需要调用php接口直接通过我们服务的网关/php接口地址即可实现调用。

注:sidecar心跳速度慢,启动服务后需要等待大约二三十秒。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值