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

node-server.js

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

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/

最新文章

  1. 收集C#常用类:自己写的一个DBHelper类
  2. gcc 和g++区别
  3. C++中static类成员
  4. [转载]CAD文件版本
  5. JDBC的批量处理数据
  6. C 可变参数(C与指针实例)
  7. 输出图像到文件 imwrite()[OpenCV 笔记7]
  8. Linux 下让进程在后台可靠运行的几种方法
  9. Zoj3332-Strange Country II(有向竞赛图)
  10. POJ训练计划3041_Asteroids(二分图/最小点覆盖=最大匹配)
  11. 本学期微分方程数值解课程总结(matlab代码)
  12. JSP具体篇——response对象
  13. .Net语言 APP开发平台——Smobiler学习日志:如何快速实现按钮组功能
  14. A. Points in Segments(cf a题, 水题)
  15. LeetCode算法题-Power Of Two(Java实现)
  16. day050 前端Jquery库的使用
  17. SpringMVC:后台将List转为Json,传值到页面
  18. PHPWeb开发相关知识
  19. Linux 工具,一本好书 大牛的博客
  20. Ionic Tabs使用

热门文章

  1. 解决flutter 运行时:Waiting for another flutter command to release the startup lock...
  2. spring多模块之间的调用
  3. Python练习题 037:Project Euler 009:毕达哥拉斯三元组之乘积
  4. Onethink 前台编辑器调用
  5. 01 How does C Programming work ? C语言如何工作?
  6. matlab中polyfit
  7. 深入浅出具有划时代意义的G1垃圾回收器
  8. 50个你必须了解的Kubernetes面试问题
  9. (九) SpringBoot起飞之路-整合/集成Swagger 2 And 3
  10. webfunny前端监控开源项目