Table of Contents

Interface IPublisher

Namespace
Silverback.Messaging.Publishing
Assembly
Silverback.Core.dll

Publishes messages via the message bus, forwarding them to the subscribers.

public interface IPublisher

Remarks

When a message is routed to a message broker endpoint, the exceptions thrown while producing it (see IProducer in Silverback.Integration) propagate to the caller as well.

Properties

Context

Gets the ISilverbackContext in the current scope.

ISilverbackContext Context { get; }

Property Value

ISilverbackContext

Methods

Publish(object, bool)

Publishes the specified message 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).

void Publish(object message, bool throwIfUnhandled = false)

Parameters

message object

The message to be published.

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 message.

SubscribedMethodInvocationException

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

PublishAsync(object, bool, CancellationToken)

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

Task PublishAsync(object message, bool throwIfUnhandled, CancellationToken cancellationToken = default)

Parameters

message object

The message to be published.

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 message.

SubscribedMethodInvocationException

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

PublishAsync(object, CancellationToken)

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

Task PublishAsync(object message, CancellationToken cancellationToken = default)

Parameters

message object

The message to be published.

cancellationToken CancellationToken

The CancellationToken that can be used to cancel the operation.

Returns

Task

A Task representing the asynchronous operation.

Exceptions

SubscribedMethodInvocationException

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

PublishAsync<TResult>(object, bool, CancellationToken)

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

Task<IReadOnlyCollection<TResult>> PublishAsync<TResult>(object message, bool throwIfUnhandled, CancellationToken cancellationToken = default)

Parameters

message object

The message to be published.

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<IReadOnlyCollection<TResult>>

A Task<TResult> representing the asynchronous operation. The task result contains a collection of TResult, since multiple subscribers could handle the message and return a value.

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 message.

SubscribedMethodInvocationException

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

PublishAsync<TResult>(object, CancellationToken)

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

Task<IReadOnlyCollection<TResult>> PublishAsync<TResult>(object message, CancellationToken cancellationToken = default)

Parameters

message object

The message to be published.

cancellationToken CancellationToken

The CancellationToken that can be used to cancel the operation.

Returns

Task<IReadOnlyCollection<TResult>>

A Task<TResult> representing the asynchronous operation. The task result contains a collection of TResult, since multiple subscribers could handle the message and return a value.

Type Parameters

TResult

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

Exceptions

SubscribedMethodInvocationException

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

Publish<TResult>(object, bool)

Publishes the specified message 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).

IReadOnlyCollection<TResult> Publish<TResult>(object message, bool throwIfUnhandled = false)

Parameters

message object

The message to be published.

throwIfUnhandled bool

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

Returns

IReadOnlyCollection<TResult>

A collection of TResult, since multiple subscribers could handle the message and return a value.

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 message.

SubscribedMethodInvocationException

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