ThreadChannelConnectionFactory 是否应该与 RabbitAdmin 自动声明兼容?

Is ThreadChannelConnectionFactory supposed to be compatible with RabbitAdmin automatic declaration?

如下面的(失败)测试所示,创建连接时未声明可声明对象:

private const val QUEUE = "test"

@SpringBootTest
class ThreadChannelConnectionFactoryTest {

    @Autowired
    private lateinit var admin: AmqpAdmin

    @Test
    fun queueExists() {
        assertThat(admin.getQueueInfo(QUEUE)).isNotNull
    }

    @SpringBootApplication(proxyBeanMethods = false)
    protected class TestApplication {

        @Bean
        fun queue() = QueueBuilder.nonDurable(QUEUE).build()

        @Bean
        fun connectionFactory() = ThreadChannelConnectionFactory(RabbitConnectionFactoryBean().rabbitConnectionFactory)
    }
}

注释掉 connectionFactory bean 定义使测试通过,因为 Spring Boot 随后会创建一个老式的 CachingConnectionFactory。

这有什么充分的理由,还是只是被忽视了?如果我需要两个功能集,我有什么选择?

编辑:从 2.3.1 开始,以下解决方法似乎有效:

class ConnectionListenerFiringThreadChannelConnectionFactory(connectionFactory: ConnectionFactory, isPublisher: Boolean) : ThreadChannelConnectionFactory(connectionFactory) {

    init {
        if (!isPublisher) {
            setPublisherConnectionFactory(ConnectionListenerFiringThreadChannelConnectionFactory(connectionFactory, true))
        }
    }

    constructor(connectionFactory: ConnectionFactory) : this(connectionFactory, false)

    override fun createConnection(): Connection {
        val connection = super.createConnection()
        connectionListener.onCreate(connection)

        return connection
    }
}

这是一个错误;您的解决方法是正确的。

https://github.com/spring-projects/spring-amqp/issues/1268