我在彈簧整合方面玩的更多,我對它非常感興趣,但對我的意見有一個奇怪的行爲,我找不到答案。彈簧積分隊列通道容量錯誤
我使用隊列通道的簡單應用:
<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,他已經消費了票,所以隊列中又有一個空間可用。如此尷尬,謝謝你的幫助。 –