title: REST endpoints in Spring Integration make messaging channels multithreaded
body: <p>I have a very simple  Spring Boot application, which provides a couple of restful endpoints and this is supposed to drive a sftp file being uploaded to a sftp server. My requirement is that if there is more than one file, the files should be queued. I expected to achieve this with the default behaviour of the sftp spring integration workflow, as i read that DirectChannel automatically queues files. To test the behaviour I do the following: </p>
  
  <ol>
  <li>Send a big file, blocking the channel for a while by calling an endpoint.</li>
  <li>Send a smaller file by calling an endpoint.</li>
  </ol>
  
  <p>Expected result: the smaller file is queued onto a channel and is processed after the uploading of the bigger file is finished.
  Actual result: A new connection to sftp server is opened and the smaller file is uploaded there without being queued, while the bigger file continues transmission.</p>
  
  <p>There are two files in my application:</p>
  
  <p>DemoApplication.java</p>
  
  <pre><code>@SpringBootApplication
  @IntegrationComponentScan
  @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
  public class DemoApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
  
      @Bean
      public SessionFactory&lt;LsEntry&gt; sftpSessionFactory() {
          DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
          factory.setHost("localhost");
          factory.setPort(22);
          factory.setUser("tester");
          factory.setPassword("password");
          factory.setAllowUnknownKeys(true);
          return factory;
      }
  
      @Bean
      @ServiceActivator(inputChannel = "toSftpChannel")
      public MessageHandler handler() {
          SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory());
          handler.setRemoteDirectoryExpression(new LiteralExpression("/"));
          return handler;
      }
  
      @MessagingGateway
      public interface MyGateway {
  
           @Gateway(requestChannel = "toSftpChannel")
           void sendToSftp(File file);
      }
  }
  </code></pre>
  
  <p>DemoController.java</p>
  
  <pre><code>@RestController
  public class DemoController {
  
      @Autowired
      MyGateway gateway;
  
      @RequestMapping("/sendFile")
      public void sendFile() {
          File file = new File("C:/smallFile.txt");
          gateway.sendToSftp(file);
      }
  
      @RequestMapping("/sendBigFile")
      public void sendBigFile() {
          File file = new File("D:/bigFile.zip");
          gateway.sendToSftp(file);
      }
  }
  </code></pre>
  
  <p>I'm a complete newbie to spring and i'm not sure entirely that my sftp channels get created here properly, my guess would be that a new one gets created every time i do a sendToSftp call. Any help on how to achieve the queue behaviour in this case would be appreciated.</p>