Eureka整合sidecar异构调用

本次使用nodejs脚本生成的异构程序测试:

node-server.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var http = require('http');
var url = require('url');
var path = require('path');
 
//创建server
var server = http.createServer(function(req, res){
    //获得请求路径
    var pathname = url.parse(req.url).pathname;
    res.writeHead(200, {'Content-Type':'application/json; charset=utf-8'});
    if(pathname === '/'){
        res.end(JSON.stringify({ "index":"欢迎" }));
    }else if(pathname === '/health.json'){
        res.end(JSON.stringify({ "status":"UP" }));
    }else{
        res.end("404");
    }
});
 
//创建监听,并打印日志
server.listen(8060, function(){
    console.log('listening on localhost:8060');
});

  生成js文件保存执行cmd node+路径

测试  : localhost:8060 是否正常访问

 

1.首先修改Zuul网关的配置:

复制代码
server:
  port: 8050
spring:
  application:
    name: client-Zuul
eureka:
  client:
    serviceUrl:
      defaultZone: http://user:password123@localhost:8761/eureka
zuul:
  ignoredServices: '*'
  routes:
    app-provider-user:            #名称随意,唯一就好
      path: /user/**
      serviceId: provider-user
    app-sidecar:                  #通过sidecar调用nodejs的服务
      path: /sidecar/**
      serviceId: sidecar
复制代码

2.SideCarRunApp.java

1
2
3
4
5
6
7
8
9
10
11
12
13
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.sidecar.EnableSidecar;
 
@SpringBootApplication
@EnableSidecar
public class SideCarRunApp {
 
    public static void main(String[] args) {
        SpringApplication.run(SideCarRunApp.class, args);
    }
 
}

  application.yml

复制代码
server:
  port: 8070
spring:
  application:
    name: sidecar
eureka:
  client:
    serviceUrl:
      defaultZone: http://user:password123@localhost:8761/eureka
sidecar:
  port: 8060
  health-uri: http://localhost:8060/health.json
复制代码

pom.xml

复制代码
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>eureka.sidecar</groupId>
  <artifactId>eureka-sidecar</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <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>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-sidecar</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>
复制代码

测试访问:http://localhost:8070/

 

posted @   蔡徐坤1987  阅读(980)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示