Table of Contents

Class CommandPublisherExtensions

Namespace
Silverback.Messaging.Publishing
Assembly
Silverback.Core.Model.dll
public static class CommandPublisherExtensions
Inheritance
CommandPublisherExtensions
Inherited Members

Methods

ExecuteCommand(IPublisher, ICommand, bool)

Executes the specified command forwarding it to its subscribers via the message bus and the method will not complete until all subscribers have processed it (unless using Silverback.Integration to produce and consume the message through a message broker).

public static void ExecuteCommand(this IPublisher publisher, ICommand commandMessage, bool throwIfUnhandled = true)

Parameters

publisher IPublisher

The IPublisher.

commandMessage ICommand

The command to be executed.

throwIfUnhandled bool

A boolean value indicating whether an exception must be thrown if no subscriber is handling the message.

Exceptions

UnhandledMessageException

throwIfUnhandled is true and no subscriber handled the command.

SubscribedMethodInvocationException

A subscribed method has an invalid signature, for example no argument resolver can be found for one of its parameters.

ExecuteCommandAsync(IPublisher, ICommand, bool, CancellationToken)

Executes the specified command forwarding it to its subscribers via the message bus and the method will not complete until all subscribers have processed it (unless using Silverback.Integration to produce and consume the message through a message broker).

public static Task ExecuteCommandAsync(this IPublisher publisher, ICommand commandMessage, bool throwIfUnhandled, CancellationToken cancellationToken = default)

Parameters

publisher IPublisher

The IPublisher.

commandMessage ICommand

The command to be executed.

throwIfUnhandled bool

A boolean value indicating whether an exception must be thrown if no subscriber is handling the message.

cancellationToken CancellationToken

The CancellationToken that can be used to cancel the operation.

Returns

Task

A Task representing the asynchronous operation.

Exceptions

UnhandledMessageException

throwIfUnhandled is true and no subscriber handled the command.

SubscribedMethodInvocationException

A subscribed method has an invalid signature, for example no argument resolver can be found for one of its parameters.

ExecuteCommandAsync(IPublisher, ICommand, CancellationToken)

Executes the specified command forwarding it to its subscribers via the message bus and the method will not complete until all subscribers have processed it (unless using Silverback.Integration to produce and consume the message through a message broker).

public static Task ExecuteCommandAsync(this IPublisher publisher, ICommand commandMessage, CancellationToken cancellationToken = default)

Parameters

publisher IPublisher

The IPublisher.

commandMessage ICommand

The command to be executed.

cancellationToken CancellationToken

The CancellationToken that can be used to cancel the operation.

Returns

Task

A Task representing the asynchronous operation.

Exceptions

UnhandledMessageException

No subscriber handled the command.

SubscribedMethodInvocationException

A subscribed method has an invalid signature, for example no argument resolver can be found for one of its parameters.

ExecuteCommandAsync<TResult>(IPublisher, ICommand<TResult>, bool, CancellationToken)

Executes the specified command forwarding it to its subscribers via the message bus and the method will not complete until all subscribers have processed it (unless using Silverback.Integration to produce and consume the message through a message broker).

public static Task<TResult> ExecuteCommandAsync<TResult>(this IPublisher publisher, ICommand<TResult> commandMessage, bool throwIfUnhandled, CancellationToken cancellationToken = default)

Parameters

publisher IPublisher

The IPublisher.

commandMessage ICommand<TResult>

The command to be executed.

throwIfUnhandled bool

A boolean value indicating whether an exception must be thrown if no subscriber is handling the message.

cancellationToken CancellationToken

The CancellationToken that can be used to cancel the operation.

Returns

Task<TResult>

A Task<TResult> representing the asynchronous operation. The Task result contains the command result.

Type Parameters

TResult

The type of the result that is expected to be returned by the subscribers.

Exceptions

UnhandledMessageException

throwIfUnhandled is true and no subscriber handled the command.

SubscribedMethodInvocationException

A subscribed method has an invalid signature, for example no argument resolver can be found for one of its parameters.

InvalidOperationException

The command wasn't handled by exactly one subscriber returning a result.

ExecuteCommandAsync<TResult>(IPublisher, ICommand<TResult>, CancellationToken)

Executes the specified command forwarding it to its subscribers via the message bus and the method will not complete until all subscribers have processed it (unless using Silverback.Integration to produce and consume the message through a message broker).

public static Task<TResult> ExecuteCommandAsync<TResult>(this IPublisher publisher, ICommand<TResult> commandMessage, CancellationToken cancellationToken = default)

Parameters

publisher IPublisher

The IPublisher.

commandMessage ICommand<TResult>

The command to be executed.

cancellationToken CancellationToken

The CancellationToken that can be used to cancel the operation.

Returns

Task<TResult>

A Task<TResult> representing the asynchronous operation. The Task result contains the command result.

Type Parameters

TResult

The type of the result that is expected to be returned by the subscribers.

Exceptions

UnhandledMessageException

No subscriber handled the command.

SubscribedMethodInvocationException

A subscribed method has an invalid signature, for example no argument resolver can be found for one of its parameters.

InvalidOperationException

The command wasn't handled by exactly one subscriber returning a result.

ExecuteCommand<TResult>(IPublisher, ICommand<TResult>, bool)

Executes the specified command forwarding it to its subscribers via the message bus and the method will not complete until all subscribers have processed it (unless using Silverback.Integration to produce and consume the message through a message broker).

public static TResult ExecuteCommand<TResult>(this IPublisher publisher, ICommand<TResult> commandMessage, bool throwIfUnhandled = true)

Parameters

publisher IPublisher

The IPublisher.

commandMessage ICommand<TResult>

The command to be executed.

throwIfUnhandled bool

A boolean value indicating whether an exception must be thrown if no subscriber is handling the message.

Returns

TResult

The command result.

Type Parameters

TResult

The type of the result that is expected to be returned by the subscribers.

Exceptions

UnhandledMessageException

throwIfUnhandled is true and no subscriber handled the command.

SubscribedMethodInvocationException

A subscribed method has an invalid signature, for example no argument resolver can be found for one of its parameters.

InvalidOperationException

The command wasn't handled by exactly one subscriber returning a result.