/
BatchSequence.cs
48 lines (44 loc) · 1.94 KB
/
BatchSequence.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
// Copyright (c) 2020 Sergio Aquilini
// This code is licensed under MIT license (see LICENSE file for details)
using System;
using System.Threading.Tasks;
using Silverback.Messaging.Broker.Behaviors;
using Silverback.Util;
namespace Silverback.Messaging.Sequences.Batch
{
/// <summary>
/// Represent an arbitrary sequence of messages created to consume unrelated messages in batch (see
/// <see cref="BatchSettings" />).
/// </summary>
public class BatchSequence : Sequence
{
/// <summary>
/// Initializes a new instance of the <see cref="BatchSequence" /> class.
/// </summary>
/// <param name="sequenceId">
/// The identifier that is used to match the consumed messages with their belonging sequence.
/// </param>
/// <param name="context">
/// The current <see cref="ConsumerPipelineContext" />, assuming that it will be the one from which the
/// sequence gets published to the internal bus.
/// </param>
public BatchSequence(string sequenceId, ConsumerPipelineContext context)
: base(
sequenceId,
context,
Check.NotNull(context, nameof(context)).Envelope.Endpoint.Batch?.MaxWaitTime != null,
Check.NotNull(context, nameof(context)).Envelope.Endpoint.Batch?.MaxWaitTime)
{
if (context.Envelope.Endpoint.Batch == null)
throw new InvalidOperationException("Endpoint.Batch is null.");
TotalLength = context.Envelope.Endpoint.Batch.Size;
}
/// <summary>
/// Called when the timout is elapsed. In this special case the sequence is completed instead of aborted.
/// </summary>
/// <returns>
/// A <see cref="Task" /> representing the asynchronous operation.
/// </returns>
protected override Task OnTimeoutElapsedAsync() => CompleteAsync();
}
}