Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote / In process service

i was wondering if spring has any solution to support a procedure call using configuration of an in process service or remote service.

update 1

an example, lets say we have the following :

Common project:

public interface ServiceBInterface {
     boolean doSomething();
}

Project A (depended on common project) :

@Service
public class ServiceA {

     @Autowired
     private ServiceBInterface serviceB;

     public void flowA() {
            // run flow A code
            boolean result = serviceB.doSomething();
           // continue run flow A code with result of service B 
     }
}

Project B (depended on common project) :

@Service
public class ServiceB implements ServiceBInterface {
    public boolean doSomething() {
        boolean result = false;
        // execute some code
        return result;
    }
}

i would like to be able to configure ServiceBInterface bean to be initialized on the following options:

  1. An instance of ServiceB
  2. An instance of some sort of object that will make an RPC to ServiceB that runs independently on a different process of ServiceA.

Answer Project A (depended on common project) :

    @Service
    public class ServiceA {

         @Autowired
         private ServiceBInterface serviceB;

@PostConstruct
    public void init() {
        if (Boolean.getBoolean("remote")) {
            RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
            rmiProxyFactoryBean.setServiceUrl("rmi://localhost:1099/ServiceB");
            rmiProxyFactoryBean.setServiceInterface(ServiceBInterface.class);
            rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
            rmiProxyFactoryBean.setLookupStubOnStartup(false);

            rmiProxyFactoryBean.afterPropertiesSet();
            serviceB = (ServiceBInterface) rmiProxyFactoryBean.getObject();
        }
    }
         public void flowA() {
                // run flow A code
                boolean result = serviceB.doSomething();
               // continue run flow A code with result of service B 
         }
    }

Project B (depended on common project) :

   @Service
    public class ServiceB implements ServiceBInterface {

      RmiServiceExporter rmiServiceExporte;
@PostConstruct
public void init() throws RemoteException {
        if (Boolean.getBoolean("remoteB")) {
            rmiServiceExporter = new RmiServiceExporter();
            rmiServiceExporter.setServiceName("ServiceB");
            rmiServiceExporter.setService(serviceB());
            rmiServiceExporter.setServiceInterface(ServiceBInterface.class);
            rmiServiceExporter.setServicePort(9999);
            rmiServiceExporter.afterPropertiesSet();
        }
    }
        public boolean doSomething() {
            boolean result = false;
            // execute some code
            return result;
        }
    }
like image 553
Tal Ben Shabtay Avatar asked Jan 19 '26 02:01

Tal Ben Shabtay


1 Answers

Sorry you question isn't clear to me, but I wonder if you'd be able to find some help for yourself reading Spring Integration Reference Manual. For example there is an RMI support which is represented as a pair of inbound/outbound gateways to communicate with the remote procedure service.

Otherwise, please, be more specific, especially with the sample of code for solution which you'd like to reach.

like image 94
Artem Bilan Avatar answered Jan 21 '26 20:01

Artem Bilan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!