My SpringCloud Gateway has lots of globla filters , the sentinel filter is first .
when the try number is larger than setting number, i hope that the sentinel throws the exception and finish,
but because of code chain.filter(exchange) ,all the filter would be excuted ,then throws my exception .
i want to ask that ,how to throw exception immediately if over the setting number , don't excute the other filters
9条答案
按热度按时间bprjcwpo1#
Hi, could you please give a code snippet to demonstrate your problem?
mrzz3bfm2#
First Filter:
Copy of SentinelGatewayFilter:
Last Filter:
I thought the demo would stop on the SentinelFilter(Order 2) and throws Exception, but the LastFilter(Order 3) printed and throwed exception then.
hsvhsicv3#
I'll take a view these days.
tgabmvqs4#
i think you need to adjust the filter's excution order,when the sentinel‘s filter is first execute Filter and throws exception, other’s filter has no time to execute。
c8ib6hqw5#
i think you need to adjust the filter's excution order,when the sentinel‘s filter is first execute Filter and throws exception, other’s filter has no time to execute。
I Had try what u said, I deleted the first Filter, Sentinel Filter is first, but the last Filter still excuted and printed,then throws the FlowException...
rwqw0loc6#
I'll take a view these days.
Big god , pay attention to my question please! We Need U
ee7vknir7#
May the problem locates on this line?
chain.filter at the beginning invoke the next filter first in future.
83qze16e8#
The filters in Spring Cloud Gateway is reactive (i.e. asynchronous), so
chain.filter(exchange)
does not actually invoke the next filter. The filters are invoked on subscription (i.e. when requests are coming).The Sentinel Reactor operator wraps the
subscribe
operation with the Sentinel subscriber. For example:This will trigger the
onSubscribe
event for downstream. The filter chain is wrapped withMono.defer()
, which will be triggered on subscription. SeeFilterWebHandler
of Spring Cloud Gateway:The asynchronous part of the proceeding filters won't be called actually (the Sentinel reactor subscriber will cut down the event if blocked). But this should be resolved, as some operations (not in the reactive stream) are indeed performed during subscription from upstream (this might be difficult to understand).
rsl1atfo9#
I also encountered the same problem. There are some custom filters in my gateway to process services, such as authorization authentication. When I put SentinelGatewayFilter first in the Filter chain, due to the line of Mono asyncResult = chain.filter(exchange), when ParamFlowException is thrown, SpringCloudGateway returns Mono.empty(), which is not expected of. The reason is because other business Filter has also been executed and committed Response. My expectation is that when the current limit occurs, it will not enter other filters. But now, I can only put SentinelGatewayFilter at the end. When other Filters are committed, I no longer enter SentinelGatewayFilter and return Response directly.