weibocom / motan

A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.
Other
5.88k stars 1.78k forks source link

CommonClient generalized calls support motan1 protocol #1036

Closed coderDylan closed 1 year ago

coderDylan commented 1 year ago

many companies are still using the old protocol(motan V1),but generalized calls are not supported. The motan2 protocol supported generalized calls through the CommonClient,but not support motan1 protocol. I've supported it since I passed the makeover

coderDylan commented 1 year ago

@rayzhang0603 pls codereview

rayzhang0603 commented 1 year ago

非常抱歉没有及时回复。

CommonClient在设计上并没有限定只针对motan2协议,只是对不需要设置'parametersDesc'的场景提供了单独的方法(如果一个方法名只对应唯一的方法,client侧可以不用设置'parametersDesc'。唯一方法名更适合跨语言RPC,所以推荐这样设计接口)。

如果确实需要设置'parametersDesc'(比如使用了方法重载),或者需要设置自定义Attachment时,可以直接构造Request进行调用,样例如下:

        CommonClient service = motanDemoServiceReferer.getRef();
        Request request =MotanClientUtil.buildRequest("com.weibo.motan.demo.service.MotanDemoService", "hello", "java.lang.String", new Object[]{"a"}, null);
        System.out.println(service.call(request, String.class));

上面的方式应该可以满足不同协议下各种调用场景,所以没有必要增加专门针对motan1协议的调用姿势了。

coderDylan commented 1 year ago

非常抱歉没有及时回复。

CommonClient在设计上并没有限定只针对motan2协议,只是对不需要设置'parametersDesc'的场景提供了单独的方法(如果一个方法名只对应唯一的方法,client侧可以不用设置'parametersDesc'。唯一方法名更适合跨语言RPC,所以推荐这样设计接口)。

如果确实需要设置'parametersDesc'(比如使用了方法重载),或者需要设置自定义Attachment时,可以直接构造Request进行调用,样例如下:

        CommonClient service = motanDemoServiceReferer.getRef();
        Request request =MotanClientUtil.buildRequest("com.weibo.motan.demo.service.MotanDemoService", "hello", "java.lang.String", new Object[]{"a"}, null);
        System.out.println(service.call(request, String.class));

上面的方式应该可以满足不同协议下各种调用场景,所以没有必要增加专门针对motan1协议的调用姿势了。

抱歉,因为我在使用 Object call(String methodName, Object[] arguments, Class<?> returnType)这个方法进行泛化调用motan1协议的接口时发生了异常,原因就是没有设置'parametersDesc',接口也没有方法重载情况,所以我就尝试添加了新的调用方法。