From 01ab6827307924919f737a0bf9c26defe307aa93 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 9 Jun 2016 17:56:50 +0100 Subject: [PATCH] Add feign-hystrix sample --- feign-hystrix/README.md | 2 + feign-hystrix/pom.xml | 113 ++++++++++++++++++ .../java/demo/FeignClientApplication.java | 46 +++++++ .../src/main/resources/application.properties | 0 .../src/test/java/demo/AdhocTestSuite.java | 35 ++++++ .../demo/FeignClientApplicationTests.java | 27 +++++ ...nClientWithServerListApplicationTests.java | 52 ++++++++ pom.xml | 1 + 8 files changed, 276 insertions(+) create mode 100644 feign-hystrix/README.md create mode 100644 feign-hystrix/pom.xml create mode 100644 feign-hystrix/src/main/java/demo/FeignClientApplication.java create mode 100644 feign-hystrix/src/main/resources/application.properties create mode 100644 feign-hystrix/src/test/java/demo/AdhocTestSuite.java create mode 100644 feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java create mode 100644 feign-hystrix/src/test/java/demo/FeignClientWithServerListApplicationTests.java diff --git a/feign-hystrix/README.md b/feign-hystrix/README.md new file mode 100644 index 0000000..0b162e8 --- /dev/null +++ b/feign-hystrix/README.md @@ -0,0 +1,2 @@ +This project is a sample of a client application with Feign +that doesn't use Eureka but does use Hystrix. diff --git a/feign-hystrix/pom.xml b/feign-hystrix/pom.xml new file mode 100644 index 0000000..259a57d --- /dev/null +++ b/feign-hystrix/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + + org.springframework.cloud.sample + spring-cloud-sample-feign-hystrix + ${spring-cloud.version} + jar + + spring-cloud-sample-feign-hystrix + Demo project for Spring Cloud + + + org.springframework.boot + spring-boot-starter-parent + 1.3.5.RELEASE + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + UTF-8 + 1.7 + Brixton.BUILD-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + maven-deploy-plugin + + true + + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/feign-hystrix/src/main/java/demo/FeignClientApplication.java b/feign-hystrix/src/main/java/demo/FeignClientApplication.java new file mode 100644 index 0000000..f6cdead --- /dev/null +++ b/feign-hystrix/src/main/java/demo/FeignClientApplication.java @@ -0,0 +1,46 @@ +package demo; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@SpringBootApplication +@EnableFeignClients +public class FeignClientApplication { + + @Bean + public ApplicationRunner runner(final RestClient client) { + return new ApplicationRunner() { + + @Override + public void run(ApplicationArguments args) throws Exception { + System.err.println(client.hello()); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(FeignClientApplication.class, args); + } +} + +@FeignClient(name = "example", url = "example.com", fallback=FallbackClient.class) +interface RestClient { + @RequestMapping(value="/", method = RequestMethod.GET) + String hello(); +} + +@Component +class FallbackClient implements RestClient { + @Override + public String hello() { + return "oops"; + } +} diff --git a/feign-hystrix/src/main/resources/application.properties b/feign-hystrix/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/feign-hystrix/src/test/java/demo/AdhocTestSuite.java b/feign-hystrix/src/test/java/demo/AdhocTestSuite.java new file mode 100644 index 0000000..8e2c7f2 --- /dev/null +++ b/feign-hystrix/src/test/java/demo/AdhocTestSuite.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * 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 demo; + +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +/** + * A test suite for probing weird ordering problems in the tests. + * + * @author Dave Syer + */ +@RunWith(Suite.class) +@SuiteClasses({ FeignClientApplicationTests.class, + FeignClientWithServerListApplicationTests.class }) +@Ignore("Test suite for tracking order dependencies") +public class AdhocTestSuite { + +} diff --git a/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java b/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java new file mode 100644 index 0000000..c2fdc26 --- /dev/null +++ b/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java @@ -0,0 +1,27 @@ +package demo; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = FeignClientApplication.class) +@WebIntegrationTest(randomPort = true) +@DirtiesContext +public class FeignClientApplicationTests { + + @Autowired + private RestClient client; + + @Test + public void clientConnects() { + assertTrue(client.hello().contains("eureka-server feign feign-eureka + feign-hystrix hystrix hystrix-amqp netflix-sidecar