Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
2daeed6c
Commit
2daeed6c
authored
Oct 01, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some examples to docs
parent
23b8c96b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
11 deletions
+120
-11
spring-cloud-netflix.adoc
src/main/asciidoc/spring-cloud-netflix.adoc
+120
-11
No files found.
src/main/asciidoc/spring-cloud-netflix.adoc
View file @
2daeed6c
...
...
@@ -14,14 +14,14 @@ Example eureka client:
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "Hello world";
}
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
@RequestMapping("/")
public String home() {
return "Hello world";
}
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
...
...
@@ -50,9 +50,9 @@ Example eureka server:
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
...
...
@@ -65,14 +65,123 @@ Eureka (apache -> tomcat) see https://github.com/cfregly/fluxcapacitor/wiki/Netf
== Circuit Breaker: Hystrix Clients
Example boot app:
```
@Configuration
@EnableAutoConfiguration
@EnableHystrix
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
@Component
public class StoreIntegration {
@HystrixCommand(fallbackMethod = "defaultStores")
public Object getStores(Map<String, Object> parameters) {
//do stuff that might fail
}
public Object defaultStores(Map<String, Object> parameters) {
return /* something useful */;
}
}
```
== Circuit Breaker: Hystrix Dashboard
=== Turbine
== Declarative REST Client: Feign
Example application.yml:
```
spring:
cloud:
client:
serviceIds:
- stores
```
Example spring boot app
```
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEurekaClient
public class Application extends FeignConfigurer {
@Bean
public StoreClient storeClient() {
//loadBalance plugs Feign into ribbon. feign() works without load balancing.
return loadBalance(StoreClient.class, "http://stores");
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
StoreClient.java
```
public interface StoreClient {
@RequestMapping(method = RequestMethod.GET, value = "/stores")
Stores getStores();
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
Store update(@PathParameter("storeId") Long storeId, Store store);
}
```
== Client Side Load Balancer: Ribbon
Example application.yml:
```
spring:
cloud:
client:
serviceIds:
- stores
```
Usage of `LoadBalancerClient` directly:
```
public class MyClass {
@Autowired
private LoadBalancerClient loadBalancer;
public void doStuff() {
//"stores" in choose() must match a service in spring.cloud.client.serviceIds
ServiceInstance instance = loadBalancer.choose("stores");
URI storesUri = URI.create(String.format("http://%s:%s", instance.getHost(), instance.getPort()));
// ... do something with the URI
}
}
```
Indirect usage via `RestTemplate`. Notice the `stores` hostname part, must match a service id in spring.cloud.client.serviceIds:
```
public class MyClass {
@Autowired
private RestTemplate restTemplate;
public String doOtherStuff() {
String results = restTemplate.getForObject("http://stores/stores", String.class);
return results;
}
}
```
== External Configuration: Archaius
== Router and Filter: Zuul
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment