spring - 远程/进程内服务

标签 spring spring-boot spring-integration rmi spring-cloud

我想知道spring是否有任何解决方案来支持使用进程内服务或远程服务的配置进行过程调用。

更新1

举个例子,假设我们有以下内容:

常见项目:

public interface ServiceBInterface {
     boolean doSomething();
}

项目A(取决于公共(public)项目):

@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(取决于公共(public)项目):

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

我希望能够配置 ServiceBInterface bean 以通过以下选项进行初始化:

  1. ServiceB 的实例
  2. 某种对象的实例,它将向 ServiceB 发起 RPC,该 RPC 在 ServiceA 的不同进程上独立运行。

回答 项目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(取决于公共(public)项目):

   @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 Reference Manual 时为自己找到一些帮助。 。例如,有一个 RMI 支持,它表示为一对入站/出站网关,用于与远程过程服务进行通信。

否则,请更加具体,尤其是您想要达到的解决方案的代码示例。

关于spring - 远程/进程内服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32051169/

相关文章:

Spring选择多个标签和绑定(bind)

java - 我有一个错误,但依赖项包含在 gradle root 和 gradle 模块配置中,为什么?

java - Spring Security中如何防止多次登录

spring-boot - 带有 SSL 的 Spring Boot 的 REST WebService,但没有自签名证书

Spring Boot 在启动时抛出 BeanCreationException

java - 将 YAML 列表映射到 Spring Boot 中的对象列表

spring-integration - 即使超时超过 Spring Integration 消息 channel 也会挂起

java - 如何将 SQL 转换为 JPQL 查询?

java - Spring Integration - 线程化出站 channel

tomcat - 使用 Tomcat 的 Spring Stream 聚合应用程序