Eyck
Eyck

Reputation: 53

RabbitTemplate send failure after deleting exchange

I've got following problem. I'm using RabbitTemplate class from spring-rabbit-2.0.5.RELEASE. And send messeges to different exchanges using it. By default everything work fine. But when one of the exchanges is being deleted and there is a lot of messages to process there is a problem with sending messages to existing exchange - but no error is being thrown - messages are just silently dropped.

Code can be simplify to this. In given scenario after deleting exchange EX2 - Only part of the messages would be sent to EX1. Simple fix for that would be add a Thread.sleep(50) after each send - but this obviously unacceptable.

    RabbitTemplate rabbitTemplate = new RabbitTemplate();
    for (int i = 0; i < 1000; i++) {
        rabbitTemplate.send("EX1", "RK1", someMessage);
        rabbitTemplate.send("EX2", "RK2", someMessage);
    }

After doing some investigations I came to following conclusions:

1) I'm reusing an existing channel - which is obvious

2) After sending message to non existing exchange channel is being closed and unfortunately it seems that is being closed by Rabbit itself and shutdown message is being send asynchronously to driver

3) After getting message about closed connection driver recreate a channel but messages sent in the meantime are lost

One of the possible solution would be having different channel for each exchange (it will work in my case as I'm sending messages only to couple of exchanges (less then 10)).

But in general it seems that this is just expected behaviour of RabbitTemplate (when your are not using confirmations)

Upvotes: 0

Views: 292

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121282

I think you need to study what is Publisher Confirms and Returns: https://docs.spring.io/spring-amqp/docs/2.1.3.RELEASE/reference/html/_reference.html#cf-pub-conf-ret

Also follow the link about Scoped Operations.

Upvotes: 1

Related Questions