我想知道spring是否有任何解決方案來支持使用在線服務或遠程服務配置的過程調用。遠程/正在處理服務
更新1
一個例子,可以說,我們有以下幾點:
共同的項目:
public interface ServiceBInterface {
boolean doSomething();
}
項目A(取決於通用項目):
@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
}
}
B項目(依靠普通項目CT):
@Service
public class ServiceB implements ServiceBInterface {
public boolean doSomething() {
boolean result = false;
// execute some code
return result;
}
}
我想能夠配置ServiceBInterface豆下列選項進行初始化:
- ServiceB
- 某種對象的實例的實例,它會將一個RPC轉換爲獨立於ServiceA的不同進程上運行的ServiceB。
回答 項目A(取決於通用項目):
@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
}
}
項目B(依賴於通用項目):
@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;
}
}
閱讀參考指南,關於遠程處理的部分是你想要的,如果你想更詳細的支持使用Spring Integration。 –