Table of Contents

Class ConsumerTransactionManager

Namespace
Silverback.Messaging.Consuming.Transaction
Assembly
Silverback.Integration.dll

Handles the consumer transaction.

public sealed class ConsumerTransactionManager : IConsumerTransactionManager
Inheritance
ConsumerTransactionManager
Implements
Inherited Members

Constructors

ConsumerTransactionManager(ConsumerPipelineContext, ISilverbackLogger<ConsumerTransactionManager>)

Initializes a new instance of the ConsumerTransactionManager class.

public ConsumerTransactionManager(ConsumerPipelineContext context, ISilverbackLogger<ConsumerTransactionManager> logger)

Parameters

context ConsumerPipelineContext

The current ConsumerPipelineContext.

logger ISilverbackLogger<ConsumerTransactionManager>

The ISilverbackLogger.

Properties

Aborted

Gets the AsyncEvent<TArg> that is after the consumer is aborted.

public AsyncEvent<ConsumerPipelineContext> Aborted { get; }

Property Value

AsyncEvent<ConsumerPipelineContext>

Aborting

Gets the AsyncEvent<TArg> that is before the consumer is aborted.

public AsyncEvent<ConsumerPipelineContext> Aborting { get; }

Property Value

AsyncEvent<ConsumerPipelineContext>

Committed

Gets the AsyncEvent<TArg> that is after the consumer is committed.

public AsyncEvent<ConsumerPipelineContext> Committed { get; }

Property Value

AsyncEvent<ConsumerPipelineContext>

Committing

Gets the AsyncEvent<TArg> that is fired before the consumer is committed.

public AsyncEvent<ConsumerPipelineContext> Committing { get; }

Property Value

AsyncEvent<ConsumerPipelineContext>

Remarks

It isn't fired when the consumer is committed by the rollback, without processing the message (see Skipping).

Skipping

Gets the AsyncEvent<TArg> that is fired when the rollback commits the consumer without processing the message, for example when the message is skipped or moved by the error policies or when an incomplete sequence is aborted.

public AsyncEvent<ConsumerPipelineContext> Skipping { get; }

Property Value

AsyncEvent<ConsumerPipelineContext>

Remarks

It's fired right before the consumer is committed (after Aborting and before Aborted) and only if the commit actually happens. The commit is deferred, and the event isn't fired, when other sequences are pending or still being processed, or when the consumer is stopping. Committing and Committed aren't fired in this case.

The transaction failed: the handlers must not rely on the storage transaction enlisted by the subscribers, which is rolled back. An exception thrown by a handler fails the rollback and the consumer isn't committed.

Methods

CommitAsync()

Commits the transaction.

public Task CommitAsync()

Returns

Task

A Task representing the asynchronous operation.

Exceptions

InvalidOperationException

The transaction was already aborted (or is being aborted).

RollbackAsync(Exception?, bool, bool, bool)

Aborts the transaction and causes the uncommitted changes to be rolled back.

public Task<bool> RollbackAsync(Exception? exception, bool commitConsumer = false, bool throwIfAlreadyCommitted = true, bool stopConsuming = true)

Parameters

exception Exception

The exception that caused the rollback.

commitConsumer bool

A value indicating whether the consumer have to be committed anyway. This depends on the error policy being applied.

throwIfAlreadyCommitted bool

A value indicating whether an exception must be thrown if the transaction was already committed.

stopConsuming bool

A value indicating whether the consumer must be stopped.

Returns

Task<bool>

A Task<TResult> representing the asynchronous operation. The task result contains a value indicating whether the rollback was performed.

Exceptions

InvalidOperationException

The transaction was already committed (or is being committed) and throwIfAlreadyCommitted is true.