Notice that the `serviceUrl` is pointing to the same host as the local
instance.
=== Peer Awareness
Eureka can be made even more resilient and available by running
multiple instances and asking them to register with each other. In
fact, this is the default behaviour, so all you need to do to make it
work is add a valid `serviceUrl` to a peer, e.g.
.application.yml (Two Peer Aware Eureka Servers)
----
---
spring:
profiles: peer1
eureka:
instance:
hostname: peer1
client:
serviceUrl:
defaultZone: http://peer2/eureka/
---
spring:
profiles: peer2
eureka:
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://peer1/eureka/
----
In this example we have a YAML file that can be used to run the same
server on 2 hosts (peer1 and peer2), by running it in different
Spring profiles. You could use this configuration to test the peer
awareness on a single host (there's not much value in doing that in
production) by manipulating `/etc/hosts` to resolve the host names. In
fact, the `eureka.instance.hostname` is not needed if you are running
on a machine that knows its own hostname (it is looked up using
`java.net.InetAddress` by default).
You can add multiple peers to a system, and as long as they are all
connected to each other by at least one edge, they will synchronize
the registrations amongst themselves. If the peers are physically
separated (inside a data centre or between multiple data centres) then
the system can in principle survive split-brain type failures.
== Circuit Breaker: Hystrix Clients
== Circuit Breaker: Hystrix Clients
Netflix has created a library called https://github.com/Netflix/Hystrix[Hystrix] that implements the http://martinfowler.com/bliki/CircuitBreaker.html[circuit breaker pattern]. In a microservice architecture it is common to have multiple layers of service calls.
Netflix has created a library called https://github.com/Netflix/Hystrix[Hystrix] that implements the http://martinfowler.com/bliki/CircuitBreaker.html[circuit breaker pattern]. In a microservice architecture it is common to have multiple layers of service calls.
...
@@ -150,7 +244,7 @@ Having an open circuit stops cascading failures and allows overwhelmed or failin
...
@@ -150,7 +244,7 @@ Having an open circuit stops cascading failures and allows overwhelmed or failin
Example boot app:
Example boot app:
```
----
@Configuration
@Configuration
@EnableAutoConfiguration
@EnableAutoConfiguration
@EnableHystrix
@EnableHystrix
...
@@ -175,7 +269,7 @@ public class StoreIntegration {
...
@@ -175,7 +269,7 @@ public class StoreIntegration {
}
}
}
}
```
----
The `@HystrixCommand` is provided by a Netflix contrib library called
The `@HystrixCommand` is provided by a Netflix contrib library called
"javanica". Spring Cloud automatically wraps Spring beans with that
"javanica". Spring Cloud automatically wraps Spring beans with that
...
@@ -201,7 +295,9 @@ Looking at an individual instances Hystrix data is not very useful in terms of t
...
@@ -201,7 +295,9 @@ Looking at an individual instances Hystrix data is not very useful in terms of t
https://github.com/Netflix/feign[Feign] is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same `HttpMessageConverters` used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.
https://github.com/Netflix/feign[Feign] is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same `HttpMessageConverters` used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.
Example spring boot app
Example spring boot app
```
[source,java,indent=0]
----
@Configuration
@Configuration
@ComponentScan
@ComponentScan
@EnableAutoConfiguration
@EnableAutoConfiguration
...
@@ -218,10 +314,11 @@ public class Application extends FeignConfigurer {
...
@@ -218,10 +314,11 @@ public class Application extends FeignConfigurer {
}
}
}
}
```
----
StoreClient.java
.StoreClient.java
```
[source,java,indent=0]
----
public interface StoreClient {
public interface StoreClient {
@RequestMapping(method = RequestMethod.GET, value = "/stores")
@RequestMapping(method = RequestMethod.GET, value = "/stores")
Stores getStores();
Stores getStores();
...
@@ -229,13 +326,14 @@ public interface StoreClient {
...
@@ -229,13 +326,14 @@ public interface StoreClient {
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
Store update(@PathParameter("storeId") Long storeId, Store store);
Store update(@PathParameter("storeId") Long storeId, Store store);