axum-strangler initial release

35 points midasso

Hey all! I've just released a crate to help with transitioning services from something else to Rust using the strangler fig pattern (https://docs.microsoft.com/en-us/azure/architecture/patterns/strangler-fig).
In short, the strangler fig pattern is just incrementally replacing parts of a service by another service without a consumer of said service noticing, and eventually the old service "dies" because there is nothing left to replace.

The crate is: https://crates.io/crates/axum-strangler. It aims to allow you to "automatically" follow the strangler fig pattern by allowing you to specify routes (or just as an entire fallback) in the axum framework that you want to be handled by the previous service, and the requests will just be forwarded to the strangled service, and the responses will also just pass back through.

An example:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let http_client = reqwest::Client::new();
    let strangler_svc = axum_strangler::StranglerService::new(
        http_client,
        axum::http::uri::Authority::from_static("127.0.0.1:3333"),
        axum::http::uri::Scheme::HTTP,
    );
    let router = axum::Router::new().fallback(strangler_svc);
    axum::Server::bind(&"127.0.0.1:0".parse()?)
        .serve(router.into_make_service())
        .await?;
    Ok(())
}

Any sort of feedback is more than welcome. Once I get this through the door at my work, I hope to be able to spend more time adding a lot of extra features that could help others adopt Rust in their professional setting by being reducing the upfront cost needed.

Note: one of the first items on my TODO is replace \reqwest\\ with \hyper::client\\ to reduce the amount of dependencies and tie in better with the axum framework.