Spring integration Spring集成队列通道容量错误

Spring integration Spring集成队列通道容量错误,spring-integration,message-queue,Spring Integration,Message Queue,我对spring integration更感兴趣,但我认为有一种奇怪的行为,我找不到答案 我有一个使用队列通道的简单应用程序: <int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket"> <int:queue capacity="1"/> </int:channel> 问题记者: public class ProblemReporter { privat

我对spring integration更感兴趣,但我认为有一种奇怪的行为,我找不到答案

我有一个使用队列通道的简单应用程序:

<int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket">
    <int:queue capacity="1"/>
</int:channel>
问题记者:

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;
    }
}
我使用的是Spring Boot 1.3.3,Sprint Integration 4.2.5.0版本。我还尝试了SpringBoot1.2.8和SpringIntegration4.1.9

这是预期的行为吗


提前感谢。

看起来像你的
频道。发送(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());
        });
注意:只能通过
@EnableIntegrationMBeanExport
@EnableIntegrationManagement
来启用
sendCount
(及类似功能)。 请参阅参考手册中的


此外,您还可以在框架中找到一些关于此问题的测试用例,例如…

谢谢您的回复,我不确定您对not shared bean的意思。我在上面的问题中扩展了我的课程。我通过@Value注入通道,因此它由Spring管理。当我有机会将容量提高到50,那么我就可以在频道中获得200…好的。因为它看起来像一个Spring Boot应用程序,所以如果你在GitHub上的某个地方共享它,我们将在本地使用它,那就太好了。我已经有了一个转换者,他已经消费了票,所以这是队列中又一个可用的空间。太尴尬了,谢谢你的帮助。这不是尊重的问题。问题出在其他地方,但出于帮助,我接受你的回答:-)
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
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