API Gateway
API Gateway باستخدام Spring Cloud Gateway
10-15 دقيقة
API Gateway باستخدام Spring Cloud Gateway
تُعدّ API Gateway مكوّنًا أساسيًا في معمارية الخدمات المصغّرة (microservices). فهي تعمل كنقطة دخول موحّدة لجميع العملاء، وتتولى إدارة جوانب مهمة مثل التوجيه والأمان وتحديد معدّل الطلبات.
1. إعداد API Gateway
1.1 إنشاء مشروع 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 الإعداد الأساسي
# 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/
التعليقات
التعليقات مدعومة عبر GitHub Discussions
سجّل الدخول باستخدام GitHub للمشاركة في النقاش