[英]Spring-Integration: QueueChannel
简短的摘要:
我想将消息发送到队列,并使多个线程处理此消息。 应用程序应仅将消息异步发送到网关,但在队列已满时应将其阻塞。 我也想使传递到Queue的线程是多线程的。 我的问题是我的队列永远不会阻塞并接收更多消息,因此它的实际大小为
我不确定您所说的“不阻止”是什么意思。 这对我来说很好...
@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个立即发送,然后由于阻塞等待队列空间而每秒发送一次。
如果您想阻止呼叫者,为什么感觉需要异步网关?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.