简体   繁体   English

Spring Integration:Transformer:文件到对象

[英]Spring Integration : Transformer : file to Object

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. 我是Spring Integration的新手,我试图读取一个文件并将其转换为一个自定义对象,该对象必须发送到jms中,并包装在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 ?) 我不确定传入的数据类型是什么,转换后的对象类型应该是什么(应该包装在Message中吗?)

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

    }

The payload is a File ( java.io.File ). 有效负载是一个Filejava.io.File )。

You can read the file and output whatever you want ( String , byte[] , Invoice etc). 您可以读取文件并输出所需的任何内容( Stringbyte[]Invoice等)。

Or you could use some of the standard transformers (eg FileToStringTransformer , JsonToObjectTransformer etc). 或者,您可以使用某些标准转换器(例如FileToStringTransformerJsonToObjectTransformer等)。

The JMS adapter will convert the object to TextMessage , ObjectMessage etc. JMS适配器会将对象转换为TextMessageObjectMessage等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM