I am trying to listen to any lapin connection error in Rust. I want to restart my connection with RabbitMQ once the disconnect happens. I have a 3 second backoff time inside the restart function which retries connection with RabbitMQ indefinitely.
This code doesn’t seem to work though, because trying to spawn a new tokio thread causes this issue:
there is no reactor running, must be called from the context of a Tokio 1.x runtime
stack backtrace:
2024-08-16T06:13:19.442374Z ERROR lapin::io_loop: error doing IO error=IOError(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" })
2024-08-16T06:13:19.442389Z ERROR lapin::channels: Connection error error=IO error: Connection reset by peer (os error 104)
20
let instance = self.clone();
connection.on_error(move |err| {
let instance_copy = instance.clone();
tokio::spawn(async move {
event!(Level::ERROR, "Connection Tokio spawn restart");
instance_copy.restart().await;
event!(Level::ERROR, "Connection Tokio spawn restart done");
});
});