I want to get the bound Rabbit user and password in Cloud Foundry.
Configuration:
@Profile("cloud")
@Configuration
public class RabbitMQCloudConfig extends AbstractCloudConfig {
public ConnectionFactory rabbitFactory() {
return connectionFactory().rabbitConnectionFactory();
}
}
And in my controller I can get the rabbit user but how can I get the password?
@Autowired(required = false)
RabbitMQCloudConfig rabbitMQCloudConfig;
private void setRabbitCredentialsForCF() {
this.user = rabbitMQCloudConfig.rabbitFactory().getUsername();
//this.password = ????
}
It seems that you are using Spring's RabbitMQ integration as your client.
So the question is which ConnectionFactory implementation did you register as your ConnectionFactory Bean. If you are using any subclass of AbstractConnectionFactory
, there is a public getRabbitConnectionFactory
which returns a reference to the underlying Rabbit Connection factory
. Once you get the RabbitConnectionFactory, getting password is pretty easy by calling the getPassword
method.
org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
/**
* Return a reference to the underlying Rabbit Connection factory.
* @return the connection factory.
* @since 1.5.6
*/
public com.rabbitmq.client.ConnectionFactory getRabbitConnectionFactory() {
return this.rabbitConnectionFactory;
}