spring-boot - Spring rabbitmq amqp connection Factory - How override connection properties
问题描述
I am trying to use SimpleMessageListenerContainer and Default connection factory, I don't want use properties using spring deault properties spring.rabbitmq.*, I would like to set connection properties at run-time when connection Factory injected. But my container try to connect to localhost, any help is much appriciated My code example is like this
@Bean
public SimpleMessageListenerContainer queueListenerContainer(AbstractConnectionFactory connectionFactory,
MessageListenerAdapter listenerAdapter) {
connectionFactory.setHost(Arrays.toString(rabbitMqConfig.getSubscriberHosts()));
connectionFactory.setVirtualHost("hydra.services");
connectionFactory.setPort(rabbitMqConfig.getSubscriberPort());
connectionFactory.setUsername(rabbitMqConfig.getSubscriberUsername());
connectionFactory.setPassword(rabbitMqConfig.getSubscriberPassword());
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setQueueNames(rabbitMqConfig.getSubscriberQueueName());
container.setConnectionFactory(connectionFactory);
// container.setQueueNames("SampleQueue"); /*This just for testing.. !*/
container.setMessageListener(listenerAdapter);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setDeclarationRetries(5);// This is default to 3, We can twick this and move this to prop
container.setPrefetchCount(100); //Tell the broker how many messages to send to each consumer in a single request.
return container;
}
But still the code this container try to connect to local host. Logs :
[30m2019-03-17 09:35:43,335[0;39m [34mINFO [0;39m [[34mmain[0;39m] [33morg.springframework.amqp.rabbit.connection.AbstractConnectionFactory[0;39m: Attempting to connect to: [localhost:5672] [30m2019-03-17 09:35:45,499[0;39m [34mINFO [0;39m [[34mmain[0;39m] [33morg.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer[0;39m: Broker not available; cannot force queue declarations during start [30m2019-03-17 09:35:45,778[0;39m [34mINFO [0;39m [[34mqueueListenerContainer-1[0;39m] [33morg.springframework.amqp.rabbit.connection.AbstractConnectionFactory[0;39m: Attempting to connect to: [localhost:5672] [30m2019-03-17 09:35:48,365[0;39m [34mINFO [0;39m [[34mmain[0;39m] [33morg.springframework.boot.StartupInfoLogger[0;39m: Started DftpEppScrubberApplication in 162.706 seconds (JVM running for 164.364)
Edit 2
This way I am getting unknowhost error. I thought initially it was firewall Issue but I checked connection everything seems to be right. I am not sure what is Problem Here!
解决方案
推荐阅读
- python - Google Kickstart 练习轮 2019 问题 1 中的错误答案(猜数)
- keycloak - KeyCloak“账户管理页面”的不同主题
- pycharm - pycharm中的自动右/左缩进关键字
- reactjs - 与 usestate 一起使用时,useAsync 会导致无限刷新循环
- javascript - Typescript 中是否有模式匹配类型?
- oracle - 对 Oracle 表使用 SHRINK SPACE 有什么缺点?
- python - 使用python根据第一天的值查找接下来几天重复id的记录
- r - 从相邻矩阵(从到)格式数据转换为长格式
- python - 在 Keras 中乘以大小 [batch] 和大小 [batch, features] 的张量
- reactjs - 添加 @zeit/next-css 时未找到模块