1. Overview
1.1 Plugin Name
dividePlugin
1.2 Appropriate Scenario
- Handling
http protocolrequests. - Support traffic management, such as a/b test, grayscale test.
- Service Load Balancing.
- Set request timeout.
1.3 Plugin functionality
- Supports traffic management based on request information such as uri, header, and query.
- Supports configurable load balancing and service warm-up. See
loadBalancein the rule configuration below for supported algorithms. - Supports setting the maximum value of the request header, the maximum value of the request body, and the request level timeout.
- Supports setting the timeout retry policy and the number of retries. Currently, the retry policy supports: current (retrying the server that failed before) and failover (retrying other servers).
1.4 Plugin Code
- Core module is
shenyu-plugin-divide. - Core class is
org.apache.shenyu.plugin.divide.DividePlugin.
2. How to use plugin
2.1 Plugin-use procedure chart

2.2 Import pom
- Import maven in shenyu-bootstrap project's
pom.xmlfile.
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-gateway</artifactId>
<version>${project.version}</version>
</dependency>
2.3 Enable plugin
- In
shenyu-admin--> BasicConfig --> Plugin -->divideset Status enable.

2.4 Config plugin
2.4.1 Configure access parameters in the client project configuration file
- Client access method and server address. The following example uses the http access method. Currently, the client supports the following access methods: http, zookeeper, etcd, nacos, consul. For detailed access configuration parameters, please refer to Client Access Configuration.
- Client configuration, including the protocol name and the routing address of the service, please use the http protocol here, and the value of contextPath must be configured as the routing address of each service.
shenyu:
register:
registerType: http
serverLists: http://localhost:9095
props:
username: admin
password: 123456
client:
http: # http protocol
props:
contextPath: /http # routing address for each service
2.4.2 Configure upstream validity detection parameters in the shenyu-admin configuration file
The following example uses the http access method. Currently, the client supports the following access methods: http, zookeeper, etcd, nacos, consul. For detailed access configuration parameters, please refer to Client Access Configuration.
Only http-type registries support upstream detection.
shenyu:
register:
registerType: http # Only http-type register center support upstream detection.
serverLists:
props:
checked: true # The default is true, set to false, do not detect.
zombieCheckTimes: 5 # The maximum number of zombie upstream detections. If it exceeds 5 times, its validity will no longer be detected. The default value is 5.
scheduledTime: 10 # Timing detection interval, the default is 10 seconds.
zombieRemovalTimes: 60 # How many seconds the upstream is offline to be considered as a zombie upstream, the default is 60 seconds.
2.4.3 Configure the selector and rule information of the divide plugin in shenyu-admin
After the client is started, the selector and rule information will be automatically registered in shenyu-admin -> Plugin List -> Proxy -> Divide.

2.4.3.1 Selector configuration
Example of divide selector. For general selector configuration, please refer to Selectors and Rules.

2.4.3.1.1 Selector handling information configuration
host: fill inlocalhost, this field is not used currently.ip:port:ipand port, fill in theip+ port of your real service here.protocol:httpprotocol, fill inhttp:orhttps:, if not fill in, the default is:http:.startupTime: Startup time in milliseconds.weight: load balancing weight, the default value of service startup automatic registration is 50.warmupTime: Warmup time, in milliseconds. The server during warmup will calculate the instantaneous weight, and the calculated value will be smaller than the actual configured weight to protect the server just started. The default value of service startup registration is 10. For example, the warm-up time is 100 milliseconds, the current startup is 50 milliseconds, the configured weight is 50, and the actual weight is 25.status: On or off, this selector is valid only in the on state.
2.4.3.2 Processing information configuration of rules
Example of divide rule. For general rule configuration, please refer to selectors and rules.

