简体   繁体   English

使用Spring Integration优化Rabbitmq的消费消息

[英]Optimise Consuming messages from rabbitmq using Spring Integration

I am attempting to build an IntegrationFlowFactory to easily build integration flows for passing events between application contexts. 我正在尝试构建一个IntegrationFlowFactory,以轻松构建用于在应用程序上下文之间传递事件的集成流程。

Everything seems to work, and events are being published very quick. 一切似乎都正常,事件正在快速发布。

However i cannot figure out why the consuming is so slow. 但是我不知道为什么消费如此缓慢。 Adding concurrentConsumers or changing prefetchCount does not seem to change anything. 添加并发消费者或更改prefetchCount似乎没有任何改变。

Other posts talk about the network being slow, but as you can see in the RabbitConfig i am using localhost. 其他帖子谈到网络运行缓慢,但是正如您在RabbitConfig中看到的那样,我正在使用localhost。

I have a repository with my spring integration example here: https://github.com/teplyuska/spring-integration-example 我在这里有一个带有我的spring集成示例的存储库: https : //github.com/teplyuska/spring-integration-example

Your problem is here: 您的问题在这里:

Amqp.inboundGateway(getListenerContainer(queue, concurrentConsumers, prefetchCount)

Meanwhile your downstream flow is one-way and doesn't return any reply: 同时,您的下游流是单向的 ,不返回任何答复:

.handle(p -> {
                UpdateSecretEvent payload = (UpdateSecretEvent) p.getPayload();
                System.out.println("Account: " + payload.getAccountId() + " has secret: " + payload.getNewSecret());
 })
.get();

or 要么

.handle(p -> {
                UpdateEmailEvent payload = (UpdateEmailEvent) p.getPayload();
                System.out.println("Account: " + payload.getAccountId() + " has email: " + payload.getEmail());
})
.get();

So, that AmqpInboundGateway waits for the reply in its MessagingTemplate.sendAndReceive() for the private static final long DEFAULT_TIMEOUT = 1000L; 因此, AmqpInboundGateway等待其MessagingTemplate.sendAndReceive()的响应, AmqpInboundGateway等待private static final long DEFAULT_TIMEOUT = 1000L; AmqpInboundGateway private static final long DEFAULT_TIMEOUT = 1000L;

Switching to the Amqp.inboundAdapter() there does the trick. 切换到Amqp.inboundAdapter()可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM