Dubbo Generic Invocation: Project Practice and Principle Analysis
By applying Dubbo's GenericService $invoke method, the vivo project replaced tightly‑coupled direct API calls with a unified remote‑call layer that eliminates third‑party JAR dependencies, reduces system coupling, and leverages Dubbo’s internal proxy‑exporter mechanisms to dynamically invoke diverse external services.
This article explores Dubbo's generic invocation feature through a real-world project scenario at vivo. The background involves a unified configuration platform that needs to remotely invoke multiple third-party systems (like A/B testing platforms) to determine whether configuration files should be distributed to end devices.
The authors compare two solution approaches: (1) Direct approach that adds separate API calls for each third-party system, resulting in tight coupling; (2) Using Dubbo's generic invocation to abstract a unified remote call dimension, which maintains original logic while reducing system coupling. Solution two was selected for implementation.
The implementation uses Dubbo's GenericService interface, which provides a single $invoke method accepting three parameters: method name, parameter type array, and parameter value array. The code demonstrates creating a ReferenceConfig with generic=true, then invoking remote services without depending on provider interface JARs.
The article then provides an in-depth analysis of Dubbo's internal principles. For service exposure, Dubbo converts service implementations to Invoker objects through proxy factories, then converts Invokers to Exporters via protocols, registering service metadata to registries. For service consumption, Dubbo generates Invokers from remote service instances and creates dynamic proxy references through ProxyFactory.
The key difference between generic and direct invocation lies in the interfaceClass used: direct calls use the actual service interface (e.g., com.alibaba.dubbo.demo.DemoService), while generic calls use GenericService.class. The RpcInvocation objects differ accordingly, with generic calls wrapping the actual method name and parameters inside $invoke calls. This transformation is handled by GenericFilter on the provider side.
Code examples preserved:
public interface GenericService { Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException; }
ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>(); referenceConfig.setGeneric(Boolean.TRUE.toString());
Object result = genericService.$invoke(method, parameterTypeArray, parameterValueArray);
The article concludes that generic invocation reduces system coupling by eliminating dependencies on third-party JAR packages, requiring only the service interface path, parameter types, and values to make remote calls.
vivo Internet Technology
Sharing practical vivo Internet technology insights and salon events, plus the latest industry news and hot conferences.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.