Skip to main content

TransactionalOutboxLifecycleContext

Struct TransactionalOutboxLifecycleContext 

Source
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>,

Source

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 は試行用に保持します。

Source

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 やアウトボックスのパニックは伝播します。両呼び出しの前に 試行を未成功として記録しますが、パニックからの回復処理は提供しません。

Source

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 を返します。 ストレージの呼び出しや再試行は行いません。二回目の登録を拒否しても、記録済みの成功は消しません。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.