Local calls use the injvm protocol, which is a pseudo-protocol that does not open a port or initiate remote calls; it directly associates within the JVM but executes the Dubbo filter chain.
When we need to call a remote service that is not yet developed, we can implement a similar service locally using the injvm protocol, allowing us to invoke our local implementation of the service.
<dubbo:protocol name="injvm" />
<dubbo:provider protocol="injvm" />
<dubbo:service protocol="injvm" />
<dubbo:consumer injvm="true" .../>
<dubbo:provider injvm="true" .../>
or
<dubbo:reference injvm="true" .../>
<dubbo:service injvm="true" .../>
2.2.0
, each service is exposed locally by default, and no configuration is needed for local reference. If you do not want the service to be exposed remotely, simply set the protocol to injvm in the provider.Starting from 2.2.0
, each service is exposed locally by default. When referencing a service, the local service is prioritized by default. To reference a remote service, you can use the following configuration to force a remote reference.
<dubbo:reference ... scope="remote" />
Starting from 3.2
, Dubbo provides an API that allows users to dynamically configure whether a single call is a local or remote call. By default, it prioritizes local services if no configuration is provided.
Configure a single call as a remote call
RpcContext.getServiceContext().setLocalInvoke(false);
Configure a single call as a local call
RpcContext.getServiceContext().setLocalInvoke(true);