Rmi Protocol

Rmi Protocol

Feature Description

The RMI protocol uses the JDK standard java.rmi.* implementation, employing a blocking short connection and JDK standard serialization.

  • Number of connections: Multiple connections
  • Connection type: Short connection
  • Transport protocol: TCP
  • Transport method: Synchronous transmission
  • Serialization: Java standard binary serialization
  • Applicable scope: Mixed sizes of incoming and outgoing parameter data packets, with a number of consumers and providers roughly the same, can transfer files.
  • Applicable scenarios: Routine remote service method calls, interoperable with native RMI services.

Constraints

  • Parameters and return values must implement the Serializable interface.
  • The timeout configured in Dubbo is ineffective for RMI and must be set using Java startup parameters: -Dsun.rmi.transport.tcp.responseTimeout=3000, refer to the RMI configuration below.

Usage Scenarios

It is a set of APIs in Java that support the development of distributed applications, achieving method calls between programs on different operating systems.

Usage Method

Import Dependencies

Since Dubbo 3, the RMI protocol is no longer embedded in Dubbo and needs to be imported as a separate module.

  1. <dependency>
  2. <groupId>org.apache.dubbo.extensions</groupId>
  3. <artifactId>dubbo-rpc-rmi</artifactId>
  4. <version>3.3.0</version>
  5. </dependency>
  1. java -Dsun.rmi.transport.tcp.responseTimeout=3000

For more RMI optimization parameters, please refer to the JDK Documentation

Interface Description

If the service interface extends the java.rmi.Remote interface, it can interoperate with native RMI, that is:

  • The provider exposes services using Dubbo’s RMI protocol, while the consumer directly calls using the standard RMI interface,
  • or the provider exposes services using the standard RMI, while the consumer calls using Dubbo’s RMI protocol.

If the service interface does not extend the java.rmi.Remote interface:

  • By default, Dubbo will automatically generate an interface com.xxx.XxxService$Remote, extending the java.rmi.Remote interface, and expose services via this interface,
  • However, if <dubbo:protocol name="rmi" codec="spring" /> is set, the $Remote interface will not be generated, and the Spring RmiInvocationHandler interface will be used to expose services, maintaining Spring compatibility.

Define RMI Protocol

  1. <dubbo:protocol name="rmi" port="1099" />

Set Default Protocol

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

Set Protocol for Specific Service

  1. <dubbo:service interface="..." protocol="rmi" />

Multiple Ports

  1. <dubbo:protocol id="rmi1" name="rmi" port="1099" />
  2. <dubbo:protocol id="rmi2" name="rmi" port="2099" />
  3. <dubbo:service interface="..." protocol="rmi1" />

Spring Compatibility

  1. <dubbo:protocol name="rmi" codec="spring" />

Note

  • If providing services via RMI for external access, there should be no attack risks in the company’s intranet environment.

  • If the application relies on the old common-collections package, Dubbo will not depend on this package; please check if your application uses it.

  • There are deserialization security risks. Please check the application: upgrade commons-collections3 to 3.2.2; upgrade commons-collections4 to 4.1. The new versions of commons-collections resolve this issue.

Feedback

Was this page helpful?

Yes No

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