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:
<code>docker pull apache/shenyu-admin:latest</code>Start the admin container:
<code>docker run -p 9095:9095 --name shenyu-admin \
-d apache/shenyu-admin:latest</code>Pull the bootstrap image:
<code>docker pull apache/shenyu-bootstrap</code>Start the bootstrap container (enable local sync and WebSocket URL):
<code>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-bootstrap</code>After 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-adminservice 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-adminprefix from the request URI.
<code># 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/</code>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-portaland
mall-web.
Rate Limiting
To limit traffic for a specific service, enable the RateLimiter plugin (requires a running Redis instance).
Activate
RateLimiterin the plugin management section.
Add a selector for the
mall-portalservice 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.
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.