gpt4 book ai didi

java - Spring Integration - 在应用程序代码中调用方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:10:12 25 4
gpt4 key购买 nike

我有一个出站 channel 适配器,相关配置如下所示。

<int:outbound-channel-adapter channel="foo-fileChannel" ref="foo-handlerTarget" method="handleFeedFile">
<int:poller fixed-delay="5000" receive-timeout="1000" max-messages-per-poll="10" />
</int:outbound-channel-adapter>
<int:channel id="foo-fileChannel">
<int:queue />
</int:channel>


<bean id="foo-handlerTarget" class="com.abc.FooFeedHandlerImpl">
<property name="fooDescriptorFile" value="${feed.foo.fooDescriptorFile}" />
<property name="fileIdRegex" ref="foo-fileRegex" />
<property name="processId" value="${feed.processId}" />
<property name="workingLocation" value="${feed.foo.workingLocation}" />
<property name="remoteLocation" value="${feed.foo.remoteLocation}" />
<property name="stalenessThreshold" value="${feed.foo.stalenessThreshold}" />
</bean>

在 FooFeedHandlerImpl 中...

public void handleFeedFile(File retrievedFile) {
handleFeedFile(retrievedFile, null);
}


public void handleFeedFile(File retrievedFile, String processKey) {
if (isHandlerForFileName(retrievedFile.getName())) {
processFeed(retrievedFile, processKey);
}
}

问题:

channel 适配器调用哪个 handleFeedFile 方法?

当我使用Spring集成调用应用程序代码中的方法时,方法参数是如何确定的?

感谢您的帮助!

编辑:

我在本地运行了我的进程(下载了本地 SFTP 服务器 - http://www.coreftp.com/server/index.html)并确定调用了 handleFeedFile(File file) 方法。

最佳答案

您可能想引用 F.6 Message Mapping rules and conventions .

Multiple parameters could create a lot of ambiguity with regards to determining the appropriate mappings. The general advice is to annotate your method parameters with @Payload and/or @Header/@Headers Below are some of the examples of ambiguous conditions which result in an Exception being raised.

和:

Multiple methods:

Message Handlers with multiple methods are mapped based on the same rules that are described above, however some scenarios might still look confusing.

如果您无法注释您的目标方法,那么您可以使用 SpEL 表达式来调用您想要的方法:

3.3.2 Configuring An Outbound Channel Adapter

Like many other Spring Integration components, the and also provide support for SpEL expression evaluation. To use SpEL, provide the expression string via the 'expression' attribute instead of providing the 'ref' and 'method' attributes that are used for method-invocation on a bean. When an Expression is evaluated, it follows the same contract as method-invocation where: the expression for an will generate a message anytime the evaluation result is a non-null value, while the expression for an must be the equivalent of a void returning method invocation.

关于java - Spring Integration - 在应用程序代码中调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29994253/

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