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

<dubbo:protocol name="injvm" />

Set Default Protocol

<dubbo:provider protocol="injvm" />

Set Service Protocol

<dubbo:service protocol="injvm" />

Prefer injvm

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

or

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

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.

<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

RpcContext.getServiceContext().setLocalInvoke(false);

Configure a single call as a local call

RpcContext.getServiceContext().setLocalInvoke(true);
Last modified September 30, 2024: Translate (22d3d83a3b)