Spring integration Spring集成-文件入站通道适配器

Spring integration Spring集成-文件入站通道适配器,spring-integration,Spring Integration,我正在尝试使用文件入站通道适配器的示例程序。我只想使用适配器读取该文件,并将其传递给转换器以转换为映射,最后将其传递给ServiceActivator以打印映射 当我运行程序时,它正在从适配器到达transformer,但它根本没有到达Service Activator 因为我在这里使用了入站通道适配器,所以我没有使用网关作为入口点。这有什么不对吗 @Configuration public class SpringIntegrationAdapterConfig { static Logge

我正在尝试使用文件入站通道适配器的示例程序。我只想使用适配器读取该文件,并将其传递给转换器以转换为映射,最后将其传递给ServiceActivator以打印映射

当我运行程序时,它正在从适配器到达transformer,但它根本没有到达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");
   }
  }
@配置
公共类SpringIntegrationAdapterConfig{
静态记录器log=Logger.getLogger(SpringIntegrationAdapterConfig.class);
@豆子
@InboundChannelAdapter(value=“fileInputChannel”,poller=@poller(fixedDelay=“1000”))
public MessageSource fileReadingMessageResource(){
FileReadingMessageSource=新建FileReadingMessageSource();
setDirectory(新文件(“C:\\Rajashree\\work\\test”);
setFilter(新的SimplePatternFileListFilter(“Sample.csv”);
log.info(“使用文件适配器读取文件”);
返回源;
}
}
@组成部分
公共类文件服务{
静态记录器log=Logger.getLogger(FileService.class);
@转换器(inputChannel=“fileInputChannel”,outputChannel=“mappingChannel”)
公共列表读取文件(文件文件){
log.info(file.getName());
List dataList=new ArrayList();
CSVFormat CSVFormat=CSVFormat.DEFAULT.withHeader();
try(CSVParser parser=newcsvparser(newfilereader(file),csvFormat)){
parser.getRecords().stream().map(e->dataList.add(e.toMap()).collect(Collectors.toList());
日志信息(数据列表);
}捕获(IOE异常){
log.error(“文件读取错误:+e”);
}
返回数据列表;
}
}
@组成部分
公共类映射转换器{
@转换器(inputChannel=“mappingChannel”,outputChannel=“printChannel”)
公共列表映射字段(列表数据列表){
System.out.println(“文件映射::”+数据列表);
返回数据列表;
}
}
@消息端点
公共类打印服务{
@ServiceActivator(inputChannel=“printChannel”,outputChannel=“outputChannel”)
公共作废打印(列表数据列表){
System.out.println(“消息打印”);
}
}

我想日志中有一些有趣的东西。看起来你的变压器出错了。这就是为什么您无法访问下一个组件


此外,您可以打开
org.springframework.integration
类别的
DEBUG
,并调查您的消息如何传播。

Transformer工作正常。我使用普通方法加载文件,并通过网关调用transformer。整个流程运行良好。但是我想用文件适配器加载文件,但它不工作。请用日志和堆栈状态确认您的“但是”。让我知道。。。非常感谢。