pub struct TransactionalOutboxLifecycleContext<'a, A, O>where
A: AggregateRoot,
O: TransactionalOutbox<Aggregate = A>,{ /* private fields */ }Expand description
English:
Tracks one save-and-enqueue attempt while exclusively borrowing an aggregate and outbox.
Self::save_and_enqueue pulls pending events and passes ownership to the outbox. An error
does not restore them, and a second attempt in the same context is rejected. The supplied
expected revision is forwarded unchanged. Transactions, durability, and concurrent-writer
coordination remain the responsibility of TransactionalOutbox’s implementation.
Calling Self::complete checks recorded success; it does not commit a transaction.
Dropping this context performs no completion check, rollback, or event restoration.
A helper can propagate an enqueue error and check completion only after success. The assertion below follows from the context recording a successful outbox return.
日本語:
集約とアウトボックスを排他的に借用し、保存・登録の一回の試行を追跡します。
Self::save_and_enqueue は保留イベントを取り出してアウトボックスへ所有権を渡します。
エラー時も復元せず、同じコンテキストでの二回目の試行は拒否します。指定された期待
リビジョンは変更せずに渡します。トランザクション、永続性、並行書き込みの調整は
TransactionalOutbox の実装の責務です。Self::complete は記録された成功を
確認するだけで、コミットは行いません。コンテキストの破棄では完了確認、ロールバック、
イベント復元のいずれも行いません。
ヘルパーでは登録エラーを伝播し、成功後にのみ完了確認できます。 以下のアサーションは、アウトボックスが成功を返したことが記録されるため成立します。
§Example / 使用例
use ddd_toolkit_core::{
AggregateRoot, AppendResult, ExpectedRevision, TransactionalOutbox,
TransactionalOutboxLifecycleContext, TransactionalOutboxOperationError,
};
fn enqueue<A, O>(
aggregate: &mut A,
outbox: &mut O,
expected: ExpectedRevision,
) -> Result<AppendResult, TransactionalOutboxOperationError<O::Error>>
where
A: AggregateRoot,
O: TransactionalOutbox<Aggregate = A>,
{
let mut context = TransactionalOutboxLifecycleContext::new(aggregate, outbox, expected);
let result = context.save_and_enqueue()?;
assert_eq!(context.complete(), Ok(()));
Ok(result)
}Implementations§
Source§impl<'a, A, O> TransactionalOutboxLifecycleContext<'a, A, O>where
A: AggregateRoot,
O: TransactionalOutbox<Aggregate = A>,
impl<'a, A, O> TransactionalOutboxLifecycleContext<'a, A, O>where
A: AggregateRoot,
O: TransactionalOutbox<Aggregate = A>,
Sourcepub fn new(
aggregate: &'a mut A,
outbox: &'a mut O,
expected: ExpectedRevision,
) -> TransactionalOutboxLifecycleContext<'a, A, O>
pub fn new( aggregate: &'a mut A, outbox: &'a mut O, expected: ExpectedRevision, ) -> TransactionalOutboxLifecycleContext<'a, A, O>
English:
Borrows aggregate and outbox with no attempt yet recorded.
Construction neither pulls events nor calls the outbox; expected is saved for the attempt.
日本語:
aggregate と outbox を借用し、未試行の状態で作成します。
構築時にはイベントを取り出さず、アウトボックスも呼び出しません。expected は試行用に保持します。
Sourcepub fn save_and_enqueue(
&mut self,
) -> Result<AppendResult, TransactionalOutboxOperationError<<O as TransactionalOutbox>::Error>>
pub fn save_and_enqueue( &mut self, ) -> Result<AppendResult, TransactionalOutboxOperationError<<O as TransactionalOutbox>::Error>>
English:
Pulls events once and calls the outbox with the aggregate, revision, and batch.
Returns the outbox’s AppendResult or wraps its AppendError without changing it.
Even an empty batch is passed to the outbox for validation. Once an attempt starts,
later calls return TransactionalOutboxOperationError::AlreadyEnqueued, including
after failure. Pulled events are not recorded back into the aggregate on any error.
Panics from AggregateRoot::pull_events or the outbox propagate; the context marks
the attempt as unsuccessful before either call and provides no panic recovery.
日本語:
イベントを一回取り出し、集約、リビジョン、バッチをアウトボックスへ渡します。
アウトボックスの AppendResult を返すか、AppendError を変更せずに包んで返します。
空バッチも検証のためにアウトボックスへ渡します。一度試行を開始すると、失敗後も含め、
後続の呼び出しは TransactionalOutboxOperationError::AlreadyEnqueued を返します。
いずれのエラーでも取り出したイベントは集約へ記録し直しません。
AggregateRoot::pull_events やアウトボックスのパニックは伝播します。両呼び出しの前に
試行を未成功として記録しますが、パニックからの回復処理は提供しません。
Sourcepub fn complete(self) -> Result<(), TransactionalOutboxCompletionError>
pub fn complete(self) -> Result<(), TransactionalOutboxCompletionError>
English:
Consumes the context and reports whether its enqueue attempt succeeded.
Returns Ok(()) after success, TransactionalOutboxCompletionError::MissingEnqueue
before any attempt, or TransactionalOutboxCompletionError::EnqueueFailedConsumed
after an attempt without recorded success. No storage call or retry is performed;
rejecting a second enqueue does not erase a previously recorded success.
日本語:
コンテキストを消費し、登録の試行が成功したかを報告します。
成功後は Ok(())、未試行なら TransactionalOutboxCompletionError::MissingEnqueue、
成功が記録されていない試行の後なら
TransactionalOutboxCompletionError::EnqueueFailedConsumed を返します。
ストレージの呼び出しや再試行は行いません。二回目の登録を拒否しても、記録済みの成功は消しません。