-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathKafkaQueueConfiguration.cs
More file actions
68 lines (59 loc) · 2.58 KB
/
KafkaQueueConfiguration.cs
File metadata and controls
68 lines (59 loc) · 2.58 KB
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
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Confluent.Kafka;
using ViennaNET.Messaging.Configuration;
namespace ViennaNET.Messaging.KafkaQueue
{
/// <summary>
/// Настройки очереди
/// </summary>
public class KafkaQueueConfiguration : QueueConfigurationBase, IValidatableObject
{
/// <summary>
/// Определяет, является ли адаптер потребителем (True) либо отправителем (False)
/// </summary>
[JsonIgnore]
public bool IsConsumer => ConsumerConfig is not null;
/// <summary>
/// Имя очереди/топика
/// </summary>
[Required]
public string QueueName { get; set; }
/// <summary>
/// Признак работы в транзакции
/// </summary>
public bool TransactionEnabled { get; set; }
/// <summary>
/// Полная нативная конфигурация для подписчика Kafka
/// </summary>
public ConsumerConfig? ConsumerConfig { get; set; }
/// <summary>
/// Полная нативная конфигурация для издателя Kafka
/// </summary>
public ProducerConfig? ProducerConfig { get; set; }
/// <summary>
/// Таймаут в мс метода включения транзакций (InitTransactions)
/// </summary>
[Range(1, 3_600_000)]
public int InitTransactionsTimeout { get; set; } = 1000;
/// <inheritdoc />
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (ProcessingType != MessageProcessingType.ThreadStrategy)
{
yield return new ValidationResult("Only ThreadStrategy is supported",
new[] { nameof(ProcessingType) });
}
if (ConsumerConfig is not null && ProducerConfig is not null)
{
yield return new ValidationResult("Only one of ConsumerConfig and ProducerConfig can be set",
new[] { nameof(ConsumerConfig), nameof(ProducerConfig) });
}
if (ConsumerConfig is null && ProducerConfig is null)
{
yield return new ValidationResult("ConsumerConfig or ProducerConfig must be set",
new[] { nameof(ConsumerConfig), nameof(ProducerConfig) });
}
}
}
}