Class CommandPublisherExtensions
- Namespace
- Silverback.Messaging.Publishing
- Assembly
- Silverback.Core.Model.dll
Adds the ExecuteCommand(IPublisher, ICommand, bool) and ExecuteCommandAsync(IPublisher, ICommand, CancellationToken) methods to the IPublisher interface.
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
publisherIPublisherThe IPublisher.
commandMessageICommandThe command to be executed.
throwIfUnhandledboolA boolean value indicating whether an exception must be thrown if no subscriber is handling the message.
Exceptions
- UnhandledMessageException
throwIfUnhandledistrueand 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
publisherIPublisherThe IPublisher.
commandMessageICommandThe command to be executed.
throwIfUnhandledboolA boolean value indicating whether an exception must be thrown if no subscriber is handling the message.
cancellationTokenCancellationTokenThe CancellationToken that can be used to cancel the operation.
Returns
Exceptions
- UnhandledMessageException
throwIfUnhandledistrueand 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
publisherIPublisherThe IPublisher.
commandMessageICommandThe command to be executed.
cancellationTokenCancellationTokenThe CancellationToken that can be used to cancel the operation.
Returns
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
publisherIPublisherThe IPublisher.
commandMessageICommand<TResult>The command to be executed.
throwIfUnhandledboolA boolean value indicating whether an exception must be thrown if no subscriber is handling the message.
cancellationTokenCancellationTokenThe 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
TResultThe type of the result that is expected to be returned by the subscribers.
Exceptions
- UnhandledMessageException
throwIfUnhandledistrueand 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
publisherIPublisherThe IPublisher.
commandMessageICommand<TResult>The command to be executed.
cancellationTokenCancellationTokenThe 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
TResultThe 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
publisherIPublisherThe IPublisher.
commandMessageICommand<TResult>The command to be executed.
throwIfUnhandledboolA boolean value indicating whether an exception must be thrown if no subscriber is handling the message.
Returns
- TResult
The command result.
Type Parameters
TResultThe type of the result that is expected to be returned by the subscribers.
Exceptions
- UnhandledMessageException
throwIfUnhandledistrueand 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.