0
我正在嘗試使用文件 - 入站通道適配器的示例程序。我只想使用適配器讀取文件並將其傳遞給變換器以轉換爲Map,最後將其傳遞給Service Activator以打印映射。彈簧集成 - 文件入站通道適配器
當我運行程序時,它從適配器到達變壓器,但它根本沒有到達服務激活器。
因爲我已經在這裏使用的入站通道適配器,我沒有使用網關作爲切入點。這是錯的嗎?
@Configuration
public class SpringIntegrationAdapterConfig {
static Logger log = Logger.getLogger(SpringIntegrationAdapterConfig.class);
@Bean
@InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(fixedDelay = "1000"))
public MessageSource<File> fileReadingMessageResource(){
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File("C:\\Rajashree\\work\\test"));
source.setFilter(new SimplePatternFileListFilter("Sample.csv"));
log.info("Reading file using File Adapter");
return source;
}
}
@Component
public class FileService {
static Logger log = Logger.getLogger(FileService.class);
@Transformer(inputChannel = "fileInputChannel", outputChannel = "mappingChannel")
public List<Map<String, String>> readFile(File file){
log.info(file.getName());
List<Map<String, String>> dataList = new ArrayList<>();
CSVFormat csvFormat = CSVFormat.DEFAULT.withHeader();
try(CSVParser parser = new CSVParser(new FileReader(file), csvFormat)){
parser.getRecords().stream().map(e -> dataList.add(e.toMap())).collect(Collectors.toList());
log.info(dataList);
} catch (IOException e) {
log.error("File read Error : " + e);
}
return dataList;
}
}
@Component
public class MappingTransformer {
@Transformer(inputChannel = "mappingChannel", outputChannel = "printChannel")
public List<Map<String, String>> mapFields(List<Map<String, String>> dataList){
System.out.println("File mapped :: " + dataList);
return dataList;
}
}
@MessageEndpoint
public class printService{
@ServiceActivator(inputChannel="printChannel", outputChannel= "outputChannel")
public void print(List<Map<String, String>> dataList){
System.out.println("Message Printed");
}
}
變壓器工作正常。我用普通的方法加載文件並通過網關調用變換器。整個流程正常工作。但我想使用文件適配器加載文件,但它不工作。 –
你「而是」應該原木確認和堆棧狀態,請。 –
讓我發現了...謝謝您 –