我在弹簧整合方面玩的更多,我对它非常感兴趣,但对我的意见有一个奇怪的行为,我找不到答案。弹簧积分队列通道容量错误
我使用队列通道的简单应用:
<int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket">
<int:queue capacity="1"/>
</int:channel>
我也试着交会,排队同样的效果:
<int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket">
<int:rendezvous-queue/>
</int:channel>
随着我的理解,现在应该只可能在该频道中一次移动一条消息。也许2,如果你认为你有一个额外的容量。我不知道如何阅读它。但是我可以在没有消耗的情况下将四次发送到该频道,这对我来说有点奇怪,然后我不了解容量。
如下图:
主要用途: 在这里,我流10票,并呼吁openTicket每个:
public static void main(final String[] args) throws InterruptedException {
try (ConfigurableApplicationContext context = SpringApplication.run(SassSimulatorApplication2.class, args)) {
final TicketGenerator generator = context.getBean(TicketGenerator.class);
final ProblemReporter reporter = context.getBean(ProblemReporter.class);
generator.createTickets().limit(10).forEach(reporter::openTicket);
context.close();
}
}
ProblemReporter:
public class ProblemReporter {
private volatile QueueChannel channel;
public synchronized void openTicket(final Ticket ticket){
final Message<Ticket> build = TicketMessageBuilder.buildMessage(ticket);
boolean send = channel.send(build);
System.out.println("send: " + send);
System.out.println("getQueueSize: " + channel.getQueueSize());
System.out.println("getSendCount: " + channel.getSendCount());
System.out.println("getReceiveCount: " + channel.getReceiveCount());
System.out.println("getSendErrorCount: " + channel.getSendErrorCount());
System.out.println("getRemainingCapacity: " + channel.getRemainingCapacity());
}
@Value("#{ticketChannel}")
public void setChannel(final QueueChannel channel) {
this.channel = channel;
}
}
启动时应用I得到以下:
send: true
getQueueSize: 0
getSendCount: 0
getReceiveCount: 0
getSendErrorCount: 0
getRemainingCapacity: 1
send: true
getQueueSize: 0
getSendCount: 0
getReceiveCount: 0
getSendErrorCount: 0
getRemainingCapacity: 1
send: true
getQueueSize: 1
getSendCount: 0
getReceiveCount: 0
getSendErrorCount: 0
getRemainingCapacity: 0
send: true
getQueueSize: 1
getSendCount: 0
getReceiveCount: 0
getSendErrorCount: 0
getRemainingCapacity: 0
我正在使用Spring-Boot 1.3.3,Sprint-Integration 4.2.5.RELEASE。我还使用Spring-Integration 4.1.9尝试了Spring-Boot 1.2.8。
是预期的行为?
在此先感谢。
感谢您的回复,我不确定您的意思是不是共享bean。我在上面的问题中扩展了我的课程。我通过@Value注入频道,所以它由Spring管理。当我偶然能力例如。 50,然后我进入200通道... –
行。因为它看起来像一个Spring Boot应用程序,所以如果你在GitHub的某个地方共享这个应用程序将会很好,我们将在本地使用它。 –
我真的很抱歉,我真的很无聊。我已经有了Transformator,他已经消费了票,所以队列中又有一个空间可用。如此尴尬,谢谢你的帮助。 –