Java 8 Spring集成服务激活器处理程序业务逻辑

Java 8 Spring集成服务激活器处理程序业务逻辑,java-8,spring-integration,dsl,spring-integration-dsl,spring-integration-aws,Java 8,Spring Integration,Dsl,Spring Integration Dsl,Spring Integration Aws,我目前不熟悉Spring集成。 基本上,尝试使用JavaSpringIntegrationDSL异步轮询多个文件位置。我需要获取文件名并使用文件名执行一些操作,然后将文件推送到S3。最后,我的问题是,这些使用文件执行操作的任务可以在任务执行器或服务激活器处理程序中执行吗。我不知道哪个地方对 @Autowired private AWSFileManager awsFileManager; @Bean public IntegrationFlow inboundChannelFlow(@Valu

我目前不熟悉Spring集成。
基本上,尝试使用JavaSpringIntegrationDSL异步轮询多个文件位置。我需要获取文件名并使用文件名执行一些操作,然后将文件推送到S3。最后,我的问题是,这些使用文件执行操作的任务可以在任务执行器或服务激活器处理程序中执行吗。我不知道哪个地方对

@Autowired
private AWSFileManager awsFileManager;

@Bean
public IntegrationFlow inboundChannelFlow(@Value("${file.poller.delay}") long delay,
@Value("${file.poller.messages}") int maxMsgsPerPoll,
TaskExecutor taskExecutor, MessageSource<File> fileSource) 
{
    return IntegrationFlows.from(fileSource,
            c -> c.poller(Pollers.fixedDelay(delay)
                    .taskExecutor(taskExecutor)
                    .maxMessagesPerPoll(maxMsgsPerPoll)))
            .handle("AWSFileManager", "fileUpload")
            .channel(ApplicationConfiguration.inboundChannel)
            .get();
}

@Bean
TaskExecutor taskExecutor(@Value("${file.poller.thread.pool.size}") int poolSize) {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    //Runnable task1 = () -> {this.methodsamp();};
    taskExecutor.setCorePoolSize(poolSize);

    //taskExecutor.execute(task1);
    return taskExecutor;
}
@Async
public void methodsamp()
{
    try
    {
        awsFileManager.fileUpload();
        System.out.println("test");
    }
    catch(Exception ex)
    {

    }
@Autowired
私人AWSFileManager AWSFileManager;
@豆子
public IntegrationFlow inboundChannelFlow(@Value(${file.poller.delay})长延迟,
@值(“${file.poller.messages}”)int-maxMsgsPerPoll,
TaskExecutor TaskExecutor,MessageSource文件源)
{
返回IntegrationFlows.from(文件源,
c->c.轮询器(轮询器固定延迟(延迟)
.taskExecutor(taskExecutor)
.maxMessagesPerPoll(maxmsgspepoll)))
.handle(“AWSFileManager”、“文件上载”)
.channel(应用程序配置.inboundChannel)
.get();
}
@豆子
TaskExecutor TaskExecutor(@Value(“${file.poller.thread.pool.size}”)int-poolSize){
ThreadPoolTaskExecutor taskExecutor=新的ThreadPoolTaskExecutor();
//Runnable task1=()->{this.methodsamp();};
taskExecutor.setCorePoolSize(池大小);
//taskExecutor.execute(task1);
返回任务执行器;
}
@异步的
公共无效方法samp()
{
尝试
{
awsFileManager.fileUpload();
系统输出打印(“测试”);
}
捕获(例外情况除外)
{
}
我在这里附上了示例代码。
还有一种方法可以检索通道中文件的文件名,因为我需要将此作为参数传递给fileUpload方法。
请告知。

您的问题不清楚。
TaskExecutor
用于流中的线程上下文。Service Activator(
.handle()
)正是用于您的业务逻辑方法。此操作可以在来自executor的线程上执行。并且您在
集成流中确实正确地使用了它们


FileReadingMessageSource
使用
java.io.File
作为
有效负载生成消息。因此,这是获取文件名的方法-仅从
File.getName()获取

请不要对每个SO线程问太多问题。你当然……下次会继续问。谢谢!非常感谢你。我知道了,但处理程序只使用bean名称和方法名称,这两个字符串。我如何为它们指定filename参数?你为什么会关心这个问题?我想你肯定需要一个
File
对象将其发送到AWS S3。因此,您应该在
fileUpload()
中看到
句柄()
接收到的消息的
poyload
。我建议您阅读有关这方面的书籍,或者至少阅读Spring集成参考手册‌​生成带有文件作为有效载荷的消息。这些消息被发送到频道。
.handle()
订阅该频道并调用您的服务方法,并为该方法的参数提供适当的值。您应该将您的服务方法设置为
文件上载(File fileToUpload)
和传入消息的
有效负载
将被传递到此参数。我无法让处理程序串行运行。我有类似的内容:
.handle(“awsFileManager”,“fileUpload”).handle(“filewriteMessageHandler”)
它们似乎没有一个接一个地运行,文件写入器消息处理程序在文件上载方法之前被调用,这是另一个问题。你需要记住,下一个
.handle()
是基于上一个的结果。我甚至对调用它感到惊讶,因为我不知道你的
文件上载是如何进行的()
返回任何内容。