Spring Integration - Invoking Methods in Application Code

醉酒当歌 提交于 2019-12-12 15:26:34

问题


I have a outbound-channel-adapter, where the relevant configuration is shown below.

<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>

And in FooFeedHandlerImpl...

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


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

Questions:

Which handleFeedFile method gets invoked by the channel adapter?

When I invoke a method in the application code using Spring integration, how are the method parameters determined?

Thanks for any help!

Edit:

I ran my process locally (downloaded a local SFTP server - http://www.coreftp.com/server/index.html) and determined that the handleFeedFile(File file) method was invoked.


回答1:


You probably want to refer to 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.

and:

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.

If you're not in a position to annotate your target methods, then you might be able to use a SpEL expression to call your intended method:

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.




回答2:


According to the documentation on Spring integration, the POJO (bean foo-handlerTarget) in your case will get called with a Message object containing the payload. Have you executed your code? I'd expect it generates a NoSuchMethodError.

You need a

public void handleFeedFile(Message<?> message);

method.



来源:https://stackoverflow.com/questions/29994253/spring-integration-invoking-methods-in-application-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!