0
votes

I am new to Spring Integration and I am trying to read a file and transform into a custom object which has to be sent to jms Queue wrapped in jms.Message. It all has to be done using annotation.

I am reading the files from directory using below.

@Bean
@InboundChannelAdapter(value = "filesChannel", poller = @Poller(fixedRate = "5000", maxMessagesPerPoll = "1"))
public MessageSource<File> fileReadingMessageSource() {
    FileReadingMessageSource source = new FileReadingMessageSource();
    source.setDirectory(new File(INBOUND_PATH));
    source.setAutoCreateDirectory(false);
    /*source.setFilter(new AcceptOnceFileListFilter());*/
    source.setFilter(new CompositeFileListFilter<File>(getFileFilters()));
    return source;
}

Next Step is transforming the file content to Invoice Object(assume). I want to know what would be incoming message type for my transformer and how should I transform it. Could you please help here. I am not sure what would be the incoming datatype and what should be the transformed object type (should it be wrapped inside Message ?)

@Transformer(inputChannel = "filesChannel", outputChannel = "jmsOutBoundChannel")
public ? convertFiletoInvoice(? fileMessage){

    }
1

1 Answers

0
votes

The payload is a File (java.io.File).

You can read the file and output whatever you want (String, byte[], Invoice etc).

Or you could use some of the standard transformers (e.g. FileToStringTransformer, JsonToObjectTransformer etc).

The JMS adapter will convert the object to TextMessage, ObjectMessage etc.