Master Apache ShenYu: Code‑Free API Gateway Setup, HTTP Proxy & Rate Limiting
This article introduces Apache ShenYu, a high‑performance, visual API gateway, walks through Docker‑based installation of its admin and bootstrap containers, demonstrates HTTP proxy and address‑rewrite configuration for a SpringBoot e‑commerce project, and shows how to enable rate‑limiting using the built‑in plugins.
ShenYu Overview
Apache ShenYu is an asynchronous, high‑performance, cross‑language, reactive API gateway with over 8.5k stars on GitHub.
Key features include:
Support for multiple proxy protocols: HTTP, Dubbo, Spring Cloud, gRPC, WebSocket, MQTT, etc.
Various authentication methods: Sign, OAuth2, JWT, BasicAuth, WAF.
API governance: request/response handling, parameter mapping, load balancing, circuit breaking, rate limiting.
Visual management with dynamic traffic control, permission and plugin management.
Rich plugin ecosystem with hot‑plug and dynamic loading.
Clients for Java, Go, Python, and other languages.
Installation
Running ShenYu in a Docker environment requires both the ShenYu Admin and ShenYu Bootstrap containers.
Pull the admin image: docker pull apache/shenyu-admin:latest Start the admin container:
docker run -p 9095:9095 --name shenyu-admin \
-d apache/shenyu-admin:latestPull the bootstrap image: docker pull apache/shenyu-bootstrap Start the bootstrap container (enable local sync and WebSocket URL):
docker run -p 9195:9195 --name shenyu-bootstrap \
-e "shenyu.local.enabled=true" \
--env SHENYU_SYNC_WEBSOCKET_URLS=ws://192.168.3.101:9095/websocket \
-d apache/shenyu-bootstrapAfter both containers are running, access the visual console at http://192.168.3.101:9095 (default admin:123456).
Usage Example – Mall Project
We use the "mall" e‑commerce demo (SpringBoot3 + Vue) to illustrate ShenYu's HTTP proxy and rate‑limiting features.
Service Overview
mall-admin – backend management API (http://192.168.3.101:8080) → gateway: http://192.168.3.101:9195/mall-admin/
mall-portal – front‑store API (http://192.168.3.101:8085) → gateway: http://192.168.3.101:9195/mall-portal/
mall-web – admin front‑end (http://192.168.3.101/admin/) → gateway: http://192.168.3.101:9195/mall-web/admin/
HTTP Proxy Configuration
Add a selector for the mall-admin service in the Divide plugin and set the upstream URL to 192.168.3.101:8080.
Define a rule matching the prefix /mall-admin/** with the pattern /** to forward all paths.
Enable the Rewrite plugin to strip the /mall-admin prefix from the request URI.
# Through gateway
http://192.168.3.101:9195/mall-admin/swagger-ui/
# Forwarded to backend (original)
http://192.168.3.101:8080/mall-admin/swagger-ui/
# Correctly rewritten
http://192.168.3.101:8080/swagger-ui/After enabling the rewrite rule, the API docs are reachable at http://192.168.3.101:9195/mall-admin/swagger-ui/ . The same steps apply to mall-portal and mall-web.
Rate Limiting
To limit traffic for a specific service, enable the RateLimiter plugin (requires a running Redis instance).
Activate RateLimiter in the plugin management section.
Add a selector for the mall-portal service under FaultTolerance → RateLimiter .
Configure a token‑bucket rule using Redis; the UI shows parameters such as replenish rate and burst capacity.
When the limit is exceeded, requests to http://192.168.3.101:9195/mall-portal/home/content return a rate‑limit error.
Plugin Ecosystem
ShenYu provides a rich set of plugins for request processing, traffic governance, circuit breaking, security, logging, and caching. Commonly used plugins include Context Path, ModifyResponse, ParamMapping, Rewrite, Divide (HTTP, Dubbo, gRPC, etc.), Hystrix, RateLimiter, Sentinel, Sign, JWT, OAuth2, WAF, Logging, and Cache.
Conclusion
Apache ShenYu offers a powerful, visual API‑gateway solution that eliminates the need for custom code when implementing routing, authentication, traffic control, and rate limiting. Its extensive plugin ecosystem makes it suitable for a wide range of microservice scenarios.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
