Skip to content

Commit

Permalink
Finchley
Browse files Browse the repository at this point in the history
  • Loading branch information
javahongxi committed Oct 19, 2018
1 parent 4d35243 commit 67e9f5b
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 543 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ whatsmars-sharding-jdbc | 开源分布式数据库中间件
whatsmars-spring | spring原理、集成及新特性
whatsmars-spring-boot | springboot实战
whatsmars-spring-boot-samples | 常用starters样例
whatsmars-spring-cloud | springcloud demo
whatsmars-spring-cloud | Finchley
whatsmars-tomcat | 模拟tomcat实现,embed tomcat
[spring-boot-latest](https://github.com/javahongxi/spring-boot-latest) | Spring 5+, Spring Boot 2+
[spring-boot-simple](https://github.com/javahongxi/spring-boot-simple) | the simplest boot
Expand Down
12 changes: 4 additions & 8 deletions whatsmars-spring-cloud/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
https://github.com/spring-cloud/spring-cloud-netflix
# Spring Cloud
`Finchley`

依次启动eureka,provider,consumer,zuul
依次启动eureka,provider,consumer
1. 直接访问 localhost:8763/hi?name=hongxi
1. 网关访问 localhost:8764/demo/hi?name=hongxi&accessToken=123456 localhost:8764/demo/hi?name=hongxi
1. 停掉provider,再次进行上面的访问

API网关(zuul)
1. 通过 API 网关,封装微服务的 REST API。
1. 均通过 API 网关 进行调用,享受 API 网关带来的统一鉴权,统一监控等好处。
1. 通过 API 网关,控制对外暴露的 API,减轻安全隐患。

https://github.com/spring-cloud/spring-cloud-netflix
https://github.com/spring-cloud-samples
46 changes: 32 additions & 14 deletions whatsmars-spring-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@
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">

<parent>
<artifactId>whatsmars-parent</artifactId>
<groupId>org.hongxi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.hongxi</groupId>
<artifactId>whatsmars-spring-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>The demo module of spring cloud project</description>

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

<modules>
<module>whatsmars-cloud-consumer</module>
<module>whatsmars-cloud-eureka</module>
<module>whatsmars-cloud-provider</module>
<module>whatsmars-cloud-zuul</module>
</modules>

<properties>
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
Expand All @@ -44,6 +45,14 @@
</dependencyManagement>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
Expand All @@ -54,4 +63,13 @@
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
49 changes: 4 additions & 45 deletions whatsmars-spring-cloud/whatsmars-cloud-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,21 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>${springloaded.version}</version>
</dependency>
</dependencies>
<!-- POM不是继承spring-boot-starter-parent的话,需要下面的指定 -->
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
* Created by shenhongxi on 2017/9/14.
Expand All @@ -20,10 +17,4 @@ public class ConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}

@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
package org.hongxi.whatsmars.cloud.consumer.controller;

import org.hongxi.whatsmars.cloud.consumer.feign.DemoFeign;
import org.hongxi.whatsmars.cloud.consumer.rpc.DemoRpc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
* Created by shenhongxi on 2017/9/14.
*/
@RestController
public class DemoController {

@Autowired
private DemoRpc demoRpc;

@Autowired
private DemoFeign demoFeign;

@RequestMapping("/hello")
public String hello(String name) {
return demoRpc.hello(name);
}

@RequestMapping("/hi")
public String hi(String name) {
return demoFeign.hello(name);
public Mono<String> hi(String name) {
return Mono.just(demoFeign.hello(name));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.hongxi.whatsmars.cloud.consumer.feign;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
* Created by shenhongxi on 2017/9/14.
*/
@FeignClient(value = "${provider.name}", fallback = DemoHystrix.class)
@FeignClient(value = "demo-provider", fallback = DemoHystrix.class)
public interface DemoFeign {
@RequestMapping("/hello")
String hello(@RequestParam(name = "name") String name); // 此处必须有RequestParam
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
spring:
profiles:
active: dev

provider:
name: demo-provider

---
eureka:
client:
serviceUrl:
defaultZone: http://test.toutiao.im:8761/eureka/
server:
port: 8763
spring:
application:
name: demo-consumer
profiles: test
feign:
hystrix:
enabled: true

---
eureka:
client:
serviceUrl:
service-url:
defaultZone: http://localhost:8761/eureka/
server:
port: 8763
spring:
application:
name: demo-consumer
profiles: dev
feign:
hystrix:
enabled: true
44 changes: 1 addition & 43 deletions whatsmars-spring-cloud/whatsmars-cloud-eureka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,8 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>${springloaded.version}</version>
</dependency>
</dependencies>
<!-- POM不是继承spring-boot-starter-parent的话,需要下面的指定 -->
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit 67e9f5b

Please sign in to comment.