0
votes

For File reading message source Inbound Adapter and transformer with annotations is configured as below

@Bean
@InboundChannelAdapter(autoStartup = "false", value = "incomingchannel", poller = @Poller("custompoller"))
    public MessageSource<File> fileReadingMessageSource() {

}

@Transformer(inputChannel = "incomingchannel", outputChannel = "jobLaunchChannel")
    public JobLaunchRequest toRequest(Message<File> message) throws Exception {

}

Now I want to change the Transformer to refer to a reply channel of outbound gateway i.e. which moves the files from one directory to another directory i.e. move the file from incomingchannel directory to a different directory and the process or transform he file or perform some validations

<file:outbound-gateway id="mover" request-channel="incomingchannel" reply-channel="newdirectory" directory="<<path to new directory file to be moved" delete-source-files="true"/>

Anyone has converted above XML configuration to annotation configurations or any ideas?

After annotation configurations I will have to change the transformer input channel to refer to newdirectory channel i.e. which is a reply channel of messaging gateway...

Thanks in advance for any help ot suggestions regarding this

--- Update 1 after trying out the snippet provided in link by Artem

@Bean
@ServiceActivator(inputChannel = "incomingchannel")
public MessageHandler fileWritingMessageHandler() {
    FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(newdirectorypath));
    handler.setFileExistsMode(FileExistsMode.APPEND);
    handler.setDeleteSourceFiles(true);
    return handler;
}

@MessagingGateway(defaultRequestChannel = "incomingchannel", defaultReplyChannel = "newdirectorychannel")
public interface MyGateway {

    void writeToFile(@Header(FileHeaders.FILENAME) String fileName, @Header(FileHeaders.FILENAME) File directory,
            String data);

}

But there are two problems encountered

  1. Inbound Adapter is trying to poll the directory also as file (Recursive Directory scanner is used) - How to ensure that directory is not polled as a file

  2. nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available, failedMessage=GenericMessage [payload=C

1
Sorry, your problem is not clear. Maybe you have something in XML already as a whole solution so it would be easier for us to understand what is a scope of the problem... The <file:outbound-gateway is a FileWritingMessageHandler in Java. See in docs: docs.spring.io/spring-integration/docs/5.3.0.M4/reference/html/…Artem Bilan
@ArtemBilan, yes you are right , we already have a solution in xml configuration and as mentioned in above code snippet <outbound-Gateway configuration to move the file from incoming directory to another director and then process in the transformer.Vas..
M-m-m. so you want to place a FileWritingMessageHandler in between your @InboundChannelAdapter and JobLaunchRequest @Transformer ?Artem Bilan
@ArtemBilan, Yes perfect, i have updated the question with the implementation tried but there are exceptions. Also the InboundChannel Adapter used the recursive directory scanner, problem is Directory is also scanned and listed.Vas..

1 Answers

0
votes

Ok. Since it looks like you would like to place the FileWritingMessageHandler after @InboundChannelAdapter and before @Transformer, so this should like:

@Bean
@InboundChannelAdapter(autoStartup = "false", value = "incomingchannel", poller = @Poller("custompoller"))
    public MessageSource<File> fileReadingMessageSource() {

}

@Bean
@ServiceActivator(inputChannel = "incomingchannel")
public MessageHandler fileWritingMessageHandler() {
    FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(newdirectorypath));
    handler.setFileExistsMode(FileExistsMode.APPEND);
    handler.setDeleteSourceFiles(true);
    handler.setOutputChannelName("jobLaunchTransfromerCannel");
    return handler;
}

@Transformer(inputChannel = "jobLaunchTransfromerCannel", outputChannel = "jobLaunchChannel")
    public JobLaunchRequest toRequest(Message<File> message) throws Exception {

}

This way an @InboundChannelAdapter sends a File into a FileWritingMessageHandler for its logic, which produces a result file for the next in flow @Transformer to convert a result file into a JobLaunchRequest. And only after that a message is going to be sent to the jobLaunchChannel to file a Spring Batch Job.