dubbo 2.6.X 自定义异常处理

博客介绍了dubbo 2.6.X自定义异常拦截器的配置方法。因dubbo RPC统一拦截异常,消费者无法捕获自定义异常。着重介绍重写异常拦截器的方式,包括配置yum文件、exceptionFilter,创建AyaDubboExceptionFilter类等,完成提供者配置后,消费者端可自行捕获处理自定义异常。

dubbo 2.6.X 自定义异常拦截器

dubbo RPC 统一拦截了异常转化为RuntimeException,未能识别我们项目中定义的自定义异常,所以消费者无法捕获到自定义异常,网上罗列的处理结果有很多种,下面着重介绍第二种

  1. 提供者每个方法上throw 自定义异常
  2. 重写异常拦截器

一、配置yum文件

在这里插入图片描述
如图,我们配置filter,第一个为我们自定义的拦截器、第二个为禁用dubbo异常拦截器

配置exceptionFilter,如图所示

在这里插入图片描述

创建AyaDubboExceptionFilter类,复制dubbo RPC ExceptionFilter类文件内容,添加处理异常类,如图所示

在这里插入图片描述
在这里插入图片描述

至此我们已经完成提供者配置,消费者端捕获自定义异常自行处理,如有错误欢迎指出

转载请标明出处

https://blog.youkuaiyun.com/qq_22611671/article/details/90669083

下一篇:apache duboo 实现自定义异常拦截器

at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) 2025-04-01 13:26:49.938 [main] ERROR o.a.d.r.c.ServiceDiscoveryRegistryDirectory - [DUBBO] Unsupported protocol., dubbo version: 3.1.2, current host: 192.168.199.2, error code: 4-1. This may be caused by protocol extension does not installed, go to https://dubbo.apache.org/faq/4/1 to find instructions. java.lang.IllegalStateException: Unsupported protocol rest in notified url: DefaultServiceInstance{serviceName='ym-ucenter-service', host='192.168.199.2', port=8080, enabled=true, healthy=true, metadata={preserved.register.source=SPRING_CLOUD}}, null from registry localhost:8848 to consumer 192.168.199.2, supported protocol: [dubbo, injvm, mock, registry, service-discovery-registry, tri] at org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory.toInvokers(ServiceDiscoveryRegistryDirectory.java:305) at org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory.refreshInvoker(ServiceDiscoveryRegistryDirectory.java:252) at org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory.refreshOverrideAndInvoker(ServiceDiscoveryRegistryDirectory.java:180) at org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory.notify(ServiceDiscoveryRegistryDirectory.java:174) at org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener.addListenerAndNotify(ServiceInstancesChangedListener.java:236) at org.apache.dubbo.registry.client.ServiceDiscoveryRegistry.subscribeURLs(ServiceDiscoveryRegistry.java:325)
最新发布
04-02
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值