45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Svrnty.CQRS.Sagas.Abstractions.Messaging;
|
|
|
|
/// <summary>
|
|
/// Abstraction for saga messaging transport.
|
|
/// </summary>
|
|
public interface ISagaMessageBus
|
|
{
|
|
/// <summary>
|
|
/// Publishes a saga command message to the message bus.
|
|
/// </summary>
|
|
/// <param name="message">The message to publish.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
Task PublishAsync(SagaMessage message, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Publishes a saga step response to the message bus.
|
|
/// </summary>
|
|
/// <param name="response">The response to publish.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
Task PublishResponseAsync(SagaStepResponse response, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Subscribes to saga messages for a specific command type.
|
|
/// </summary>
|
|
/// <typeparam name="TCommand">The command type to subscribe to.</typeparam>
|
|
/// <param name="handler">Handler that processes the message and returns a response.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
Task SubscribeAsync<TCommand>(
|
|
Func<SagaMessage, TCommand, CancellationToken, Task<SagaStepResponse>> handler,
|
|
CancellationToken cancellationToken = default) where TCommand : class;
|
|
|
|
/// <summary>
|
|
/// Subscribes to saga step responses.
|
|
/// </summary>
|
|
/// <param name="handler">Handler that processes responses.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
Task SubscribeToResponsesAsync(
|
|
Func<SagaStepResponse, CancellationToken, Task> handler,
|
|
CancellationToken cancellationToken = default);
|
|
}
|