春季集成服务激活器处理程序业务逻辑



我目前是Spring Integration的新手。
基本上试图用Java Spring Integration DSL异步将多个文件位置进行轮询。我需要获取文件名并使用文件名执行一些操作,然后将文件推到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)
    {
    }

我在这里附上了示例代码。
我还可以在频道中检索文件的文件名,因为我需要将其作为参数传递给FileUpload方法。请建议。

您的问题不清楚。TaskExecutor适用于流程中的线程上下文。服务激活器(.handle())正是您的业务逻辑方法。可以在执行人的线程上执行此操作。您确实正确地在IntegrationFlow中使用它们。

FileReadingMessageSourcejava.io.File作为payload产生消息。因此,这就是获取文件名的方法 - 仅来自File.getName()

相关内容

最新更新