-
Notifications
You must be signed in to change notification settings - Fork 38
/
RabbitConsumerEndpoint.cs
83 lines (67 loc) · 2.74 KB
/
RabbitConsumerEndpoint.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2020 Sergio Aquilini
// This code is licensed under MIT license (see LICENSE file for details)
using Silverback.Messaging.Configuration.Rabbit;
namespace Silverback.Messaging
{
/// <summary>
/// Represents a queue or exchange to consume from.
/// </summary>
public abstract class RabbitConsumerEndpoint : ConsumerEndpoint
{
/// <summary>
/// Initializes a new instance of the <see cref="RabbitConsumerEndpoint" /> class.
/// </summary>
/// <param name="name">
/// The name of the queue or exchange.
/// </param>
protected RabbitConsumerEndpoint(string name)
: base(name)
{
}
/// <summary>
/// Gets or sets the RabbitMQ connection settings.
/// </summary>
public RabbitConnectionConfig Connection { get; set; } = new();
/// <summary>
/// Gets or sets the queue configuration.
/// </summary>
public RabbitQueueConfig Queue { get; set; } = new();
/// <summary>
/// Gets or sets the number of message to be processed before sending the acknowledgment to the server.
/// The most reliable level is 1 but it reduces throughput.
/// </summary>
public int AcknowledgeEach { get; set; } = 1;
/// <summary>
/// Gets or sets the QoS prefetch size parameter for the consumer.
/// </summary>
public uint PrefetchSize { get; set; }
/// <summary>
/// Gets or sets the QoS prefetch count parameter for the consumer.
/// </summary>
public ushort PrefetchCount { get; set; }
/// <inheritdoc cref="Endpoint.Validate" />
public override void Validate()
{
base.Validate();
if (Connection == null)
throw new EndpointConfigurationException("Connection cannot be null");
Connection.Validate();
if (Queue == null)
throw new EndpointConfigurationException("Queue cannot be null");
Queue.Validate();
if (AcknowledgeEach < 1)
throw new EndpointConfigurationException("AcknowledgeEach cannot be less than 1");
}
/// <inheritdoc cref="Endpoint.BaseEquals" />
protected override bool BaseEquals(Endpoint? other)
{
if (ReferenceEquals(this, other))
return true;
if (other is not RabbitConsumerEndpoint otherRabbitConsumerEndpoint)
return false;
return base.BaseEquals(other) &&
Equals(Connection, otherRabbitConsumerEndpoint.Connection) &&
Equals(Queue, otherRabbitConsumerEndpoint.Queue);
}
}
}