This document discusses microservices architectures and provides examples of tools used in microservices architectures like those implemented at Netflix. It describes common microservices patterns like service discovery (Eureka), configuration management (Archaius), load balancing (Ribbon), circuit breaking (Hystrix), monitoring (Turbine), edge services (Zuul), and logging (Blitz4j). It also discusses using these tools with Spring Cloud and provides code samples for configuring services using Netflix OSS and Spring Cloud.
5. "Microservices is a software architecture design
pattern, in which complex applications are composed of
small, independent processes communicating with each
other using language-agnostic APIs. These services are
small, highly decoupled and focus on doing a small
task."
22. TURBINE
Stream aggregator
Turbine is an application that aggregates all of the
relevant /hystrix.stream endpoints into a
combined /turbine.stream for use in the Hystrix
Dashboard
https://github.com/Netflix/Turbine
30. Eureka Server
@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
.web(true)
.run(args);
}
}
31. Eureka Server
@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
public class Application {
application.yml
server:
port: 8761
eureka:
instance:
public static void main(String[] args) {
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
new SpringApplicationBuilder(Application.class)
.web(true)
.run(args);
}
}
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
32. Eureka Client
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEurekaClient
@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);
}
}
33. Eureka Client
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableEurekaClient
@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);
}
}
application.yml
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
34. Ribbon
Transparente vía RestTemplate
RibbonAutoConfiguration.java
@Bean
@ConditionalOnMissingBean(RestTemplate.class)
public RestTemplate restTemplate(RibbonInterceptor ribbonInterceptor) {
RestTemplate restTemplate = new RestTemplate();
List<ClientHttpRequestInterceptor> list = new ArrayList<>();
list.add(ribbonInterceptor);
restTemplate.setInterceptors(list);
return restTemplate;
}
}
http://github.com/.../RibbonAutoConfiguration.java
35. Hystrix wrapper
@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 */;
}
}
36. Hystrix Config
@Configuration
@EnableAutoConfiguration
@EnableHystrix
@EnableHystrixDashboard
@ComponentScan
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
.web(true)
.run(args);
}
}
38. Spring Cloud Config
∘ Properties en repositorio Git
∘ API
∘ Profiles
∘ Encriptado
∘ @RefreshScope
∘ PropertySource & Env
https://github.com/spring-cloud/spring-cloud-config
39. Spring Cloud Config - Server
@Configuration
@EnableAutoConfiguration
@EnableEurekaClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
40. Spring Cloud Config - Server
@Configuration
@EnableAutoConfiguration
@EnableEurekaClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
bootstrap.yml
spring:
application:
name: configserver
encrypt:
keyStore:
location: classpath:keystore.jks
password: ${KEYSTORE_PASSWORD} # foobar
alias: test
application.yml
spring:
cloud:
config:
server:
basedir: target/config
uri: https://github.com/ehdez73/cloud-config
security:
user:
password: '{cipher}AQBunH7b87s86E='
41. Spring Cloud Config - Client
@Configuration
@EnableAutoConfiguration
@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);
}
}
42. Spring Cloud Config - Client
@Configuration
@EnableAutoConfiguration
@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);
}
}
bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:${config.port:8888}
53. MINIONIZE THE WORLD !!!
Minions ipsum tulaliloo
potatoooo pepete jeje baboiii
poulet tikka masala chasy la
bodaaa butt. La bodaaa
aaaaaah tulaliloo wiiiii la
bodaaa la bodaaa belloo!
Tulaliloo para tú belloo! Me
want bananaaa! Para tú
aaaaaah bananaaaa para tú jiji
po kass. Potatoooo tulaliloo
potatoooo chasy me want
bananaaa! Ti aamoo! para tú.
https://github.com/ehdez73/minionize-the-world
The minions