Microservices
Part I : Spring Cloud / Eureka & Zuul
Qui suis-je ?







Microservices ?
Products not Projects
Smart endpoints, dumb pipes
Decentralized Data Management
Design for Failure
SOA done right
Netflix
35% of US bandwidth
(youtube uses 15%)
1 Billion req/d
Peak: 20k req/s
Netflix OSS
- Hystrix
- Turbine
- Archaius
- Feign
- Ribbon
- Servo
- Eureka
- Zuul
- Security Monkey
- ...
Today ?
- Spring Cloud
- Service Registry : Eureka
- Reverse Proxy : Zuul (Routes + Ribbon + Hystrix)
Front
Server
Echo Service
Echo Service
Echo Service
Echo Service
Heartbeat

Front Server (Eureka +Zuul)
package com.mgaudin.sandbox.ht.front;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@EnableZuulProxy
@EnableEurekaServer
@EnableDiscoveryClient
@SpringBootApplication
public class FrontApplication {
public static void main(String[] args) {
SpringApplication.run(FrontApplication.class, args);
}
}
server.port=8081
spring.application.name=Front
eureka.instance.hostname=localhost
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.client.serviceUrl.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/
eureka.client.registry-fetch-interval-seconds=5
eureka.dashboard.path=/dashboard
echo.ribbon.ServerWeightTaskTimerInterval=3000
Echo Service
@RestController
@RequestMapping("/")
public class EchoController {
@RequestMapping(method = RequestMethod.POST)
public String echo(@RequestBody(required = false) String input) throws UnknownHostException {
return String.format("%s (from %s)", input == null ? "" : input, InetAddress.getLocalHost().getHostAddress());
}
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getIP() throws UnknownHostException {
return String.format("{ \"ip\": \"%s\" }", InetAddress.getLocalHost().getHostAddress());
}
}
spring.application.name=echo
eureka.client.serviceUrl.defaultZone=http://localhost:8081/eureka/
eureka.client.registry-fetch-interval-seconds=5
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.metadata-map.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
latency.artificial.wait=0
Thank you Spring !
Deployment ?
Front
Server
Echo Service
Echo Service
Echo Service
Echo Service
Heartbeat

Maven
Docker
Images
Docker Compose
Docker-Compose
Maven
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.6</version>
<configuration>
<imageName>humantalks/${project.artifactId}</imageName>
<dockerDirectory>${project.build.sourceDirectory}/../docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
Compose
front:
image: humantalks/front
ports:
- 8081:8081
echo:
image: humantalks/echo
links:
- front
expose:
- 8080
echoSlow:
image: humantalks/echo
links:
- front
environment:
- latency.artificial.wait=800
expose:
- 8080
Docker
FROM java:8
MAINTAINER Maxime Gaudin <gaudin.maxime@gmail.com>
ADD echo-1.0-SNAPSHOT.jar app.jar
RUN bash -c 'touch /app.jar'
COPY conf/application.properties application.properties
ENTRYPOINT ["java", "-jar", "/app.jar", "--spring.config.location=file:/application.properties"]
Démo
Il reste du temps ?!
Merci !
- https://github.com/MaximeGaudin/HT-Microservices
- http://martinfowler.com/articles/microservices.html
- http://www.forbes.com/sites/quickerbettertech/2014/11/24/netflix-and-youtube-now-consume-50-of-the-internet-as-the-argument-for-net-neutrality-weakens/
- http://techblog.netflix.com/2011/12/making-netflix-api-more-resilient.html
- http://netflix.github.io/#repo
HT-05/2015 - Microservices : Part I
By mgaudin
HT-05/2015 - Microservices : Part I
- 1,250