Raven21
Raven21

Reputation: 35

Spring Integration Service Activator handler business logic

I am currently new to Spring Integration.
Basically trying to poll onto multiple file locations asynchronously with Java Spring integration DSL. I am required to get the file name and perform some operations with filename and push the file to S3 finally, my question is can these tasks of performing operations with file be performed in the task executor or the service activator handler . I am not sure which is the right place.

@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)
    {

    }

I have attached the sample code here.
Also is there a way I could retrieve the filename of the files in the channel as I need to pass this as parameter to the fileUpload method. Please advise.

Upvotes: 1

Views: 864

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121442

Your question isn't clear. The TaskExecutor is for the thread context in the flow. The Service Activator (.handle()) is exactly for your business logic method. This one can be performed on a thread from the executor. And you really use them in your IntegrationFlow correctly.

The FileReadingMessageSource produces message with the java.io.File as a payload. So, that is the way to get a file name - just from File.getName()!

Upvotes: 1

Related Questions