Page History
...
가장 최근의 스냅샷부터 시작 → 남은 이벤트만 재생
✅ 핵심 특징 요약
| 기능 | 설명 |
|---|---|
| 🎯 명령-이벤트 분리 | Sale은 명령(Command), Persist된 이벤트로 상태 변경 |
| 🧠 이벤트 소싱 기반 상태 | 상태 변경 내역은 전부 이벤트로 기록되어 리플레이 가능 |
| 💾 스냅샷 | 매 5건 이벤트마다 현재 상태 저장으로 복구 최적화 |
| 🔄 복구 내장 | 스냅샷 → 이벤트 순으로 복원함 |
| 🚦 목표 달성시 종료 | 외부 TaskCompletionSource로 흐름 제어 |
NetCoreLabs 샘플코드
유닛테스트를 통한 시뮬레이터
| Code Block | ||
|---|---|---|
| ||
public class SalesSimulatorActor : ReceiveActor
{
private readonly IActorRef _salesActor;
private ICancelable scheduler;
public SalesSimulatorActor(IActorRef salesActor)
{
_salesActor = salesActor;
// Schedule the first sale simulation immediately and then every 2 seconds:
scheduler = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(TimeSpan.Zero,
TimeSpan.FromSeconds(2), Self, new StartSimulate(), Self);
Receive<StartSimulate>(HandleStart);
Receive<StopSimulate>(HandleStop);
}
private void HandleStart(StartSimulate message)
{
ConsoleHelper.WriteToConsole(ConsoleColor.Black,
$"About to simulate a sale...");
Random random = new Random();
string[] products = { "Apple", "Google", "Nokia", "Xiaomi", "Huawei" };
var randomBrand = products[random.Next(products.Length)];
var randomPrice = random.Next(1, 6) * 100; // 100, 200, 300, 400, or 500
var nextSale = new Sale(randomPrice, randomBrand);
_salesActor.Tell(nextSale);
}
private void HandleStop(StopSimulate message)
{
scheduler.Cancel();
ConsoleHelper.WriteToConsole(ConsoleColor.DarkRed,
"Simulation stopped");
}
} |
- Raven에 제공하는 가이드를 유닛테스트로 옮겨두었으며 여기서 설명된 SaleActor 이벤트소싱버전을 로컬에서 수행해볼수 있습니다.
이벤트 스토어 확인
여기서 설명되는 내용은 준비된 이벤트 소싱치를
이벤트 소싱은 저널과 스냅샷이 함께 이용되며 CRUD에서 관리되는 데이터대비 비대해질수도 있습니다.
CRUD처럼 마지막 상태데이터를 CQRS방식으로 이용하려면 DurableState Persist를 이용할수도 있습니다.
DurableState는 이벤트 발생시 변화되는 객체의 마지막 상태를 저장하는것을 의미하며
상태로 설계된 객체가 복원을 위해 이용될수 있으며 CRUD랑 유사하게 작동하며
Journal은 발생 이벤트를 모두 기록해 이벤트 소싱과 같이 시계열이 필요하고 이벤트 재생이 필요한곳에 이용될수 있습니다.
SnapShot은 Journal과 함께 이용되어 이벤트소스로부터 너무 많은 재생이 일어나지않게 방지를 하는 장치입니다.
샘플코드
이상 RavenDB을 Akka.net과 함께 이용해 이벤트 소싱을 구현하는 샘플을 간략하게 살펴보았으며
여기서 설명된 내용은 Akka.net기반 액터모델을 중심으로한 다양한 샘플기능들을 살펴볼수 여기서 실험된 작동기능은 다음 저장소에서 실행및 수행가능하며 Akka.net 기반의 액터모델을 중심으로한 다양한 기능들을 확인할수 있습니다.
...

