Spring 集成 - 在应用程序代码中调用方法

Spring Integration - Invoking Methods in Application Code

我有一个outbound-channel-adapter,相关配置如下所示。

<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);
    }
}

问题:

通道适配器调用了哪个 handleFeedFile 方法?

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

感谢您的帮助!

编辑:

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

根据 Spring 集成上的 documentation,您的情况下的 POJO(bean foo-handlerTarget)将使用包含负载的 Message 对象进行调用。你有没有执行你的代码?我希望它会生成 NoSuchMethodError.

你需要一个

public void handleFeedFile(Message<?> message);

方法。

您可能想参考 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.