SlideShare a Scribd company logo
Spring Cloud
API gateway upgrade & configuration in the cloud.
Speaker
Orkhan Gasimov
Solution design & implementation.
15 years of software engineering;
Teaching training courses.
Architecture, Java, JavaScript / TypeScript.
Author of training courses.
Microservice, Spring Cloud, Akka for Java.
2
Agenda
API Gateway
3
Agenda
API Gateway
Configuration in the cloud
4
Monolith -> Microservices
The price we pay.
Monolithic Architecture
Client Application Database
6
Microservices Architecture
DBService
Client API
DBService
DBService
7
Priorities & Objectives
• Keep things simple.
8
Priorities & Objectives
• Keep things simple.
• Minimum code change.
9
Priorities & Objectives
• Keep things simple.
• Minimum code change.
• Short release cycles.
10
Priorities & Objectives
• Keep things simple.
• Minimum code change.
• Short release cycles.
• Quick changes if necessary.
11
API Design
API Gateway – the single entry point.
API Design
DBService
API
DBService
DBService
13
API Service – deliver API for a special kind of clients.
API Design 14
DBService
API
DBService
DBService
Web
API
Mobile
API
API Versioning – evolve API supporting existing clients.
API Design 15
DBService
API
DBService
DBService
Mobile
API
Web API
v2
Web API
v1
Spring Cloud
Edge Proxy
Zuul
• Spring Cloud Netflix.
@SpringBootApplication
@EnableZuulProxy
public class ApiGateway {
public static void main(String[] args) {
SpringApplication.run(ApiGateway.class, args);
}
}
17
Zuul
• Spring Cloud Netflix.
• Simple configuration.
zuul:
ignored-services: '*’
routes:
api-v2:
path: /api/v2/**
stripPrefix: true
serviceId: apiService
api-v1:
path: /api/v1/**
stripPrefix: true
url: http://service.old
18
Zuul
• Spring Cloud Netflix.
• Simple configuration.
• Advanced filters:
• Pre filters.
• Routing filters.
• Post filters.
“pre” filters “routing” filter(s) “post” filters
“error” filters
“custom” filters
19
Zuul
• Spring Cloud Netflix.
• Simple configuration.
• Advanced filters:
• Pre filters.
• Routing filters.
• Post filters.
• Advanced configuration?
zuul:
ignored-services: '*’
routes:
api-v2:
path: /api/v2/**
stripPrefix: true
serviceId: apiService
api-v1:
path: /api/v1/**
stripPrefix: true
url: http://service.old
“pre” filters “routing”filter(s) “post” filters
“error” filters
“custom” filters
20
Spring Cloud
New API Gateway
Spring Cloud Gateway
• Predicates & Filters.
• Advanced coding.
• Advanced configuration.
Client
Gateway
Proxied
Service
Predicates
Filters
22
Predicates
Spring Cloud Gateway
Predicates
• Check whether a request should be proxied.
Client
Gateway
Proxied
ServicePredicate 1 Predicate N
24
Predicates
• Date-based route predicate factories:
• After - matches requests that happen after the provided datetime.
• Before - matches requests that happen before the provided datetime.
• Between - matches requests that happen between two dates.
spring:
cloud:
gateway:
routes:
- id: test_route
uri: http://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
25
Predicates
• Cookie and Header based route predicate factories:
• Cookie - matches a cookie by name and it’s value by regex.
• Header - matches a header by name and it’s value by regex.
spring:
cloud:
gateway:
routes:
- id: test_route
uri: lb://serviceId
predicates:
- Cookie=chocolate, ch.p
- Header=X-Request-Id, d+
26
Predicates
• Host & Remote Address based route predicate factories:
• Host - matches the Host header that matches the Ant-style pattern.
• RemoteAddr - matches a list of CIDR-notation (IPv4 or IPv6) strings.
spring:
cloud:
gateway:
routes:
- id: test_route
uri: http://example.org
predicates:
- Host=**.somehost.org
- RemoteAddr=192.168.1.1/24
27
Predicates
• Request details based route predicate factories:
• Method - matches HTTP method.
• Path - matches the request path using a Spring PathMatcher pattern.
• Query - matches a query param by name and optionally it’s value by regex.
spring:
cloud:
gateway:
routes:
- id: test_route
uri: http://example.org
predicates:
- Method=GET
- Path=/foo/{segment}
- Query=baz
28
Filters
Spring Cloud Gateway
Filters
• Decorate request before downstreaming to the proxied service.
• Decorate response before upstreaming to the client.
Client
Gateway
Proxied
ServiceFilter N Filter 1
30
Filters
• Filter Factories:
• AddRequestHeader - add a downstream header.
• AddRequestParameter - add a downstream request param.
• AddResponseHeader - add an header to downstream’s response (upstream).
spring:
cloud:
gateway:
routes:
- id: test_route
uri: http://example.org
filters:
- AddRequestHeader=X-Request-Foo, Bar
- AddRequestParameter=foo, bar
- AddResponseHeader=X-Response-Foo, Bar
31
Filters
• Filter Factories:
• Hystrix - wrap filters to Hystrix Command with provided name.
• RequestRateLimiter - set per second limits for requests made by user.
• RedirectTo - send a 300 series status with a redirect url.
• SetStatus - set upstream HTTP status.
spring:
cloud:
gateway:
routes:
- id: hytstrix_route
uri: lb://serviceId
filters:
- Hystrix=myCommandName
32
Filters
• Filter Factories:
• RemoveNonProxyHeaders - removes headers from forwarded requests.
• RemoveRequestHeader - remove a downstream header.
• RemoveResponseHeader - remove an upstream headers.
• SetResponseHeader – set an upstream header (add or replace).
• SecureHeaders - add security headers to the response.
• PreserveHostHeader - send original Host header or the one determined by
http client.
33
Filters
• Filter Factories:
• PrefixPath - add a prefix to downstream request.
• RewritePath - rewrite request path matched by regexp.
• SetPath – manipulate request path using segmented Spring uri templates.
• StripPrefix - strip prefix parts (as many as provided by parts param).
• SaveSession – ensure session is saved before forwarding the call (E.g.
SpringSession with lazy data store).
34
Java API
Spring Cloud Gateway
Java API
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
return builder.routes()
.route(r -> r.host("**.abc.org").and().path("/image/png")
.filters(f ->
f.addResponseHeader("X-TestHeader", "foobar"))
.uri("http://httpbin.org:80")
)
.route(r -> r.path("/image/webp")
.filters(f ->
f.addResponseHeader("X-AnotherHeader", "baz"))
.uri("http://httpbin.org:80")
)
.route(r -> r.order(-1)
.host("**.throttle.org").and().path("/get")
.filters(f -> f.filter(throttle.apply(1,
1,
10,
TimeUnit.SECONDS)))
.uri("http://httpbin.org:80")
)
.build();
}
36
Java API vs Configuration
Spring Cloud Gateway
Pros & Cons
• Java API:
• Predicates benefit from and(), or() and negate() operators.
• Requires rebuild upon change.
38
Pros & Cons
• Java API:
• Predicates benefit from and(), or() and negate() operators.
• Requires rebuild upon change.
• Configuration:
• Predicates are stacked using logical and.
• Benefit from external configuration store.
39
Spring Cloud Config
Configuration Management with External Config Store
Spring Cloud Config
• Load configurations using HTTP instead of local files.
App
(Config Client)
Config
Server
Config Repo
41
Spring Cloud Config
• Load configurations using HTTP instead of local files.
• Config repo:
• Git is default.
• May use SVN, File-based, Vault, JDBC and etc.
App
(Config Client)
Config
Server
Config Repo
42
Spring Cloud Config
• Config server:
@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
public static void main(String[] args) {
SpringApplication.run(ConfigServer.class, args);
}
}
spring.cloud.config.server.git:
uri: http://git.xyz/config-repo
username: user
password: passkey
43
Spring Cloud Config
• Config repo may contain:
• application.yml (or .properties) for common properties.
• AppName.yml for app-specific properties
• AppName-profile.yml for profile-specific properties.
App Specific
Common
Profile Specific
44
Spring Cloud Config
• Config client
• requires a bootstrap.yml file.
spring:
application.name: AppName
cloud.config.uri: http://host:8182
45
Spring Cloud Config
• Config client
• requires a bootstrap.yml file.
• Supports fail-fast & retry:
spring:
application.name: AppName
cloud.config.uri: http://host:8182
spring.cloud.config.failFast: true
spring.cloud.config.retry.initialInterval: 1000
spring.cloud.config.retry.maxAttempts: 6
spring.cloud.config.retry.maxInterval: 2000
spring.cloud.config.retry.multiplier: 1.1
46
Spring Cloud Config
• Encryption & Decryption.
• Supports encrypted values.
• /encrypt & /decrypt endpoints.
• Key may be a symmetric (shared) or an asymmetric one (RSA key pair).
• Values are decrypted by server before sending to client.
• Client-side decryption is also possible.
spring:
datasource:
username: dbuser
password: {cipher}FKSAJDFGYOS8F7GLHAKERGFHLSAJ
47
Spring Cloud Config
• Dynamic refresh.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
48
Spring Cloud Config
• Dynamic refresh.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
49
Spring Cloud Config
• Dynamic refresh.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
50
Spring Cloud Config
• Dynamic refresh.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
51
Spring Cloud Config
• Dynamic refresh.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
52
Spring Cloud Config
• Dynamic refresh.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
53
Spring Cloud Config
• Dynamic refresh.
• @Value & @RefreshScope.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
54
Spring Cloud Config
• Dynamic refresh.
• @Value & @RefreshScope.
• Spring Boot Actuator /refresh endpoint.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
55
Spring Cloud Config
• Dynamic refresh.
• @Value & @RefreshScope.
• Spring Boot Actuator /refresh endpoint.
• Spring Cloud Config Monitor for push notifications.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
56
Spring Cloud Config
• Dynamic refresh.
• @Value & @RefreshScope.
• Spring Boot Actuator /refresh endpoint.
• Spring Cloud Config Monitor for push notifications.
• Spring Cloud Bus for app refresh notifications.
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
57
Summary
Summary
• Spring Cloud API Gateway:
• Zuul – Spring Cloud Netflix.
• Spring Cloud Gateway.
59
Summary
• Spring Cloud API Gateway:
• Zuul – Spring Cloud Netflix.
• Spring Cloud Gateway.
• Spring Cloud Config:
• Configuration management in the cloud.
• Quick configuration refresh (zero-downtime).
60
Summary
• Spring Cloud API Gateway:
• Zuul – Spring Cloud Netflix.
• Spring Cloud Gateway.
• Spring Cloud Config:
• Configuration management in the cloud.
• Quick configuration refresh (zero-downtime).
• Additional modules required:
• Spring Cloud Bus
• Spring Cloud Monitor
61
Thank You!
ogasimov@gmail.com
facebook.com/ogassymov

More Related Content

What's hot (20)

PDF
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Henning Jacobs
 
PDF
Spring boot introduction
Rasheed Waraich
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PDF
Microservices avec Spring Cloud
Florian Beaufumé
 
PDF
Data Parallel Deep Learning
inside-BigData.com
 
PDF
Go Programming Patterns
Hao Chen
 
PDF
Advanced RAG Optimization To Make it Production-ready
Zilliz
 
PDF
Support distributed computing and caching avec hazelcast
ENSET, Université Hassan II Casablanca
 
PDF
Gestion comptes bancaires Spring boot
Abdelhakim HADI ALAOUI
 
PPTX
An Introduction to Prometheus (GrafanaCon 2016)
Brian Brazil
 
PPTX
Apache Tez - Accelerating Hadoop Data Processing
hitesh1892
 
PDF
Opentracing jaeger
Oracle Korea
 
PDF
Alphorm.com Formation Docker (1/2) : Installation et Administration
Alphorm
 
PDF
카프카, 산전수전 노하우
if kakao
 
PDF
10 things to consider when planning your Mule 4 migration
Coforge (Erstwhile WHISHWORKS)
 
PPTX
Spring boot anane maryem ben aziza syrine
Syrine Ben aziza
 
PDF
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
NGINX, Inc.
 
PDF
Building a Streaming Pipeline on Kubernetes Using Kafka Connect, KSQLDB & Apa...
HostedbyConfluent
 
PDF
Monitoring with Prometheus
Richard Langlois P. Eng.
 
PDF
Support de cours angular
ENSET, Université Hassan II Casablanca
 
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Henning Jacobs
 
Spring boot introduction
Rasheed Waraich
 
Spring Framework - Core
Dzmitry Naskou
 
Microservices avec Spring Cloud
Florian Beaufumé
 
Data Parallel Deep Learning
inside-BigData.com
 
Go Programming Patterns
Hao Chen
 
Advanced RAG Optimization To Make it Production-ready
Zilliz
 
Support distributed computing and caching avec hazelcast
ENSET, Université Hassan II Casablanca
 
Gestion comptes bancaires Spring boot
Abdelhakim HADI ALAOUI
 
An Introduction to Prometheus (GrafanaCon 2016)
Brian Brazil
 
Apache Tez - Accelerating Hadoop Data Processing
hitesh1892
 
Opentracing jaeger
Oracle Korea
 
Alphorm.com Formation Docker (1/2) : Installation et Administration
Alphorm
 
카프카, 산전수전 노하우
if kakao
 
10 things to consider when planning your Mule 4 migration
Coforge (Erstwhile WHISHWORKS)
 
Spring boot anane maryem ben aziza syrine
Syrine Ben aziza
 
Unit 1: Apply the Twelve-Factor App to Microservices Architectures
NGINX, Inc.
 
Building a Streaming Pipeline on Kubernetes Using Kafka Connect, KSQLDB & Apa...
HostedbyConfluent
 
Monitoring with Prometheus
Richard Langlois P. Eng.
 
Support de cours angular
ENSET, Université Hassan II Casablanca
 

Similar to Spring Cloud: API gateway upgrade & configuration in the cloud (20)

PDF
AAI-3218 Production Deployment Best Practices for WebSphere Liberty Profile
WASdev Community
 
PDF
Kubernetes on AWS
Grant Ellis
 
PDF
Kubernetes on AWS
Grant Ellis
 
PPTX
Azure cosmosdb
Udaiappa Ramachandran
 
PPTX
Architectures, Frameworks and Infrastructure
harendra_pathak
 
PDF
Priming Your Teams For Microservice Deployment to the Cloud
Matt Callanan
 
PDF
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
Neo4j
 
PPTX
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
VMware Tanzu
 
PDF
MLflow Model Serving
Databricks
 
PDF
(ATS6-PLAT04) Query service
BIOVIA
 
PPTX
Building microservices sample application
Anil Allewar
 
PPTX
20171122 aws usergrp_coretech-spn-cicd-aws-v01
Scott Miao
 
PPTX
From Kafka to BigQuery - Strata Singapore
Ofir Sharony
 
PDF
Opal: Simple Web Services Wrappers for Scientific Applications
Sriram Krishnan
 
PDF
6 tips for improving ruby performance
Engine Yard
 
PPTX
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
Sencha
 
PPTX
Spring Cloud Config
Theerut Bunkhanphol
 
PDF
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
IBM DevOps
 
PDF
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Claudia Ring
 
PPTX
Women Who Code - RSpec JSON API Workshop
Eddie Lau
 
AAI-3218 Production Deployment Best Practices for WebSphere Liberty Profile
WASdev Community
 
Kubernetes on AWS
Grant Ellis
 
Kubernetes on AWS
Grant Ellis
 
Azure cosmosdb
Udaiappa Ramachandran
 
Architectures, Frameworks and Infrastructure
harendra_pathak
 
Priming Your Teams For Microservice Deployment to the Cloud
Matt Callanan
 
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
Neo4j
 
SpringOne Tour: An Introduction to Azure Spring Apps Enterprise
VMware Tanzu
 
MLflow Model Serving
Databricks
 
(ATS6-PLAT04) Query service
BIOVIA
 
Building microservices sample application
Anil Allewar
 
20171122 aws usergrp_coretech-spn-cicd-aws-v01
Scott Miao
 
From Kafka to BigQuery - Strata Singapore
Ofir Sharony
 
Opal: Simple Web Services Wrappers for Scientific Applications
Sriram Krishnan
 
6 tips for improving ruby performance
Engine Yard
 
SenchaCon 2016: Upgrading an Ext JS 4.x Application to Ext JS 6.x - Mark Linc...
Sencha
 
Spring Cloud Config
Theerut Bunkhanphol
 
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
IBM DevOps
 
Deploying to and Configuring WebSphere Application Server with UrbanCode Deploy
Claudia Ring
 
Women Who Code - RSpec JSON API Workshop
Eddie Lau
 
Ad

More from Orkhan Gasimov (15)

PPTX
Complex Application Design
Orkhan Gasimov
 
PPTX
Cloud Native Spring - The role of Spring Cloud after Kubernetes became a main...
Orkhan Gasimov
 
PPTX
Digital Transformation - Why? How? What?
Orkhan Gasimov
 
PPTX
Service Mesh - Why? How? What?
Orkhan Gasimov
 
PPTX
Angular Web Components
Orkhan Gasimov
 
PPTX
Vert.x - Reactive & Distributed [Devoxx version]
Orkhan Gasimov
 
PPTX
Vertx - Reactive & Distributed
Orkhan Gasimov
 
PPTX
Designing Fault Tolerant Microservices
Orkhan Gasimov
 
PPTX
Refactoring Monolith to Microservices
Orkhan Gasimov
 
PPTX
Fault Tolerance in Distributed Environment
Orkhan Gasimov
 
PPTX
Angular or React
Orkhan Gasimov
 
PPTX
Patterns of Distributed Application Design
Orkhan Gasimov
 
PDF
Secured REST Microservices with Spring Cloud
Orkhan Gasimov
 
PDF
Data Microservices with Spring Cloud
Orkhan Gasimov
 
PDF
Spring Cloud: Why? How? What?
Orkhan Gasimov
 
Complex Application Design
Orkhan Gasimov
 
Cloud Native Spring - The role of Spring Cloud after Kubernetes became a main...
Orkhan Gasimov
 
Digital Transformation - Why? How? What?
Orkhan Gasimov
 
Service Mesh - Why? How? What?
Orkhan Gasimov
 
Angular Web Components
Orkhan Gasimov
 
Vert.x - Reactive & Distributed [Devoxx version]
Orkhan Gasimov
 
Vertx - Reactive & Distributed
Orkhan Gasimov
 
Designing Fault Tolerant Microservices
Orkhan Gasimov
 
Refactoring Monolith to Microservices
Orkhan Gasimov
 
Fault Tolerance in Distributed Environment
Orkhan Gasimov
 
Angular or React
Orkhan Gasimov
 
Patterns of Distributed Application Design
Orkhan Gasimov
 
Secured REST Microservices with Spring Cloud
Orkhan Gasimov
 
Data Microservices with Spring Cloud
Orkhan Gasimov
 
Spring Cloud: Why? How? What?
Orkhan Gasimov
 
Ad

Recently uploaded (20)

PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Digital Circuits, important subject in CS
contactparinay1
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 

Spring Cloud: API gateway upgrade & configuration in the cloud

  • 1. Spring Cloud API gateway upgrade & configuration in the cloud.
  • 2. Speaker Orkhan Gasimov Solution design & implementation. 15 years of software engineering; Teaching training courses. Architecture, Java, JavaScript / TypeScript. Author of training courses. Microservice, Spring Cloud, Akka for Java. 2
  • 8. Priorities & Objectives • Keep things simple. 8
  • 9. Priorities & Objectives • Keep things simple. • Minimum code change. 9
  • 10. Priorities & Objectives • Keep things simple. • Minimum code change. • Short release cycles. 10
  • 11. Priorities & Objectives • Keep things simple. • Minimum code change. • Short release cycles. • Quick changes if necessary. 11
  • 13. API Gateway – the single entry point. API Design DBService API DBService DBService 13
  • 14. API Service – deliver API for a special kind of clients. API Design 14 DBService API DBService DBService Web API Mobile API
  • 15. API Versioning – evolve API supporting existing clients. API Design 15 DBService API DBService DBService Mobile API Web API v2 Web API v1
  • 17. Zuul • Spring Cloud Netflix. @SpringBootApplication @EnableZuulProxy public class ApiGateway { public static void main(String[] args) { SpringApplication.run(ApiGateway.class, args); } } 17
  • 18. Zuul • Spring Cloud Netflix. • Simple configuration. zuul: ignored-services: '*’ routes: api-v2: path: /api/v2/** stripPrefix: true serviceId: apiService api-v1: path: /api/v1/** stripPrefix: true url: http://service.old 18
  • 19. Zuul • Spring Cloud Netflix. • Simple configuration. • Advanced filters: • Pre filters. • Routing filters. • Post filters. “pre” filters “routing” filter(s) “post” filters “error” filters “custom” filters 19
  • 20. Zuul • Spring Cloud Netflix. • Simple configuration. • Advanced filters: • Pre filters. • Routing filters. • Post filters. • Advanced configuration? zuul: ignored-services: '*’ routes: api-v2: path: /api/v2/** stripPrefix: true serviceId: apiService api-v1: path: /api/v1/** stripPrefix: true url: http://service.old “pre” filters “routing”filter(s) “post” filters “error” filters “custom” filters 20
  • 22. Spring Cloud Gateway • Predicates & Filters. • Advanced coding. • Advanced configuration. Client Gateway Proxied Service Predicates Filters 22
  • 24. Predicates • Check whether a request should be proxied. Client Gateway Proxied ServicePredicate 1 Predicate N 24
  • 25. Predicates • Date-based route predicate factories: • After - matches requests that happen after the provided datetime. • Before - matches requests that happen before the provided datetime. • Between - matches requests that happen between two dates. spring: cloud: gateway: routes: - id: test_route uri: http://example.org predicates: - After=2017-01-20T17:42:47.789-07:00[America/Denver] 25
  • 26. Predicates • Cookie and Header based route predicate factories: • Cookie - matches a cookie by name and it’s value by regex. • Header - matches a header by name and it’s value by regex. spring: cloud: gateway: routes: - id: test_route uri: lb://serviceId predicates: - Cookie=chocolate, ch.p - Header=X-Request-Id, d+ 26
  • 27. Predicates • Host & Remote Address based route predicate factories: • Host - matches the Host header that matches the Ant-style pattern. • RemoteAddr - matches a list of CIDR-notation (IPv4 or IPv6) strings. spring: cloud: gateway: routes: - id: test_route uri: http://example.org predicates: - Host=**.somehost.org - RemoteAddr=192.168.1.1/24 27
  • 28. Predicates • Request details based route predicate factories: • Method - matches HTTP method. • Path - matches the request path using a Spring PathMatcher pattern. • Query - matches a query param by name and optionally it’s value by regex. spring: cloud: gateway: routes: - id: test_route uri: http://example.org predicates: - Method=GET - Path=/foo/{segment} - Query=baz 28
  • 30. Filters • Decorate request before downstreaming to the proxied service. • Decorate response before upstreaming to the client. Client Gateway Proxied ServiceFilter N Filter 1 30
  • 31. Filters • Filter Factories: • AddRequestHeader - add a downstream header. • AddRequestParameter - add a downstream request param. • AddResponseHeader - add an header to downstream’s response (upstream). spring: cloud: gateway: routes: - id: test_route uri: http://example.org filters: - AddRequestHeader=X-Request-Foo, Bar - AddRequestParameter=foo, bar - AddResponseHeader=X-Response-Foo, Bar 31
  • 32. Filters • Filter Factories: • Hystrix - wrap filters to Hystrix Command with provided name. • RequestRateLimiter - set per second limits for requests made by user. • RedirectTo - send a 300 series status with a redirect url. • SetStatus - set upstream HTTP status. spring: cloud: gateway: routes: - id: hytstrix_route uri: lb://serviceId filters: - Hystrix=myCommandName 32
  • 33. Filters • Filter Factories: • RemoveNonProxyHeaders - removes headers from forwarded requests. • RemoveRequestHeader - remove a downstream header. • RemoveResponseHeader - remove an upstream headers. • SetResponseHeader – set an upstream header (add or replace). • SecureHeaders - add security headers to the response. • PreserveHostHeader - send original Host header or the one determined by http client. 33
  • 34. Filters • Filter Factories: • PrefixPath - add a prefix to downstream request. • RewritePath - rewrite request path matched by regexp. • SetPath – manipulate request path using segmented Spring uri templates. • StripPrefix - strip prefix parts (as many as provided by parts param). • SaveSession – ensure session is saved before forwarding the call (E.g. SpringSession with lazy data store). 34
  • 36. Java API @Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) { return builder.routes() .route(r -> r.host("**.abc.org").and().path("/image/png") .filters(f -> f.addResponseHeader("X-TestHeader", "foobar")) .uri("http://httpbin.org:80") ) .route(r -> r.path("/image/webp") .filters(f -> f.addResponseHeader("X-AnotherHeader", "baz")) .uri("http://httpbin.org:80") ) .route(r -> r.order(-1) .host("**.throttle.org").and().path("/get") .filters(f -> f.filter(throttle.apply(1, 1, 10, TimeUnit.SECONDS))) .uri("http://httpbin.org:80") ) .build(); } 36
  • 37. Java API vs Configuration Spring Cloud Gateway
  • 38. Pros & Cons • Java API: • Predicates benefit from and(), or() and negate() operators. • Requires rebuild upon change. 38
  • 39. Pros & Cons • Java API: • Predicates benefit from and(), or() and negate() operators. • Requires rebuild upon change. • Configuration: • Predicates are stacked using logical and. • Benefit from external configuration store. 39
  • 40. Spring Cloud Config Configuration Management with External Config Store
  • 41. Spring Cloud Config • Load configurations using HTTP instead of local files. App (Config Client) Config Server Config Repo 41
  • 42. Spring Cloud Config • Load configurations using HTTP instead of local files. • Config repo: • Git is default. • May use SVN, File-based, Vault, JDBC and etc. App (Config Client) Config Server Config Repo 42
  • 43. Spring Cloud Config • Config server: @SpringBootApplication @EnableConfigServer public class ConfigServer { public static void main(String[] args) { SpringApplication.run(ConfigServer.class, args); } } spring.cloud.config.server.git: uri: http://git.xyz/config-repo username: user password: passkey 43
  • 44. Spring Cloud Config • Config repo may contain: • application.yml (or .properties) for common properties. • AppName.yml for app-specific properties • AppName-profile.yml for profile-specific properties. App Specific Common Profile Specific 44
  • 45. Spring Cloud Config • Config client • requires a bootstrap.yml file. spring: application.name: AppName cloud.config.uri: http://host:8182 45
  • 46. Spring Cloud Config • Config client • requires a bootstrap.yml file. • Supports fail-fast & retry: spring: application.name: AppName cloud.config.uri: http://host:8182 spring.cloud.config.failFast: true spring.cloud.config.retry.initialInterval: 1000 spring.cloud.config.retry.maxAttempts: 6 spring.cloud.config.retry.maxInterval: 2000 spring.cloud.config.retry.multiplier: 1.1 46
  • 47. Spring Cloud Config • Encryption & Decryption. • Supports encrypted values. • /encrypt & /decrypt endpoints. • Key may be a symmetric (shared) or an asymmetric one (RSA key pair). • Values are decrypted by server before sending to client. • Client-side decryption is also possible. spring: datasource: username: dbuser password: {cipher}FKSAJDFGYOS8F7GLHAKERGFHLSAJ 47
  • 48. Spring Cloud Config • Dynamic refresh. App (Config Client) Config Server Config Repo Cloud Bus 48
  • 49. Spring Cloud Config • Dynamic refresh. App (Config Client) Config Server Config Repo Cloud Bus 49
  • 50. Spring Cloud Config • Dynamic refresh. App (Config Client) Config Server Config Repo Cloud Bus 50
  • 51. Spring Cloud Config • Dynamic refresh. App (Config Client) Config Server Config Repo Cloud Bus 51
  • 52. Spring Cloud Config • Dynamic refresh. App (Config Client) Config Server Config Repo Cloud Bus 52
  • 53. Spring Cloud Config • Dynamic refresh. App (Config Client) Config Server Config Repo Cloud Bus 53
  • 54. Spring Cloud Config • Dynamic refresh. • @Value & @RefreshScope. App (Config Client) Config Server Config Repo Cloud Bus 54
  • 55. Spring Cloud Config • Dynamic refresh. • @Value & @RefreshScope. • Spring Boot Actuator /refresh endpoint. App (Config Client) Config Server Config Repo Cloud Bus 55
  • 56. Spring Cloud Config • Dynamic refresh. • @Value & @RefreshScope. • Spring Boot Actuator /refresh endpoint. • Spring Cloud Config Monitor for push notifications. App (Config Client) Config Server Config Repo Cloud Bus 56
  • 57. Spring Cloud Config • Dynamic refresh. • @Value & @RefreshScope. • Spring Boot Actuator /refresh endpoint. • Spring Cloud Config Monitor for push notifications. • Spring Cloud Bus for app refresh notifications. App (Config Client) Config Server Config Repo Cloud Bus 57
  • 59. Summary • Spring Cloud API Gateway: • Zuul – Spring Cloud Netflix. • Spring Cloud Gateway. 59
  • 60. Summary • Spring Cloud API Gateway: • Zuul – Spring Cloud Netflix. • Spring Cloud Gateway. • Spring Cloud Config: • Configuration management in the cloud. • Quick configuration refresh (zero-downtime). 60
  • 61. Summary • Spring Cloud API Gateway: • Zuul – Spring Cloud Netflix. • Spring Cloud Gateway. • Spring Cloud Config: • Configuration management in the cloud. • Quick configuration refresh (zero-downtime). • Additional modules required: • Spring Cloud Bus • Spring Cloud Monitor 61