1 回答

TA貢獻1868條經(jīng)驗 獲得超4個贊
問題似乎是 RabbitMQComponent 期望找到 com.rabbitmq.client.ConnectionFactory 類型的連接工廠。
但是,springboot 自動配置正在創(chuàng)建一個 org.springframework.amqp.rabbit.connection.CachingConnectionFactory 類型的連接工廠。
因此,每當(dāng) RabbitMQComponent 試圖找到適當(dāng)?shù)倪B接工廠時,因為它正在尋找特定的類型,并且因為它沒有子類化 rabbitmq ConnectionFactory,它返回一個空值,并且無法使用指定的適當(dāng)主機名和配置參數(shù)在您的 application.yml 中。
You should also see the following in your log if you have debug level set:
2019-12-15 17:58:53.631 DEBUG 48710 --- [ main] o.a.c.c.rabbitmq.RabbitMQComponent : Creating RabbitMQEndpoint with host null:0 and exchangeName: asterix
2019-12-15 17:58:55.927 DEBUG 48710 --- [ main] o.a.c.c.rabbitmq.RabbitMQComponent : Creating RabbitMQEndpoint with host null:0 and exchangeName: asterix-sink
編輯: CachingConnectionFactory 配置有所需的 Rabbit 連接工廠作為自動配置的一部分。但是,您需要提供指向正確工廠的鏈接。
因此,您需要添加一個@Bean 來消除歧義。
@Configuration
@RequiredArgsConstructor
public class CamelConfig {
private final CachingConnectionFactory rabbitConnectionFactory;
@Bean
com.rabbitmq.client.ConnectionFactory rabbitSourceConnectionFactory() {
return rabbitConnectionFactory.getRabbitConnectionFactory();
}
}
并在您的端點配置中:
rabbitmq:asterix?connectionFactory=#rabbitSourceConnectionFactory
請注意,# 是可選的,因為當(dāng)它試圖查找 rabbit 連接工廠 bean 時,它會在代碼中被刪除。
在您的 application.yml 中,配置連接參數(shù)(該 url 不再包含在端點 URI 中)。
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
添加回答
舉報