도메인 이벤트로 채워진 비정규화된 읽기 모델로 RavenDB를 사용하고 있습니다. 두 이벤트 (Created 및 Updated)를 동시에 비정규 화하는 문제가 발생했습니다. Created 이벤트로 변경 한 내용을 저장하기 전에 Updated 이벤트로 업데이트 할 문서가로드됩니다. 나는 문서 작성을 기다릴 변경 API를 기반으로 솔루션을 내놓았다했습니다RavenDB - 문서 작성을 기다립니다.
public static T WaitAndLoad<T>(this IDocumentSession @this, ValueType id)
where T : class
{
var fullId = @this.Advanced.DocumentStore.Conventions.FindFullDocumentKeyFromNonStringIdentifier(id, typeof(T), false);
var ev = new ManualResetEvent(false);
var cancelation = new CancellationTokenSource();
@this.Advanced.DocumentStore
.Changes()
.ForDocument(fullId)
.Subscribe(change =>
{
if (change.Type == DocumentChangeTypes.Put)
{
ev.Set();
}
}, cancelation.Token);
try
{
var existing = @this.Load<T>(id);
if (existing != null)
{
return existing;
}
ev.WaitOne();
return @this.Load<T>(id);
}
finally
{
cancelation.Cancel();
}
}
불행하게도 두 번째 문서의 이드 InMemoryDocumentSessionOperations에 knownMissingIds 필드에 이미 서버에는 요청이 없기 때문에 null이 반환을로드하기 위해 호출합니다.
문서가 작성 될 때까지 기다리는 다른 방법이 있습니까?