java - 了解 spring 集成服务激活器

标签 java spring spring-integration channel

我接到一项任务,要对十年前开发的 spring-integration 项目进行一些修改,我知道它是如何工作的,所以我查看了一些spring-integration 教程,虽然我没有完全理解它,但我了解了一些基本知识。现在我尝试在进行更改之前了解以下 spring-integration 配置 spring.integration.version 2.2.4.RELEASE 的片段

<!-- Currency Pull from NetSuite -->
<int:gateway id="currencySyncGateway" service-interface="com.integration.service.INetSuiteCurrencyPullService" default-request-channel="currenciesFromNetSuite" />


<bean id="nsCurrencyPullService" class="com.integration.service.impl.NetSuiteCurrencyPullService" />
<int:channel id="currenciesFromNetSuite" />
<int:service-activator input-channel="currenciesFromNetSuite" ref="nsCurrencyPullService" method="getCurrencies" output-channel="pushCurrenciesToDB" />

<bean id="msSqlCurrencyPushService" class="com.integration.service.impl.MSSQLCurrencyPushService" />
<int:channel id="pushCurrenciesToDB" />
<int:service-activator input-channel="pushCurrenciesToDB" ref="msSqlCurrencyPushService" method="saveCurrenciesToDB" />

下面是上述bean对应的类

INetSuiteCurrencyPullService

public interface INetSuiteCurrencyPullService {

    List<Currency> getCurrencies(String in);

}

NetSuiteCurrencyPullService

public class NetSuiteCurrencyPullService implements INetSuiteCurrencyPullService {

    @Autowired
    INetSuiteClient restletClient;

    @Override
    public List<Currency> getCurrencies(String in) {
        LOGGER.info("Retrieving currencies from NetSuite...");
        PullCurrenciesRestletResponse response = restletClient.pullCurrencies();
        LOGGER.debug("Restlet response: {}", response);

        if ("SUCCESS".equals(response.getError().getCode())) {
            LOGGER.info("Received restlet response: executionTimeMillis=" + response.getExecutionTimeMillis() + ", count=" + response.getCurrencies().size());
            return response.getCurrencies();
        } else {
            String msg = "Error retrieving currencies from NetSuite: " + response.getError().getMessage();
            LOGGER.error(msg);
            throw new RuntimeException(msg);
        }
    }

}

MSSQLCurrencyPushService

public class MSSQLCurrencyPushService implements IMSSQLCurrencyPushService {

    @Autowired
    CurrencyConversionRepository currencyConversionRepository;

    @Override
    public List<Currency> saveCurrenciesToDB(List<Currency> in) {
        // logic to save Currency in DB     
        return in;
    }
}

下面是我对应用程序启动后的上述 spring-integration 配置的理解(如果错误,请更正)
1. Spring首先为INetSuiteCurrencyPullService初始化一个代理对象
2.然后实例化nsCurrencyPullService bean
3.然后调用nsCurrencyPullServicegetCurrency方法
4. 并将输出传递给 msSqlCurrencyPushServicesaveCurrencyToDB 方法

请帮我解决以下问题
那么上述步骤只在spring应用启动时执行?
或者是在应用程序启动后定期进行?
如果定期执行,我可以在哪里检查 nsCurrencyPullService 调用的轮询频率?

最佳答案

So the above steps are performed only during the spring application startup?

基础设施(bean)创建在应用程序上下文初始化期间执行一次。这些组件使用 MessageChannel 连接在一起。当网关被调用时,有效负载被包装在消息中并发送到 channel 。默认情况下, channel 是 DirectChannel,这意味着直接在调用者的线程上调用服务。

第一个服务的输出通过 channel 发送到第二个服务;再次在调用者的线程上。该服务的结果作为方法调用的结果返回给调用者。

polling frequency

这种情况下没有轮询;消息由网关的调用者发送到集成流中。

实现同样功能的现代方法是使用 DSL。

@Bean
public IntegrationFlow() {
    return IntegrationFlows.from(INetSuiteCurrencyPullService.class)
         .handle("bean1", "method1")
         .handle("bean2", "method2")
         .get();
}

关于java - 了解 spring 集成服务激活器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54542248/

相关文章:

java - 如何从帮助菜单按钮打开 html 文件

java - 随机 java.util.ConcurrentModificationException : null

java - 在哪里可以找到日志记录 channel 适配器的文档?

spring-integration - 如何与许多生产者创建 Spring 集成流程

java - 如何在边框中添加按钮?

java - 为什么 Java 中相同的输入 toString() 返回不同的值?

java 。为什么这个for循环不能正常工作

java - 从 groovy 调用 Spring 组件

java - ERR未知命令 'GEOADD'来自java spring中的嵌入式redis

java - 如何阻止处理 `int-ftp:inbound-channel-adapter ` 中的旧文件?