8 Service routing with Spring Cloud Gateway

 

This chapter covers

  • Using a service gateway with your microservices
  • Implementing a service gateway using Spring Cloud Gateway
  • Mapping microservice routes in the gateway
  • Building filters to use correlation ID and tracking

In a distributed architecture like a microservice, there will come a point where we’ll need to ensure that critical behaviors such as security, logging, and tracking users across multiple service calls occur. To implement this functionality, we’ll want these attributes to be consistently enforced across all of our services without the need for each individual development team to build their own solution. While it’s possible to use a common library or framework to assist with building these capabilities directly in an individual service, doing so has these implications:

8.1 What is a service gateway?

8.2 Introducing Spring Cloud Gateway

8.2.1 Setting up the Spring Boot gateway project

8.2.2 Configuring the Spring Cloud Gateway to communicate with Eureka

8.3 Configuring routes in Spring Cloud Gateway

8.3.1 Automated mapping of routes via service discovery

8.3.2 Manually mapping routes using service discovery

8.3.3 Dynamically reloading route configuration

8.4 The real power of Spring Cloud Gateway: Predicate and Filter Factories

8.4.1 Built-in Predicate Factories

8.4.2 Built-in Filter Factories

8.4.3 Custom filters

8.5 Building the pre-filter

8.6 Using the correlation ID in the services

8.6.1 UserContextFilter: Intercepting the incoming HTTP request

8.6.2 UserContext: Making the HTTP headers easily accessible to the service

8.6.3 Custom RestTemplate and UserContextInterceptor: Ensuring that the correlation ID gets propagated

8.7 Building a post-filter receiving correlation ID

Summary

sitemap