# RMI Support ## RMI Support | |this module is deprecated since 5.4 with no replacement and will be removed in 6.0.| |---|-----------------------------------------------------------------------------------| This chapter explains how to use channel adapters that are specific to RMI (Remote Method Invocation) to distribute a system over multiple JVMs. The first section deals with sending messages over RMI. The second section shows how to receive messages over RMI. The last section shows how to define RMI channel adapters by using the namespace support. You need to include this dependency into your project: Maven ``` org.springframework.integration spring-integration-rmi 5.5.9 ``` Gradle ``` compile "org.springframework.integration:spring-integration-rmi:5.5.9" ``` ### Outbound RMI To send messages from a channel over RMI, you can define an `RmiOutboundGateway`. This gateway uses Spring’s `RmiProxyFactoryBean` internally to create a proxy for a remote gateway. Note that, to invoke a remote interface that does not use Spring Integration, you should use a service activator in combination with Spring’s RmiProxyFactoryBean. To configure the outbound gateway, you can write a bean definition similar the following: ``` ``` ### Inbound RMI To receive messages over RMI, you need to use an `RmiInboundGateway`. You can configure the gateway as shown in the following example: ``` ``` | |If you use an `errorChannel` on an inbound gateway, it the error flow normally returns a result or throws an exception.
This is because it is likely that there is a corresponding outbound gateway waiting for a response of some kind.
Consuming a message on the error flow and not replying results in no reply for the inbound gateway.
Exceptions (on the main flow when there is no `errorChannel` or on the error flow) propagate to the corresponding inbound gateway.| |---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ### RMI namespace support To configure the inbound gateway, you can use the namespace support for it. The following code snippet shows the different configuration options that are supported: ``` ``` You can also use the namespace support to configure the outbound gateway. The following code snippet shows the different configuration for an outbound RMI gateway: ``` ``` ### Configuring with Java Configuration The following example shows how to configure an inbound gateway and an outbound gateway with Java: ``` @Bean public RmiInboundGateway inbound() { RmiInboundGateway gateway = new RmiInboundGateway(); gateway.setRequestChannel(requestChannel()); gateway.setRegistryHost("host"); gateway.setRegistryPort(port); return gateway; } @Bean @ServiceActivator(inputChannel="inChannel") public RmiOutboundGateway outbound() { RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://host:port/" + RmiInboundGateway.SERVICE_NAME_PREFIX + "remoteChannelName"); return gateway; } ``` As of version 4.3, the outbound gateway has a second constructor that takes an `RmiProxyFactoryBeanConfigurer` instance, along with the service url argument. It allows further configuration before the proxy is created — for example, to inject a Spring Security `ContextPropagatingRemoteInvocationFactory`, as the following example shows: ``` @Bean @ServiceActivator(inputChannel="inChannel") public RmiOutboundGateway outbound() { RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://host:port/" + RmiInboundGateway.SERVICE_NAME_PREFIX + "remoteChannelName", pfb -> { pfb.setRemoteInvocationFactory(new ContextPropagatingRemoteInvocationFactory()); }); return gateway; } ``` Starting with version 5.0, you can set this with the XML namespace by using the `configurer` attribute.