-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CD826
authored and
CD826
committed
Jul 31, 2017
1 parent
6e9fbf6
commit 5990d5b
Showing
135 changed files
with
4,386 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# TwoStepsFromJava-Cloud-Feign | ||
|
||
Spring Cloud 示例项目:结合Ribbon和Feign实现声明式服务调用。 | ||
|
||
|
||
Spring Cloud Release Trains: [Dalston.SR1](http://projects.spring.io/spring-cloud/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>twostepsfromjava.cloud</groupId> | ||
<artifactId>twostepsfromjava-cloud-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>mall-web</artifactId> | ||
<name>Spring Cloud Sample Projects: Mall</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-eureka</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-ribbon</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-hystrix</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-feign</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>product-service-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
41 changes: 41 additions & 0 deletions
41
hystrix/mall-web/src/main/java/io/twostepsfromjava/cloud/web/mall/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*** | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.twostepsfromjava.cloud.web.mall; | ||
|
||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.feign.EnableFeignClients; | ||
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; | ||
|
||
/** | ||
* TwoStepsFromJava Cloud -- Mall Web Project | ||
* | ||
* @author CD826([email protected]) | ||
* @since 1.0.0 | ||
*/ | ||
@EnableHystrixDashboard | ||
@EnableCircuitBreaker | ||
@EnableFeignClients | ||
@EnableDiscoveryClient | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...ll-web/src/main/java/io/twostepsfromjava/cloud/web/mall/controller/ProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*** | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.twostepsfromjava.cloud.web.mall.controller; | ||
|
||
import io.twostepsfromjava.cloud.product.dto.Product; | ||
import io.twostepsfromjava.cloud.web.mall.service.ProductService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* Product Controller | ||
* | ||
* @author CD826([email protected]) | ||
* @since 1.0.0 | ||
*/ | ||
@RestController | ||
@RequestMapping("/products") | ||
public class ProductController { | ||
@Autowired | ||
private ProductService productService; | ||
|
||
@RequestMapping(method = RequestMethod.GET) | ||
public List<Product> list() { | ||
return this.productService.findAll(); | ||
} | ||
|
||
@RequestMapping(value = "/{itemCode}", method = RequestMethod.GET) | ||
public Product detail(@PathVariable String itemCode) { | ||
return this.productService.loadByItemCode(itemCode); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rix/mall-web/src/main/java/io/twostepsfromjava/cloud/web/mall/service/ProductService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*** | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.twostepsfromjava.cloud.web.mall.service; | ||
|
||
import io.twostepsfromjava.cloud.product.dto.Product; | ||
import org.springframework.cloud.netflix.feign.FeignClient; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* Product Service | ||
* | ||
* @author CD826([email protected]) | ||
* @since 1.0.0 | ||
*/ | ||
@FeignClient(name = "PRODUCT-SERVICE", fallback = ProductServiceFallback.class) | ||
public interface ProductService { | ||
|
||
@RequestMapping(value = "/products", method = RequestMethod.GET) | ||
List<Product> findAll(); | ||
|
||
@RequestMapping(value = "/products/{itemCode}", method = RequestMethod.GET) | ||
Product loadByItemCode(@PathVariable("itemCode") String itemCode); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...-web/src/main/java/io/twostepsfromjava/cloud/web/mall/service/ProductServiceFallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*** | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.twostepsfromjava.cloud.web.mall.service; | ||
|
||
import io.twostepsfromjava.cloud.product.dto.Product; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Product Service Fallback | ||
* | ||
* @author CD826([email protected]) | ||
* @since 1.0.0 | ||
*/ | ||
@Component | ||
public class ProductServiceFallback implements ProductService { | ||
@Override | ||
public List<Product> findAll() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public Product loadByItemCode(@PathVariable("itemCode") String itemCode) { | ||
return new Product("error", "未知", "TwoStepsFromJava-Fallback", 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
server.port=8080 | ||
|
||
spring.application.name=MALL-WEB | ||
|
||
feign.hystrix.enabled=true | ||
|
||
eureka.client.service-url.defaultZone=http://localhost:8260/eureka | ||
|
||
logging.level.org.springframework=INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
======================================================================================================================= | ||
== == | ||
== == | ||
== _______ _____ ______ _ _____ _ ____ _ _ _____ == | ||
== |__ __|/ ____|| ____| | | / ____|| | / __ \ | | | || __ \ == | ||
== | | | (___ | |__ | | ______ | | | | | | | || | | || | | | == | ||
== | | \___ \ | __|_ | ||______|| | | | | | | || | | || | | | == | ||
== | | ____) || | | |__| | | |____ | |____| |__| || |__| || |__| | == | ||
== |_| |_____/ |_| \____/ \_____||______|\____/ \____/ |_____/ -- Consumer == | ||
== == | ||
== == | ||
======================================================================================================================= | ||
:: twostepsfromjava.io :: v1.0.0.BUILD-SNAPSHOT BUILD-BY: CD826 |
Oops, something went wrong.