Rmi agreement
Feature description
The RMI protocol is implemented using the JDK standard java.rmi.*
, using blocking short connections and JDK standard serialization.
- Number of connections: multiple connections
- Connection method: short connection
- Transport protocol: TCP
- Transmission method: synchronous transmission
- Serialization: Java standard binary serialization
- Scope of application: Incoming and outgoing parameter packets are mixed in size, the number of consumers and providers is similar, and files can be transferred.
- Applicable scenarios: regular remote service method calls, interoperability with native RMI services
Constraints
- Parameters and return values need to implement
Serializable
interface - The timeout in dubbo configuration is invalid for RMI, you need to use the java startup parameter setting:
-Dsun.rmi.transport.tcp.responseTimeout=3000
, see the following RMI configuration
scenes to be used
It is a set of Java APIs that supports the development of distributed applications, and realizes the method calling of programs between different operating systems.
How to use
Import dependencies
Starting from Dubbo 3, the RMI protocol is no longer embedded in Dubbo, and an independent module needs to be introduced separately.
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-rpc-rmi</artifactId>
<version>1.0.0</version>
</dependency>
java -Dsun.rmi.transport.tcp.responseTimeout=3000
For more RMI optimization parameters, please see JDK Documentation
Interface Description
If the service interface inherits the java.rmi.Remote
interface, it can interoperate with native RMI, namely:
- The provider uses Dubbo’s RMI protocol to expose the service, and the consumer directly uses the standard RMI interface to call,
- Or the provider uses standard RMI to expose the service, and the consumer uses Dubbo’s RMI protocol to call.
If the service interface does not extend the java.rmi.Remote
interface:
- By default, Dubbo will automatically generate a
com.xxx.XxxService$Remote
interface, inherit thejava.rmi.Remote
interface, and expose the service through this interface, - But if
<dubbo:protocol name="rmi" codec="spring" />
is set, the$Remote
interface will not be generated, and the service will be exposed using Spring’sRmiInvocationHandler
interface, which is compatible with Spring.
Define the RMI protocol
<dubbo:protocol name="rmi" port="1099" />
SET DEFAULT PROTOCOL
<dubbo:provider protocol="rmi" />
Set the protocol of a service
<dubbo:service interface="..." protocol="rmi" />
Multiple ports
<dubbo:protocol id="rmi1" name="rmi" port="1099" />
<dubbo:protocol id="rmi2" name="rmi" port="2099" />
<dubbo:service interface="..." protocol="rmi1" />
Spring Compatibility
<dubbo:protocol name="rmi" codec="spring" />
- If you are using RMI to provide services for external access, there should be no risk of attack in the company’s intranet environment.
- At the same time, if the application relies on the old common-collections package, dubbo will not depend on this package. Please check whether your application has used it.