튜토리얼

첫 Ranvier 회로를 만들어 봅시다.

이 튜토리얼은 facade crate(전면 크레이트)로 최소 HTTP ingress 회로를 만든 뒤, 더 깊은 워크플로를 위해 canonical examples로 안내합니다.

1. 의존성 설치

cargo add ranvier
cargo add tokio --features full
cargo add anyhow
cargo add async-trait

2. Transition 정의

use async_trait::async_trait;
use ranvier::prelude::*;

#[derive(Clone)]
struct Hello;

#[async_trait]
impl Transition<(), String> for Hello {
    type Error = anyhow::Error;
    type Resources = ();

    async fn run(
        &self,
        _state: (),
        _resources: &Self::Resources,
        _bus: &mut Bus,
    ) -> Outcome<String, Self::Error> {
        Outcome::Next("Hello, Ranvier!".to_string())
    }
}

3. Ingress Builder 연결

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let hello = Axon::<(), (), anyhow::Error>::new("Hello")
        .then(Hello);

    Ranvier::http()
        .bind("127.0.0.1:3000")
        .route("/", hello)
        .run(())
        .await
        .map_err(|e| anyhow::anyhow("{}", e))?;

    Ok(())
}
cargo run으로 실행한 뒤 http://127.0.0.1:3000에 접속하세요.

4. 리소스 연결 이해하기

DB 풀, 트레이서, 설정 등 공유 리소스는 명시적으로 연결됩니다. Ingress에서 리소스를 주입하거나 Bus에서 필요한 시점에 읽습니다.

5. Canonical Examples 실행 (Repository)

Hello World (HTTP)

cargo run -p hello-world

Typed State Tree

cargo run -p typed-state-tree

Schematic Baseline

cargo run -p basic-schematic

Canonical 예제 목록은 저장소에서 확인할 수 있습니다: ranvier/examples

6. Schematic 내보내기

ranvier schematic basic-schematic --output schematic.json

7. Trace Projection 생성

ranvier status projection-from-example order-processing-demo \
  --output ./dist/trace-order \
  --service "Ranvier Service" \
  --circuit-id order_processing \
  --circuit-version 0.1.0