forked from jmug/stoatchat
fix: amqprs startup bug (#744)
This commit is contained in:
@@ -29,7 +29,7 @@ impl AMQP {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_auto() -> AMQP {
|
pub async fn new_auto() -> revolt_result::Result<AMQP> {
|
||||||
let config = revolt_config::config().await;
|
let config = revolt_config::config().await;
|
||||||
|
|
||||||
let connection = Connection::open(&OpenConnectionArguments::new(
|
let connection = Connection::open(&OpenConnectionArguments::new(
|
||||||
@@ -46,21 +46,26 @@ impl AMQP {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to open RabbitMQ channel");
|
.expect("Failed to open RabbitMQ channel");
|
||||||
|
|
||||||
channel
|
let mut resp = AMQP::new(connection, channel);
|
||||||
.exchange_declare(
|
resp.configure_channels().await?;
|
||||||
ExchangeDeclareArguments::new(&config.pushd.exchange, "direct")
|
Ok(resp)
|
||||||
.durable(true)
|
|
||||||
.finish(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.expect("Failed to declare exchange");
|
|
||||||
|
|
||||||
AMQP::new(connection, channel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn configure_channels(&self) -> revolt_result::Result<()> {
|
pub async fn repoen_channel(&mut self) {
|
||||||
|
self.channel = self
|
||||||
|
.connection
|
||||||
|
.open_channel(None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to open RabbitMQ channel");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn configure_channels(&mut self) -> revolt_result::Result<()> {
|
||||||
let config = revolt_config::config().await;
|
let config = revolt_config::config().await;
|
||||||
|
|
||||||
|
if !self.channel.is_open() {
|
||||||
|
self.repoen_channel().await;
|
||||||
|
}
|
||||||
|
|
||||||
self.channel
|
self.channel
|
||||||
.exchange_declare(
|
.exchange_declare(
|
||||||
ExchangeDeclareArguments::new(
|
ExchangeDeclareArguments::new(
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ pub async fn web() -> Rocket<Build> {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to declare exchange");
|
.expect("Failed to declare exchange");
|
||||||
|
|
||||||
let amqp = AMQP::new(connection, channel);
|
let mut amqp = AMQP::new(connection, channel);
|
||||||
amqp.configure_channels()
|
amqp.configure_channels()
|
||||||
.await
|
.await
|
||||||
.expect("Failed to configure channels");
|
.expect("Failed to configure channels");
|
||||||
|
|||||||
Reference in New Issue
Block a user