开发者社区 > 云原生 > 正文

关于Dubbo的demo 如果限流规则设置在服务提供方

消费者那边似乎无法抓到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&register.ip=10.6.24.97&side=consumer&timeout=3000&timestamp=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

展开
收起
码字王 2023-05-19 19:11:21 116 0
1 条回答
写回答
取消 提交回答
  • 确实捕获不到,因为在filter中抛出异常,dubbo框架为了避免反序列化失败将异常信息通过StringUtils.toString(e)处理了。

    demo用的jdk1.8,参考#295,dubbo自带的ExceptionFilter会排序到SentinelDubboProviderFilter后面,这时经框架处理返回失败响应(错误码70,SERVICE_ERROR),异常信息也被处理了,调用方捕获到的是dubbo的RpcException;

    即使用jdk1.7或者指定ExceptionFilter放到前面,只是提供端多了个WARN打印,调用方捕获到的还是RpcExcetion。

    原回答者GitHub用户cdfive

    2023-05-19 22:46:06
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
Dubbo开源现状与2.7规划 立即下载
Dubbo分布式服务治理实战 立即下载
《Dubbo 3.0 前瞻》 立即下载