heuts
heuts

Reputation: 117

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.

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.

Other posts talk about the network being slow, but as you can see in the RabbitConfig i am using localhost.

I have a repository with my spring integration example here: https://github.com/teplyuska/spring-integration-example

Upvotes: 0

Views: 245

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

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;

Switching to the Amqp.inboundAdapter() there does the trick.

Upvotes: 1

Related Questions