Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huihui1112 opened this issue Jan 2, 2019 · 4 comments
Closed

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

huihui1112 opened this issue Jan 2, 2019 · 4 comments
Labels
kind/question Category issues related to questions or problems

Comments

@huihui1112
Copy link

huihui1112 commented Jan 2, 2019

消费者那边似乎无法抓到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)
@cdfive
Copy link
Collaborator

cdfive commented Jan 4, 2019

确实捕获不到,因为在filter中抛出异常,dubbo框架为了避免反序列化失败将异常信息通过StringUtils.toString(e)处理了。

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

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

@huihui1112
Copy link
Author

嗯嗯!!!大神的框架底子可以的. 明白了.

@cdfive
Copy link
Collaborator

cdfive commented Jan 4, 2019

嗯嗯!!!大神的框架底子可以的. 明白了.

也是在学习和摸索哈。

补充下刚找到的一个方法可以捕获:
比如自定义一个DubboFallback或者修改默认的DefaultDubboFallback
throw new SentinelRpcException(ex);改为return new RpcResult(new SentinelRpcException(ex));

这样在demo1的消费端就能捕获到SentinelRpcException了。

但要注意的是:
这里的demo是在一个工程里,实际项目中可能消费端没有依赖sentinel-core,这种方式消费端可能报反序列化异常;如果工程都有依赖,那这种方式应该没问题。

因为消费端的依赖不确定,所以dubbo的ExceptionFilter实现逻辑是尽可能避免消费端反序列化失败问题。

我也提了个问题 #379 ,可以一起讨论,看能否通过BlockException#isBlockException区分是否是Sentinel的流控异常。

@huihui1112
Copy link
Author

嗯嗯!!!大神的框架底子可以的. 明白了.

也是在学习和摸索哈。

补充下刚找到的一个方法可以捕获:
比如自定义一个DubboFallback或者修改默认的DefaultDubboFallback
throw new SentinelRpcException(ex);改为return new RpcResult(new SentinelRpcException(ex));

这样在demo1的消费端就能捕获到SentinelRpcException了。

但要注意的是:
这里的demo是在一个工程里,实际项目中可能消费端没有依赖sentinel-core,这种方式消费端可能报反序列化异常;如果工程都有依赖,那这种方式应该没问题。

因为消费端的依赖不确定,所以dubbo的ExceptionFilter实现逻辑是尽可能避免消费端序列化失败问题。

我也提了个问题 #379 ,可以一起讨论,看能否通过BlockException#isBlockException区分是否是Sentinel的流控异常。

嗯嗯!!!!!!!谢谢大佬!!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Category issues related to questions or problems
Projects
None yet
Development

No branches or pull requests

3 participants