#Ranvier 첫 서비스 퀵스타트

버전: 0.51.0
최근 업데이트: 2026-09-29
적용 대상: 공개 ranvier facade
카테고리: 시작하기

이 문서는 빈 프로젝트에서 설치, 첫 HTTP 실행, Schematic 확인, 분기와 실패 후의 안전한 입력 수정까지 따라가는 한국어 기준 경로입니다. 코드 예제는 공개 crates.io 패키지 ranvier 0.51.0을 대상으로 컴파일 확인했습니다.

#사전 준비

  • Rust 1.93.0 이상
  • Cargo
rustc --version

#1. facade로 설치하기

새 애플리케이션은 다음 경로로 시작합니다.

cargo new ranvier-quickstart
cd ranvier-quickstart
cargo add ranvier@0.51.0
cargo add tokio@1 --features macros,rt-multi-thread

ranvier-core, ranvier-runtime, ranvier-http를 각각 직접 추가하지 마세요. 이 crate들은 고급 통합에 사용할 수 있지만, 첫 사용자를 위한 설치 계약은 facade 하나입니다.

#2. 공개 facade transition과 네이티브 HTTP ingress 추가

src/main.rs를 다음 코드로 바꿉니다.

use ranvier::prelude::*;
use ranvier::runtime::ClosureTransition;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let hello = Axon::<(), (), String>::new("hello").then(ClosureTransition::new(
        "greet",
        |_input: (), _bus: &mut Bus| Outcome::next("Hello, Ranvier!".to_string()),
    ));

    Ranvier::http()
        .bind("127.0.0.1:3000")
        .route("/", hello)
        .run(())
        .await?;

    Ok(())
}

서비스를 실행합니다.

cargo run --locked

다른 터미널에서 http://127.0.0.1:3000/에 요청합니다.

curl http://127.0.0.1:3000/

응답 본문은 Hello, Ranvier!입니다. 이 예제는 공개 ranvier package facade와 ClosureTransition adapter를 사용합니다. 생성된 Cargo.lock을 보존하면 아래의 --locked 실행에서 테스트한 의존성 해석을 재현할 수 있습니다.

실행 가능한 정본은 `fixtures/quickstart-public/src/main.rs`입니다.

#3. Schematic, 분기, 순수 실패 복구 확인

src/bin/onboarding-flow.rs 파일을 만들고 다음 코드를 넣습니다.

use ranvier::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let flow = Axon::<String, String, String>::new("helpdesk")
        .then_fn("validate", |input: String, _bus: &mut Bus| {
            if input == "invalid" {
                Outcome::Fault("invalid request".to_string())
            } else {
                Outcome::Next(input)
            }
        })
        .then_fn("route", |input: String, _bus: &mut Bus| {
            if input == "billing" {
                Outcome::Branch("billing-review".to_string(), None)
            } else {
                Outcome::Next(input)
            }
        });

    for node in &flow.schematic().nodes {
        println!("schematic_node={}", node.label);
    }

    let mut bus = Bus::new();
    let failed = flow.execute_simple("invalid".to_string(), &mut bus).await;
    println!("first_attempt={failed:?}");

    let mut bus = Bus::new();
    let retried = flow.execute_simple("billing".to_string(), &mut bus).await;
    println!("corrected_attempt={retried:?}");

    Ok(())
}

프로젝트 디렉터리에서 실행합니다.

cargo run --locked --bin onboarding-flow

예상 출력:

schematic_node=helpdesk
schematic_node=validate
schematic_node=route
first_attempt=Fault("invalid request")
corrected_attempt=Branch("billing-review", None)

Branch는 호출자에게 라우팅 결정을 반환하며 목적지를 자동 실행하지 않습니다. 첫 실행은 입력 검증에 실패하고 두 번째 실행은 수정된 입력을 사용합니다. 두 transition이 순수하고 외부 부수 효과가 없기 때문에 이 예제에서는 재실행해도 안전합니다. 임의의 실패한 워크플로를 안전하게 재시도할 수 있다는 뜻은 아닙니다. 실행 소스는 `fixtures/quickstart-public/src/bin/onboarding-flow.rs`에 보존합니다.

state-persistence-demo는 메모리 저장소를 사용하는 예제입니다. 로컬 checkpoint/resume을 설명할 수 있지만 PostgreSQL 내구성, 프로세스 재시작 복구 또는 운영 영속성 계약의 증거는 아닙니다. 해당 검증은 M427-RQ1/RQ4에서 계속 열려 있습니다.

#4. 유지 대상 워크플로 세 가지로 이어가기

다음 학습 경로는 세 가지로 제한합니다.

워크플로 확인할 내용 지원 계약
타입 상태 진행 Axon 단계 간 컴파일 시점 handoff Canonical / Developer gate
타입 JSON 네이티브 HTTP Ranvier ingress를 통한 타입 요청/응답 경계 Supported / Release gate
Bus capability 정책 명시적 리소스 존재와 접근 정책 Supported / Release gate

Ranvier 소스 checkout에서는 다음으로 정확한 워크플로 묶음을 컴파일합니다.

cargo check -p typed-state-tree -p typed-json-api -p bus-capability-demo --locked

세 package는 반복 Developer/Release compile 계약에 포함되며 외부 런타임 서비스가 필요하지 않습니다.

#5. HTTP 경계 선택하기

시작점 선택 이유
의사결정 워크플로가 중심인 신규 서비스 네이티브 Ranvier::http() 하나의 ingress/guard/Outcome 모델과 Schematic-aware routing
일부 복잡한 endpoint를 가진 기존 Axum 서비스 Axum + Ranvier 하이브리드 Axum routing과 Tower middleware는 유지하고 결정 로직만 Axon에 위임

네이티브 방식이 기본 시작 경로이며 하이브리드는 명시적인 통합 선택입니다. 애플리케이션이 상태를 Bus에 연결하지 않으면 Tower/Axum middleware 상태는 Ranvier Schematic에 포함되지 않습니다.

#6. 지원 경계

  • Stable Candidate API는 API 안정성 계약을 따릅니다.
  • Canonical 예제는 Developer gate에서, Supported 예제는 Release gate에서 실행합니다.
  • schema로 설명하는 Branch, Jump, Emit payload와 runtime Bus presence 검사는 컴파일 시점의 타입 보장이 아닙니다.
  • M419가 증거를 공개하기 전까지 macOS와 정기 플랫폼/MSRV matrix는 검증 완료로 주장하지 않습니다.

#7. Experimental과 Lab 경로는 마지막에 보기

퀵스타트와 세 가지 유지 대상 워크플로가 컴파일된 뒤 Examples Explorer에서 Lab 또는 Experimental 통합을 참고하세요. 이 예제들은 유용한 참고 자료지만 정기 Developer/Release 지원 약속에는 포함되지 않습니다.