gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:17:53 27 4
gpt4 key购买 nike

我接到一项任务,要对十年前开发的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com