GH-2815: Fix RabbitAdmin for static `Declarables

Fixes: #2815
Issue link: https://github.com/spring-projects/spring-amqp/issues/2815

When rabbitmq resets, `RabbitAdmin#initialize` calls `redeclareManualDeclarables()` first, before it continues with re-declaring statically configured declarations. 
This means that explicitly declared Bindings to statically declared Exchanges can never be restored, because the Exchange has to exist in order for the Binding declaration to succeed.

* Call new `redeclareBeanDeclarables()` before `redeclareManualDeclarables()`

**Auto-cherry-pick to `3.1.x`**
This commit is contained in:
Tran Ngoc Nhan
2024-09-16 23:39:12 +07:00
committed by GitHub
parent 7d1e696d7f
commit 2ebc7ef123

View File

@@ -81,6 +81,7 @@ import com.rabbitmq.client.Channel;
* @author Gary Russell
* @author Artem Bilan
* @author Christian Tzolov
* @author Ngoc Nhan
*/
@ManagedResource(description = "Admin Tasks")
public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, ApplicationEventPublisherAware,
@@ -648,8 +649,14 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Applicat
@Override // NOSONAR complexity
public void initialize() {
redeclareBeanDeclarables();
redeclareManualDeclarables();
}
/**
* Process bean declarables.
*/
private void redeclareBeanDeclarables() {
if (this.applicationContext == null) {
this.logger.debug("no ApplicationContext has been set, cannot auto-declare Exchanges, Queues, and Bindings");
return;