Local Call

Local Calls in Dubbo

Feature Description

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.

Usage Scenarios

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.

Usage Method

Define the injvm Protocol

  1. <dubbo:protocol name="injvm" />

Set Default Protocol

  1. <dubbo:provider protocol="injvm" />

Set Service Protocol

  1. <dubbo:service protocol="injvm" />

Prefer injvm

  1. <dubbo:consumer injvm="true" .../>
  2. <dubbo:provider injvm="true" .../>

or

  1. <dubbo:reference injvm="true" .../>
  2. <dubbo:service injvm="true" .../>

Note

From 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.

Automatic Exposure

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.

  1. <dubbo:reference ... scope="remote" />

Dynamically Configure Call Behavior

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

  1. RpcContext.getServiceContext().setLocalInvoke(false);

Configure a single call as a local call

  1. RpcContext.getServiceContext().setLocalInvoke(true);

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)