2
votes

I'm trying sample program with file - inbound channel Adapter. I just want to read the file using adapter and pass it to the transformer to convert into Map and finally pass it to Service Activator to print the map.

When i run the program it is reaching transformer from Adapter but it is not reaching the Service Activator at all.

As i have used the Inbound Channel Adapter here, i have not used Gateway as an entry point. Is this something wrong?

@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");
   }
  }
1

1 Answers

0
votes

I guess there is something interesting in logs. Looks like your transformer throws error. That's why you can't reach the next component.

In addition you can switch on DEBUG for the org.springframework.integration category and investigate logs how your messages travel.