Apache ShenYu is a Java-based API Gateway designed for service proxy, protocol conversion, and API governance in microservices architectures. It functions as a reactive gateway built on Spring Boot 3.x and Project Reactor, routing and transforming requests to backend services through a plugin-based architecture.
This document provides a high-level overview of ShenYu's architecture, core components, and request processing model. For detailed information about specific subsystems:
Apache ShenYu implements a control plane/data plane separation pattern. shenyu-admin manages and persists configuration; shenyu-bootstrap executes the request pipeline entirely from in-memory caches.
ShenYu Control Plane / Data Plane (key class names shown)
Sources: pom.xml30-52 README.md59-90
The shenyu-bootstrap module is the gateway runtime that handles incoming requests. It runs as a Spring Boot application and processes traffic through a chain of plugins.
Key Classes:
org.apache.shenyu.bootstrap.ShenyuBootstrapApplication - Main entry pointorg.apache.shenyu.web.handler.ShenyuWebHandler - Request handlerorg.apache.shenyu.plugin.base.chain.DefaultShenyuPluginChain - Plugin execution chainThe bootstrap module requires Java 17+ and uses Netty for reactive request handling.
Sources: pom.xml36 README.md107-112 pom.xml84
The shenyu-admin module provides the control plane for managing gateway configuration through a web UI and REST API. It persists configuration to a relational database and notifies gateway instances of changes.
Key Components:
SelectorService — manages routing selectorsRuleService — manages routing rulesPluginService — manages plugin configurationsSources: pom.xml31 README.md100-105
ShenYu supports multiple database backends with a unified schema:
| Database | Support Status |
|---|---|
| H2 | Development/testing |
| MySQL | Production |
| PostgreSQL | Production |
| Oracle | Production |
| OpenGauss | Production |
| OceanBase | Production |
Core Tables:
plugin — plugin definitions and global configurationselector — module-level routing rulesrule — method-level routing rulesmeta_data — service metadata for RPC protocolsdashboard_user — admin user accountsapp_auth — application authentication credentialsSee page 2 for full schema documentation.
Sources: pom.xml108-192
Request Flow Steps:
GlobalPlugin (order=-1) initializes ShenyuContextPluginEnum.codeSources: README.md166-187 README.md190-199
The project is organized as a multi-module Maven build:
Sources: pom.xml30-52
ShenYu provides proxy plugins for multiple RPC protocols:
| Protocol | Plugin | Port | Description |
|---|---|---|---|
| HTTP | divide | 9195 | HTTP/HTTPS proxy |
| Apache Dubbo | dubbo | 9195 | Dubbo RPC proxy |
| gRPC | grpc | 9195 | gRPC protocol conversion |
| Spring Cloud | spring-cloud | 9195 | Spring Cloud service proxy |
| WebSocket | websocket | 9195 | WebSocket protocol support |
| Motan | motan | 9195 | Motan RPC proxy |
| SOFA RPC | sofa | 9195 | SOFA RPC proxy |
| Tars | tars | 9195 | Tars RPC proxy |
Sources: README.md81 pom.xml122 pom.xml128-130
ShenYu includes plugins for authentication, authorization, and traffic management:
app_auth tableSources: README.md82-83
Configuration changes propagate from Admin to Bootstrap instances through seven synchronization mechanisms:
| Strategy | Implementation Class | Use Case |
|---|---|---|
| WebSocket | WebSocketDataChangedListener | Default, low latency |
| ZooKeeper | ZookeeperDataChangedListener | Distributed coordination |
| Nacos | NacosDataChangedListener | Alibaba ecosystem |
| etcd | EtcdDataChangedListener | Kubernetes environments |
| HTTP Long Polling | HttpLongPollingDataChangedListener | No external dependencies |
| Apollo | ApolloDataChangedListener | Apollo configuration center |
| Polaris | PolarisDataChangedListener | Tencent service governance |
Each gateway instance maintains an in-memory ConcurrentHashMap cache updated by the chosen synchronization strategy.
Sources: README.md190-199 pom.xml131-162
ShenYu integrates with multiple service registries:
The DiscoveryUpstreamService abstracts registry interactions, and UpstreamCheckService performs health checks on discovered services.
Sources: README.md81 pom.xml116-162
Namespace isolation is supported via the namespace_id column in configuration tables:
selector.namespace_idrule.namespace_idmeta_data.namespace_idapp_auth.namespace_idThe namespace_plugin_rel table maintains plugin configurations per namespace. See page 4.10 for full multi-tenancy documentation.
Sources: pom.xml30-52
Plugins execute in a defined order specified by PluginEnum.code. Each request traverses all enabled plugins in the DefaultShenyuPluginChain via the ShenyuPlugin.execute() method.
Plugin execution order (PluginEnum sort values)
Plugins are categorized by function:
| Category | Order Range | Examples |
|---|---|---|
| Infrastructure | -1 to 15 | GlobalPlugin, CachePlugin, MetricsPlugin |
| Security | 20–50 | SignPlugin, JwtPlugin, WafPlugin |
| Traffic Control | 60–150 | RateLimiterPlugin, SentinelPlugin, HystrixPlugin |
| Transformation | 70–120 | RequestPlugin, RewritePlugin, RedirectPlugin |
| Proxy | 199–320 | DividePlugin, DubboPlugin, GrpcPlugin, WebSocketPlugin |
| Response | 220–420 | ResponsePlugin, CryptorResponsePlugin |
Sources: README.md164-175
Version 2.7.1 introduces AI proxy capabilities through the aiProxy plugin:
Supported Providers:
Configuration:
provider - AI service providerbaseUrl - API endpoint URLmodel - Model identifier (e.g., gpt-4o-mini)apiKey - Authentication keytemperature - Sampling temperature (0-1)maxTokens - Maximum response tokensstream - Enable streaming responsesprompt - System prompt templateSources: pom.xml189-191
To deploy ShenYu with Docker:
Default admin credentials:
admin123456 (stored SHA-512 hashed in the database)Sources: README.md92-112
Sources: pom.xml84 pom.xml138 README.md202-205
ShenYu's routing configuration follows a three-level hierarchy:
Each level has associated conditions evaluated using operators: match, =, regex, contains, exclude, startsWith, endsWith, pathPattern.
Sources: README.md178-187
ShenYu supports multiple observability integrations:
shenyu-plugin-metricsThe operation_record_log table provides audit trails for configuration changes.
Sources: README.md84 shenyu-admin/src/main/resources/sql-script/h2/schema.sql357-365
Refresh this wiki
This wiki was recently refreshed. Please wait 7 days to refresh again.