gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:47:49 26 4
gpt4 key购买 nike

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

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。

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

  • ThreadLocal channel
  • 自动可声明声明

编辑:从 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

关于amqp - ThreadChannelConnectionFactory 是否应该与 RabbitAdmin 自动声明兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64877681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com