The local call uses the injvm protocol, which is a pseudo-protocol. It does not open ports, does not initiate remote calls, and is only directly associated in the JVM, but executes Dubbo’s Filter chain.
When we need to call a remote service, the remote service has not been developed yet, and similar services are implemented locally using the injvm protocol. When calling this service, we can call our local implementation 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" .../>
Dubbo from 2.2.0
, each service will be exposed locally by default, and can be referenced locally without any configuration. If you do not want the service to be exposed remotely, you only need to set the protocol to injvm in the provider. **
Starting with 2.2.0
, every service is exposed locally by default. When referencing services, local services are preferred by default. If you want to reference remote services, you can use the following configuration to force references to remote services.
<dubbo:reference ... scope="remote" />
Starting with’ 3.2’, the api provided by Dubbo allows users to dynamically configure whether a single call is a local call or a remote call, and when it is not configured, the local service will be referenced first by default.
Configure a single call as a remote call.
RpcContext.getServiceContext().setLocalInvoke(false);
Configure a single call as a local call.
RpcContext.getServiceContext().setLocalInvoker(true);