2017-10-27 14 views
1

짧은 요약 : 나는 큐에 메시지를 보내고 여러 스레드가이 메시지를 처리 ​​할 수 ​​있도록 할봄 - 통합 : QueueChannel

. 응용 프로그램은 메시지를 게이트웨이에 비동기 적으로 보내야하지만 큐가 가득 차면 차단되어야합니다. 또한 Queue multi-threaded 로의 전달을 원했습니다. 내 문제는 내 대기열이 절대로 차단하지 않고 실제 크기가 더 많은 메시지를 전달한다는 것입니다.

답변

1

"차단하지 않음"이라는 것이 확실하지 않습니다. 이것은 나를 위해 잘 작동합니다 ...

@SpringBootApplication 
public class So46973604Application { 

    private final Logger LOGGER = LoggerFactory.getLogger(So46973604Application.class); 

    public static void main(String[] args) { 
     SpringApplication.run(So46973604Application.class, args).close(); 
    } 

    @Bean 
    ApplicationRunner runner(Gate gate) { 
     return args -> { 
      for (int i = 0; i < 20; i++) { 
       gate.send("foo"); 
       LOGGER.info("Sent " + i); 
      } 
     }; 
    } 

    @Bean 
    QueueChannel channel() { 
     return new QueueChannel(10); 
    } 

    @ServiceActivator(inputChannel = "channel", poller = @Poller(fixedDelay = "0")) 
    public void handle(String in) throws InterruptedException { 
     Thread.sleep(1_000); 
    } 

    @MessagingGateway(defaultRequestChannel = "channel") 
    public interface Gate { 

     void send(String out); 

    } 

} 

처음 10 개가 즉시 전송되고 대기열 차단 대기로 인해 초당 1 개가 전송됩니다.

왜 호출자를 차단하려면 비동기 게이트웨이가 필요하다고 생각하십니까?