Allow configuring vhost

This commit is contained in:
Graham Christensen 2018-03-01 22:42:25 -05:00
parent c6855b5fd3
commit 7eb39889c3
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
2 changed files with 5 additions and 3 deletions

View file

@ -33,6 +33,7 @@ pub struct FeedbackConfig {
pub struct RabbitMQConfig { pub struct RabbitMQConfig {
pub ssl: bool, pub ssl: bool,
pub host: String, pub host: String,
pub virtualhost: Option<String>,
pub username: String, pub username: String,
pub password: String, pub password: String,
} }
@ -118,11 +119,12 @@ impl Config {
impl RabbitMQConfig { impl RabbitMQConfig {
pub fn as_uri(&self) -> String { pub fn as_uri(&self) -> String {
return format!( return format!(
"{}://{}:{}@{}//", "{}://{}:{}@{}/{}",
if self.ssl { "amqps" } else { "amqp" }, if self.ssl { "amqps" } else { "amqp" },
self.username, self.username,
self.password, self.password,
self.host self.host,
self.virtualhost.clone().unwrap_or("/".to_owned()),
); );
} }
} }

View file

@ -301,7 +301,7 @@ pub fn session_from_config(config: &RabbitMQConfig) -> Result<amqp::Session, amq
amqp::AMQPScheme::AMQPS => 5671, amqp::AMQPScheme::AMQPS => 5671,
amqp::AMQPScheme::AMQP => 5672, amqp::AMQPScheme::AMQP => 5672,
}, },
vhost: "/".to_owned(), vhost: config.virtualhost.clone().unwrap_or("/".to_owned()),
login: config.username.clone(), login: config.username.clone(),
password: config.password.clone(), password: config.password.clone(),
scheme: scheme, scheme: scheme,