0%
API Gateway avec Spring Cloud Gateway

API Gateway

API Gateway avec Spring Cloud Gateway

10-15 min

API Gateway avec Spring Cloud Gateway

L'API Gateway est un composant essentiel dans l'architecture microservices. Il sert de point d'entrée unique pour tous les clients et gère des aspects importants comme le routage, la sécurité, et la limitation de débit.

1. Configuration de l'API Gateway

1.1 Création du Projet Gateway

curl https://start.spring.io/starter.tgz \
    -d dependencies=cloud-gateway,cloud-eureka-client \
    -d groupId=com.example \
    -d artifactId=api-gateway \
    -d name=api-gateway \
    -d description=API%20Gateway%20for%20Microservices \
    -d packageName=com.example.gateway \
    -d packaging=jar \
    -d javaVersion=17 \
    -d type=maven-project \
    | tar -xzvf -

1.2 Configuration de Base

# application.yml
server:
  port: 8080

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lower-case-service-id: true
      routes:
        - id: product-service
          uri: lb://product-service
          predicates:
            - Path=/api/products/**
          filters:
            - StripPrefix=1
            - name: RequestRateLimiter
              args:
                redis-rate-limiter.replenishRate: 10
                redis-rate-limiter.burstCapacity: 20
                key-resolver: "#{@ipKeyResolver}"

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

Commentaires

Les commentaires sont alimentés par GitHub Discussions

Connectez-vous avec GitHub pour participer à la discussion

Lien copié !