我更喜欢弹簧整合我非常感兴趣的东西,但我认为这是一个奇怪的行为,我找不到答案。
我有一个使用Queue-Channel的简单应用程序:
<int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket">
<int:queue capacity="1"/>
</int:channel>
我也尝试过具有相同效果的Rendezvous-Queue:
<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;
}
}
开始申请时,我得到以下内容:
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。
这是预期的行为???
提前致谢。
答案 0 :(得分:1)
您的channel.send(build, 30000);
似乎是针对local
变量而非共享bean
完成的。
我的测试用例如下:
QueueChannel channel = new QueueChannel(3);
IntStream.range(0, 4)
.forEach(i -> {
boolean send = channel.send(new GenericMessage<>("test-" + i), 100);
System.out.println("send: " + send);
System.out.println("getQueueSize: " + channel.getQueueSize());
System.out.println("getRemainingCapacity: " + channel.getRemainingCapacity());
});
结果是:
send: true
getQueueSize: 1
getRemainingCapacity: 2
send: true
getQueueSize: 2
getRemainingCapacity: 1
send: true
getQueueSize: 3
getRemainingCapacity: 0
send: false
getQueueSize: 3
getRemainingCapacity: 0
注意:sendCount
(及类似内容)只能通过@EnableIntegrationMBeanExport
或@EnableIntegrationManagement
启用。
请参阅参考手册中的Management。
此外,您可以在框架中找到有关此问题的一些测试用例,例如: QueueChannelTests