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

sentinel使用回退功能时,会发生以下异常

限流规则和回调函数都设定到了自己的服务端,当有其它服务调用我服务接口且达到了限流规则设定的阀值,返回给调用方的信息是这样的:Caused by: com.alibaba.dubbo.remoting.RemotingException: com.alibaba.com.caucho.hessian.io.HessianProtocolException: expected map/object at java.lang.String ({"code":"120023","message":"QPS exceeded the threshold set by Sentinel"})

回调函数定制信息如下: DubboFallbackRegistry.setProviderFallback(new DubboFallbackImpl4Producer());

public class DubboFallbackImpl4Producer implements DubboFallback { @OverRide public Result handle(Invoker<?> invoker, Invocation invocation, BlockException ex) { StringBuffer sb = new StringBuffer(); sb.append(invoker.getInterface().toString()); Map<String, String> map = new HashMap<>(2); map.put("code", "120023"); map.put("message", "QPS exceeded the threshold set by Sentinel : " + sb); return new RpcResult(new JSONObject(map).toString()); } }

原提问者GitHub用户Mr-ZhangJ

展开
收起
码字王 2023-05-19 19:03:01 125 0
1 条回答
写回答
取消 提交回答
  • HessianProtocolException似乎是Dubbo RPC调用中的反序列化出错。 检查dubbo和fastjson版本在提供者和使用者端是否相同。

    Map<String, String> map = new HashMap<>(2); ... return new RpcResult(new JSONObject(map).toString());

    您的项目中的JSONObject包是什么? fastjson中JSONObect的构造函数是: JSONObject(映射<字符串,对象>映射),而不是JSONObject。

    原回答者GitHub用户cdfive

    2023-05-19 21:26:50
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:

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

相关电子书

更多
阿里云容器 AHAS Sentinel 网关流控揭秘 立即下载
workshop专场-微服务专场-开发者动手实践营-微服务-使用Sentinel进行微服务流量控制 立即下载
Sentinel分布式系统下的流量防卫兵 立即下载