简短摘要:
我希望将消息发送到队列,并使多个线程处理这些消息。应用程序应该只是异步地将消息发送到Gateway,但在队列已满时应该会被阻塞。另外,我还想将消息传递到多线程队列。我的问题是,我的队列永远不会阻塞并接收比实际大小更大的消息。
发布于 2017-10-27 16:33:49
我不知道你所说的“不妨碍”是什么意思。对我来说很好..。
@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立即发送,然后每秒一个。
如果你想阻止调用者,为什么你觉得你需要一个异步网关?
https://stackoverflow.com/questions/46973604
复制相似问题