2.4.3.2.1 Rule processing information configuration
The loadBalance, timeout, retry, retryStrategy and retryBackOffSpec fields below describe the released v2.7.2 implementation. requestTimeout and poolGroup are available only in 2.7.3-SNAPSHOT.
loadBalance: Selects an upstream for HTTP requests. In ShenYu 2.7.2, the supported values arerandom(default),roundRobin,hash,leastActive,p2c, andshortestResponse. Thehashstrategy uses consistent hashing by client IP. TheleastActivestrategy selects the upstream with the fewest in-flight requests and uses warm-up-adjusted weights to break ties.timeout: The timeout of a single call attempt to thehttpclient, in milliseconds, the default value is 3000. Inv2.7.2, or withrequestTimeoutomitted in2.7.3-SNAPSHOT, an attempt ends when the response headers arrive, so the deadline covers establishing the connection, waiting for the response and reading the headers - not the response body. In2.7.3-SNAPSHOT, configuringrequestTimeout(including0) makes each attempt body-aware and caps it by thistimeout; a positiverequestTimeoutadditionally bounds the whole sequence.retry: The number of retries after a failed call, the default value is 3. Eligibility depends on the selectedretryStrategyandretryBackOffSpec: the legacycurrentstrategy retriesTimeoutException,ConnectTimeoutException,ReadTimeoutExceptionandIllegalStateException, but excludesDataBufferLimitException; the default FAILOVER path retries every error (th -> true), whilefixedandexponentialretry onlyGETrequests and their transient transport failures (plus upstream 5xx statuses when used withfailover).DataBufferLimitExceptionis therefore retried only by the default FAILOVER path.headerMaxSize: The maximum value of the requestedheader.requestMaxSize: The maximum value of the request body.retryStrategy: Supported since2.4.3, retry strategy after failure, defaultcurrentto maintain compatibility with lower versions. For example, there are 3 downstream serviceshttp:localhost:1111,http:localhost:1112andhttp:localhost:1113, assuming the first load balancing tohttp:localhost:1111andcall failed. Using thecurrentstrategy will continue to retry callinghttp:localhost:1111; using thefailoverstrategy will retry calling other services such ashttp:localhost:1112through theload balancing, if it fails again at this time , call tohttp:localhost:1113until no service is available.retryBackOffSpec: The back-off used between retries, the default isdefault. WithretryStrategy=current,defaultuses a capped random back-off (20 ms initial, 20 s cap, 0.5 jitter);fixeduses a flat 2 s delay;exponentialuses an exponential back-off starting at 500 ms with a 5 s cap. WithretryStrategy=failover,defaultretries immediately with no back-off, whilefixedandexponentialkeep their respective delays. Inv2.7.2,currentretries andfixed/exponentialretries (including FAILOVER) are guarded by the aggregate budget(retry + 1) * timeout + retry * maximumBackoff, wheremaximumBackoffis 20 s, 2 s or 5 s respectively; the default FAILOVER path has neither this budget nor back-off.requestTimeout: Optional whole-request deadline in milliseconds, available only in2.7.3-SNAPSHOT. Omitted (null) selects the legacy mode: each attempt is bounded bytimeoutonly up to the response headers, and the sequence is guarded by an implicit aggregate budget(retry + 1) * timeout + retry * maximumBackoff, except for the default FAILOVER path, where neither the budget nor back-off applies. A positive value bounds the whole retry sequence - every attempt, the back-off in between and writing the response body - and an expired deadline returnsHTTP 504; the implicit aggregate budget is skipped because this deadline owns the sequence.0disables the whole-request timer and skips the implicit budget, but each attempt remains body-aware and is still capped bytimeout.poolGroup: Optional, available only in2.7.3-SNAPSHOT. Selects a named connection pool defined inshenyu.httpclient.pool-groups(see the gateway property config page). An unknown group name returnsHTTP 503instead of falling back to the shared default pool.
In v2.7.2, the legacy current strategy maps attempt-count exhaustion to HTTP 408 ("the maximum number of retry times has been exceeded"). fixed and exponential rethrow the last failure, which surfaces as HTTP 504 for transport timeouts. failover still uses the retry count: it returns HTTP 503 when no healthy upstream remains, but an exhausted configured attempt timeout maps to HTTP 504, not 503 or 408. For the budgeted paths, expiry of the aggregate retry budget returns HTTP 504.
In 2.7.3-SNAPSHOT, when requestTimeout is configured (including 0) and the terminal failure is a TimeoutException, that failure is rethrown and maps to HTTP 504 instead of HTTP 408; other terminal failures keep the HTTP 408 mapping. When a positive requestTimeout expires first, the client returns HTTP 504.
A status can only be set while the response headers are still unwritten. Once a streaming response has been committed, a deadline that expires afterwards can only truncate the body, not replace the status the client already received.
- An ordinary request is bounded per attempt by
timeout(3000 ms by default). With the defaultcurrentstrategy, exhausting the retry count returnsHTTP 408; if the aggregate budget expires first, the result isHTTP 504. - A slow streaming response (SSE, long polling) is a different case. In
v2.7.2, or withrequestTimeoutomitted in2.7.3-SNAPSHOT, an active stream can outlivetimeoutas long as the reads keep completing. Inv2.7.2, size the transport timeouts for the expected stream. In2.7.3-SNAPSHOT, set a positiverequestTimeoutto bound the whole sequence including the body; withrequestTimeout: 0, the whole-request timer is off, but each attempt remains body-aware and is capped bytimeout. Disablingshenyu.httpclient.responseTimeoutalone does not remove the transport-level read deadlines (shenyu.httpclient.readTimeoutand the idle thresholds).
2.5 Examples
2.5.1 Example A/B Test
To be added, welcome contribute.
2.5.2 Example Grayscale Test
To be added, welcome contribute.
3. How to disable plugin
- In
shenyu-admin--> BasicConfig --> Plugin -->divideset Status disable.
