diff --git a/ace-sidecar/ace-sidecar-client-demo/pom.xml b/ace-sidecar/ace-sidecar-client-demo/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..002d6c8f95d3b34cd850fea23af51ba73ab8b681 --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/pom.xml @@ -0,0 +1,61 @@ + + + + ace-sidecar + com.github.wxiaoqi + 1.0-SNAPSHOT + + 4.0.0 + + ace-sidecar-client-demo + + + + org.springframework.cloud + spring-cloud-starter-config + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-netflix-sidecar + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.cloud + spring-cloud-starter-feign + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-client-demo/readme.md b/ace-sidecar/ace-sidecar-client-demo/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..19fe23e74c486c098ad68bb10005f1929c843dce --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/readme.md @@ -0,0 +1,28 @@ +Python服务端示例: +https://gitee.com/superjery/tornado_boilerplate + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +需以下根文件: + __init__.py + application.py + server.py + urls.py + +需以下根文件夹: + handlers + model + static + templates +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Python 安装 3.5 +tornado 安装 4.5 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +运行python server.py即可启动Web + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +两种访问接口方式: +http://localhost:5689/ace-sidecar-client-demo/test/test +http://localhost:5689/ace-sidecar-client-demo/message/123 diff --git a/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/PythonServerBootstrap.java b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/PythonServerBootstrap.java new file mode 100644 index 0000000000000000000000000000000000000000..d5e5e038e7c9d969dfc41e6926cf876b31eff488 --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/PythonServerBootstrap.java @@ -0,0 +1,23 @@ +package com.github.wxiaoqi.security.sidecarclient; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * ${DESCRIPTION} + * + * @author yangyongjie + * @create 2017-10-22 20:30 + */ +@SpringBootApplication +@EnableEurekaClient +@EnableDiscoveryClient +@EnableFeignClients +public class PythonServerBootstrap { + public static void main(String[] args) { + SpringApplication.run(PythonServerBootstrap.class, args); + } +} diff --git a/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/client/PythonFeignClient.java b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/client/PythonFeignClient.java new file mode 100644 index 0000000000000000000000000000000000000000..d274113740af153cf7c50eaf2c8ef4da5f1c40c9 --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/client/PythonFeignClient.java @@ -0,0 +1,23 @@ +package com.github.wxiaoqi.security.sidecarclient.client; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import com.github.wxiaoqi.security.sidecarclient.entity.Message; +import org.springframework.web.bind.annotation.RequestParam; +import java.util.List; + +/** + * ${DESCRIPTION} + * + * @author yangyongjie + * @create 2017-10-22 20:30 + */ +@FeignClient(name = "ace-sidecar-server") +public interface PythonFeignClient { + //parse param like /message?id=12 + @RequestMapping("/message/{id}") + List getMsg(@RequestParam("id") Long id); + //parse url like /test + @RequestMapping("/test") + String getTest(); +} \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/entity/Message.java b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/entity/Message.java new file mode 100644 index 0000000000000000000000000000000000000000..6871e0cb64df5b7b8f4880f28999313d8f224db3 --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/entity/Message.java @@ -0,0 +1,28 @@ +package com.github.wxiaoqi.security.sidecarclient.entity; + +/** + * ${DESCRIPTION} + * + * @author yangyongjie + * @create 2017-10-22 20:30 + */ +public class Message { + private Long id; + private String msg; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/rest/PythonController.java b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/rest/PythonController.java new file mode 100644 index 0000000000000000000000000000000000000000..8cf4670c7337ebb89f50f215aae52652dc4807ec --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/src/main/java/com/github/wxiaoqi/security/sidecarclient/rest/PythonController.java @@ -0,0 +1,31 @@ +package com.github.wxiaoqi.security.sidecarclient.rest; + +import com.github.wxiaoqi.security.sidecarclient.entity.Message; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; +import com.github.wxiaoqi.security.sidecarclient.client.PythonFeignClient; +import org.springframework.web.bind.annotation.*; +import java.util.List; + +/** + * ${DESCRIPTION} + * + * @author yangyongjie + * @create 2017-10-22 20:30 + */ +@RestController +@RequestMapping("test") +public class PythonController { + @Autowired + private PythonFeignClient pythonFeignClient; + + @RequestMapping(value = "/test", method = RequestMethod.GET) + public String getTest() { + return pythonFeignClient.getTest(); + } + + @RequestMapping(value = "/message/{id}", method = RequestMethod.GET) + public List getMsg(@PathVariable Long id) { + return pythonFeignClient.getMsg(id); + } +} \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-client-demo/src/main/resources/application.yml b/ace-sidecar/ace-sidecar-client-demo/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..ed9ab188fd93ac48b8e12b8b9b45e477adac1be0 --- /dev/null +++ b/ace-sidecar/ace-sidecar-client-demo/src/main/resources/application.yml @@ -0,0 +1,14 @@ +server: + port: 5689 #启动端口 + +spring: + application: + name: ace-sidecar-client-demo + +eureka: + instance: + statusPageUrlPath: /info + healthCheckUrlPath: /health + client: + serviceUrl: + defaultZone: http://localhost:8761/eureka/ \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-server/pom.xml b/ace-sidecar/ace-sidecar-server/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..dce413a309ac0a34dc05e8ed946c22f1c1e2c5cc --- /dev/null +++ b/ace-sidecar/ace-sidecar-server/pom.xml @@ -0,0 +1,54 @@ + + + + ace-sidecar + com.github.wxiaoqi + 1.0-SNAPSHOT + + 4.0.0 + + ace-sidecar-server + + + + org.springframework.cloud + spring-cloud-starter-config + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-netflix-sidecar + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.cloud + spring-cloud-starter-eureka + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-server/readme.md b/ace-sidecar/ace-sidecar-server/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..682a7b9f54d1b50ccada518301ca1cd63b8e9531 --- /dev/null +++ b/ace-sidecar/ace-sidecar-server/readme.md @@ -0,0 +1,24 @@ +使用Sidecar代理远程Python服务,端口为Python的Web端口 +当然,换成Node的Web端口,即可代理Node的远程服务 +远程服务需要实现一个接口,返回 + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Node: +app.get('/health', (req, res) => { + res.json({ + status: 'UP' + }) +}) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Python: +class HealthHandler(tornado.web.RequestHandler): + def get(self): + self.set_header("content-type", "application/json") + self.render('health') + +health: +{"status":"UP"} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +切记,通过此代理访问不到远程Python提供的服务, +需通过ace-sidecar-client-demo封装后才可访问到。 \ No newline at end of file diff --git a/ace-sidecar/ace-sidecar-server/src/main/java/com/github/wxiaoqi/security/sidecar/SidercarBootstrap.java b/ace-sidecar/ace-sidecar-server/src/main/java/com/github/wxiaoqi/security/sidecar/SidercarBootstrap.java new file mode 100644 index 0000000000000000000000000000000000000000..d99c807c36f397337c8d53cef5d5217517c3cdc9 --- /dev/null +++ b/ace-sidecar/ace-sidecar-server/src/main/java/com/github/wxiaoqi/security/sidecar/SidercarBootstrap.java @@ -0,0 +1,16 @@ +package com.github.wxiaoqi.security.sidecar; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.sidecar.EnableSidecar; + +/** + * Created by ace on 2017/7/29. + */ +@EnableSidecar +@SpringBootApplication +public class SidercarBootstrap { + public static void main(String[] args) { + SpringApplication.run(SidercarBootstrap.class, args); + } +} diff --git a/ace-sidecar/ace-sidecar-server/src/main/resources/application.yml b/ace-sidecar/ace-sidecar-server/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..e8deaad1b41a03d6ffe6b7f8c80257e45c8e74d7 --- /dev/null +++ b/ace-sidecar/ace-sidecar-server/src/main/resources/application.yml @@ -0,0 +1,19 @@ +server: + port: 5688 #启动端口 + +spring: + application: + name: ace-sidecar-server + +sidecar: + port: 5680 #python接口 + health: + uri: http://localhost:${sidecar.port}/health + +eureka: + instance: + statusPageUrlPath: /info + healthCheckUrlPath: /health + client: + serviceUrl: + defaultZone: http://localhost:8761/eureka/ \ No newline at end of file diff --git a/ace-sidecar/pom.xml b/ace-sidecar/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..1dc3b0774f524bfaa3615f18b2f42c4919f414d3 --- /dev/null +++ b/ace-sidecar/pom.xml @@ -0,0 +1,20 @@ + + + + ace-security + com.github.wxiaoqi + 1.0-SNAPSHOT + + 4.0.0 + + ace-sidecar + pom + + + ace-sidecar-server + ace-sidecar-client-demo + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 44045495cdd4591c97d920e034633a8844e4f656..2e1d5ec149183abed88ea71463eff976fba2bc7d 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,7 @@ ace-config ace-generator ace-auth + ace-sidecar pom