-
Notifications
You must be signed in to change notification settings - Fork 36
/
TransactionalOutboxBroker.cs
61 lines (56 loc) · 2.54 KB
/
TransactionalOutboxBroker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2020 Sergio Aquilini
// This code is licensed under MIT license (see LICENSE file for details)
using System;
using Microsoft.Extensions.DependencyInjection;
using Silverback.Diagnostics;
using Silverback.Messaging.Broker;
using Silverback.Messaging.Broker.Behaviors;
using Silverback.Messaging.Outbound.Routing;
using Silverback.Messaging.Outbound.TransactionalOutbox.Repositories;
namespace Silverback.Messaging.Outbound.TransactionalOutbox
{
/// <summary>
/// An <see cref="IBroker" /> implementation that is used by the <see cref="OutboxProduceStrategy" /> to
/// write into the outbox.
/// </summary>
public class TransactionalOutboxBroker : Broker<IProducerEndpoint, IConsumerEndpoint>
{
private readonly IOutboxWriter _queueWriter;
/// <summary>
/// Initializes a new instance of the <see cref="TransactionalOutboxBroker" /> class.
/// </summary>
/// <param name="queueWriter">
/// The <see cref="IOutboxWriter" /> to be used to write to the queue.
/// </param>
/// <param name="serviceProvider">
/// The <see cref="IServiceProvider" /> to be used to resolve the required services.
/// </param>
public TransactionalOutboxBroker(
IOutboxWriter queueWriter,
IServiceProvider serviceProvider)
: base(serviceProvider)
{
_queueWriter = queueWriter;
}
/// <inheritdoc cref="Broker{TProducerEndpoint,TConsumerEndpoint}.InstantiateProducer" />
protected override IProducer InstantiateProducer(
IProducerEndpoint endpoint,
IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider,
IServiceProvider serviceProvider) =>
new OutboundQueueProducer(
_queueWriter,
this,
endpoint,
behaviorsProvider,
serviceProvider,
serviceProvider.GetRequiredService<IOutboundLogger<OutboundQueueProducer>>());
/// <inheritdoc cref="Broker{TProducerEndpoint,TConsumerEndpoint}.InstantiateConsumer" />
protected override IConsumer InstantiateConsumer(
IConsumerEndpoint endpoint,
IBrokerBehaviorsProvider<IConsumerBehavior> behaviorsProvider,
IServiceProvider serviceProvider) =>
throw new InvalidOperationException(
"This IBroker implementation is used to write to outbound queue. " +
"Only the producers are therefore supported.");
}
}