了解 spring-集成服务激活器
Understanding spring-integration service-activator
我的任务是对十年前开发的 spring-integration
项目进行一些修改,我知道它是如何工作的,所以我查看了一些 spring-integration
教程,虽然我没有完全理解它,但我对它有一些基本的了解。现在我试图在进行更改
之前了解 spring.integration.version 2.2.4.RELEASE
的 spring-integration
配置的以下片段
<!-- 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. 然后调用nsCurrencyPullService
的getCurrencies
方法
4. 并将输出传递给 msSqlCurrencyPushService
的 saveCurrenciesToDB
方法
请帮我解决以下问题
所以上面的步骤只在spring应用程序启动时执行?
还是在应用程序启动后定期进行?
如果它定期执行,我可以在哪里检查 nsCurrencyPullService
调用的轮询频率?
So the above steps are performed only during the spring application startup?
基础结构(bean)创建在应用程序上下文初始化期间执行一次。这些组件使用 MessageChannel
s 连接在一起。当网关被调用时,有效载荷被包装在一条消息中并发送到通道。默认情况下,通道是 DirectChannel
s,这意味着服务直接在调用者的线程上调用。
第一个服务的输出通过通道发送到第二个服务;再次在调用者的线程上。该服务的结果作为方法调用的结果返回给调用者。
polling frequency
本场景没有轮询;消息由网关的调用者发送到集成流中。
现代的方法是使用 DSL。
@Bean
public IntegrationFlow() {
return IntegrationFlows.from(INetSuiteCurrencyPullService.class)
.handle("bean1", "method1")
.handle("bean2", "method2")
.get();
}
我的任务是对十年前开发的 spring-integration
项目进行一些修改,我知道它是如何工作的,所以我查看了一些 spring-integration
教程,虽然我没有完全理解它,但我对它有一些基本的了解。现在我试图在进行更改
spring.integration.version 2.2.4.RELEASE
的 spring-integration
配置的以下片段
<!-- 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. 然后调用nsCurrencyPullService
的getCurrencies
方法
4. 并将输出传递给 msSqlCurrencyPushService
saveCurrenciesToDB
方法
请帮我解决以下问题
所以上面的步骤只在spring应用程序启动时执行?
还是在应用程序启动后定期进行?
如果它定期执行,我可以在哪里检查 nsCurrencyPullService
调用的轮询频率?
So the above steps are performed only during the spring application startup?
基础结构(bean)创建在应用程序上下文初始化期间执行一次。这些组件使用 MessageChannel
s 连接在一起。当网关被调用时,有效载荷被包装在一条消息中并发送到通道。默认情况下,通道是 DirectChannel
s,这意味着服务直接在调用者的线程上调用。
第一个服务的输出通过通道发送到第二个服务;再次在调用者的线程上。该服务的结果作为方法调用的结果返回给调用者。
polling frequency
本场景没有轮询;消息由网关的调用者发送到集成流中。
现代的方法是使用 DSL。
@Bean
public IntegrationFlow() {
return IntegrationFlows.from(INetSuiteCurrencyPullService.class)
.handle("bean1", "method1")
.handle("bean2", "method2")
.get();
}