消费者那边似乎无法抓到SentinelRpcException 异常.
会显示报错异常信息. 大概是这样子..... 那么我把限流规则配在服务端这边... 消费端被限流了... 我莫非还要对异常里的具体信息 进行判断吗....
因为不对异常做判断的话. 这有两种可能 一种是Dubbo服务提供方调用异常. 一种是 被限流了. 但是如果把限流规则配在消费端的话 可以抓取到SentinelRpcException异常 然后走里面的业务逻辑.....
com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote method: sayHello, provider: dubbo://127.0.0.1:25758/com.alibaba.csp.sentinel.demo.dubbo.FooService?application=demo-consumer&dubbo=2.6.2&interface=com.alibaba.csp.sentinel.demo.dubbo.FooService&methods=doAnother,sayHello&pid=1082®ister.ip=10.6.24.97&side=consumer&timeout=3000×tamp=1546417423254, cause: com.alibaba.csp.sentinel.slots.block.SentinelRpcException: com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.SentinelRpcException: com.alibaba.csp.sentinel.slots.block.flow.FlowException Caused by: com.alibaba.csp.sentinel.slots.block.flow.FlowException
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:100)
at com.alibaba.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:148)
at com.alibaba.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:77)
at com.alibaba.csp.sentinel.adapter.dubbo.SentinelDubboConsumerFilter.invoke(SentinelDubboConsumerFilter.java:60)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.csp.sentinel.adapter.dubbo.DubboAppContextFilter.invoke(DubboAppContextFilter.java:41)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:48)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
at com.alibaba.dubbo.common.bytecode.proxy0.sayHello(proxy0.java)
at com.alibaba.csp.sentinel.demo.dubbo.consumer.FooServiceConsumer.sayHello(FooServiceConsumer.java:30)
at com.alibaba.csp.sentinel.demo.dubbo.demo2.FooConsumerBootstrap.lambda$main$0(FooConsumerBootstrap.java:63)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.alibaba.dubbo.remoting.RemotingException: com.alibaba.csp.sentinel.slots.block.SentinelRpcException: com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.SentinelRpcException: com.alibaba.csp.sentinel.slots.block.flow.FlowException Caused by: com.alibaba.csp.sentinel.slots.block.flow.FlowException
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.returnFromResponse(DefaultFuture.java:222)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:139)
at com.alibaba.dubbo.remoting.exchange.support.DefaultFuture.get(DefaultFuture.java:112)
原提问者GitHub用户huihui1112
确实捕获不到,因为在filter中抛出异常,dubbo框架为了避免反序列化失败将异常信息通过StringUtils.toString(e)处理了。
demo用的jdk1.8,参考#295,dubbo自带的ExceptionFilter会排序到SentinelDubboProviderFilter后面,这时经框架处理返回失败响应(错误码70,SERVICE_ERROR),异常信息也被处理了,调用方捕获到的是dubbo的RpcException;
即使用jdk1.7或者指定ExceptionFilter放到前面,只是提供端多了个WARN打印,调用方捕获到的还是RpcExcetion。
原回答者GitHub用户cdfive
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。