我承担了对十年前开发的spring-integration
项目进行一些修改的任务,并且我知道其工作原理的线索,因此我看了一些spring-integration
教程,尽管我不太了解它,但我对它有一些基本的了解。现在,在尝试进行更改之前,我想了解spring-integration
的{{1}}配置的以下摘要
spring.integration.version 2.2.4.RELEASE
以下是上述bean的对应类
INetSuiteCurrencyPullService
<!-- 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" />
NetSuiteCurrencyPullService
public interface INetSuiteCurrencyPullService {
List<Currency> getCurrencies(String in);
}
MSSQLCurrencyPushService
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);
}
}
}
下面是我对应用程序启动后上面的public class MSSQLCurrencyPushService implements IMSSQLCurrencyPushService {
@Autowired
CurrencyConversionRepository currencyConversionRepository;
@Override
public List<Currency> saveCurrenciesToDB(List<Currency> in) {
// logic to save Currency in DB
return in;
}
}
配置的理解(如果错误,请更正)
1. Spring首先为spring-integration
初始化一个代理对象
2.然后实例化INetSuiteCurrencyPullService
bean
3.然后调用nsCurrencyPullService
的{{1}}方法
4.并将输出传递到getCurrencies
nsCurrencyPullService
方法中
请帮助我解决以下问题
那么上述步骤仅在spring应用程序启动期间执行吗?
还是在应用程序启动后定期执行?
如果它定期执行,在哪里可以检查saveCurrenciesToDB
调用的轮询频率?
答案 0 :(得分:1)
那么上述步骤仅在spring应用程序启动期间执行吗?
在应用程序上下文初始化期间,一次执行基础结构(bean)创建。这些组件使用MessageChannel
连接在一起。当网关被调用时,有效载荷被包裹在一条消息中并发送到通道。默认情况下,通道为DirectChannel
,这意味着服务直接在调用者的线程上调用。
第一个服务的输出通过通道发送到第二个服务;再次在调用者的线程上。该服务的结果作为方法调用的结果返回给调用方。
轮询频率
在这种情况下没有轮询;消息由网关的调用者发送到集成流中。
使用DSL的一种现代方法。
@Bean
public IntegrationFlow() {
return IntegrationFlows.from(INetSuiteCurrencyPullService.class)
.handle("bean1", "method1")
.handle("bean2", "method2")
.get();
}