apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.35k stars 26.4k forks source link

2.7.x泛化调用: 客户端异步功能无法兼容低版本 #6604

Closed chpengzh closed 3 years ago

chpengzh commented 4 years ago

Environment

Steps to reproduce this issue

  1. 使用2.5.6版本发布dubbo服务
  2. 依照https://github.com/apache/dubbo/issues/3163 功能进行泛化调用,声明客户端异步化调用
  3. Future 返回值中报错如下(method '$invokeAsync' not found),错误来源于服务端;
Failed to invoke remote proxy method $invokeAsync to registry://10.179.84.162:2181/com.alibaba.dubbo.registry.RegistryService?application=htw-facade&application.name=htw-facade&dubbo=2.5.3-didi-24&export=dubbo%3A%2F%2F10.179.25.19%3A7778%2Fcom.d.h.f.a.s.F*Service%3Fanyhost%3Dtrue%26application%3Dh-f%26application.name%3Dh-f%26default.service.filter%3DBhBizProviderFilter%2CBhDLProviderFilter%2CBhMetricsProviderFilter%2CDubboProviderContextSwitchFilter%26default.threads%3D500%26default.token%3Dtrue%26dispatcher%3Dmessage%26dubbo%3D2.5.3-didi-24%26interface%3Dcom.d.h.f.a.s.F*Service%26methods%3DoutAuthAndSendVoucher%2CqueryCardRemainInfo%2ChealthData%2CgetCityConfigControlResult%2CgetTripEndPopResult%2CactivityConfig%2CqrCodeUrlAnalyze%2CoutAuthCheck%2CfindTripEndPopResult%26owner%3D*%26pid%3D34411%26revision%3D1.0.2%26side%3Dprovider%26threadname%3DnonCoreFacadeProvider%26threads%3D100%26timestamp%3D1597290687001%26version%3D1.0.0_stable&file=/h/x/h/dubboLocal.cache&owner=*&pid=34411&registry=zookeeper&timestamp=1597290687000, cause: Not found method \"$invokeAsync\" in class com.d.h.f.a.s.F*Service.

创建 ReferenceConfig 和调用相关代码

@Service
public class DubboGenericIntegrationServiceImpl implements DubboGenericIntegrationService {

    @Resource
    private ApplicationConfig applicationConfig;

    @Resource
    private List<RegistryConfig> registryConfigs;

    @Resource
    private ConsumerConfig consumerConfig;

    @Nonnull
    @Override
    public ReferenceConfig<GenericService> createReference(
            @Nonnull String serviceName,
            @Nonnull String version,
            boolean async
    ) {
        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
        reference.setInterface(serviceName);
        reference.setVersion(version);
        reference.setGeneric(Boolean.TRUE.toString());
        reference.setCheck(false);
        reference.setAsync(async);

        reference.setApplication(applicationConfig);
        reference.setRegistries(registryConfigs);
        reference.setConsumer(consumerConfig);
        return reference;
    }

    @Override
    public Object invokeSync(
            @Nonnull GenericService service,
            @Nonnull ProxyInvokeParam param
    ) {
        return service.$invoke(param.getMethod(), param.getParamTypes(), param.getParams());
    }

    @Override
    public CompletableFuture<Object> invokeASync(
            @Nonnull GenericService service,
            @Nonnull ProxyInvokeParam param
    ) {
        return service.$invokeAsync(param.getMethod(), param.getParamTypes(), param.getParams());
    }
}
AlbumenJ commented 3 years ago

For lower version is not support async generic call. It is impossible to make it work if consumer or provider not support it. Please try upgrade your provider version.