using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.CollectBus.Kafka.Attributes
{
[AttributeUsage(AttributeTargets.Method)]
public class KafkaSubscribeAttribute : Attribute
{
///
/// 订阅的主题
///
public string Topic { get; set; }
///
/// 分区
///
public int Partition { get; set; } = -1;
///
/// 消费者组
///
public string GroupId { get; set; }
///
/// 任务数(默认是多少个分区多少个任务)
/// 如设置订阅指定Partition则任务数始终为1
///
public int TaskCount { get; set; } = -1;
///
/// 批量处理数量
///
public int BatchSize { get; set; } = 100;
///
/// 是否启用批量处理
///
public bool EnableBatch { get; set; } = false;
///
/// 批次超时时间
///
public TimeSpan? BatchTimeout { get; set; }=null;
///
/// 订阅主题
///
/// batchTimeout格式:("00:05:00")
public KafkaSubscribeAttribute(string topic, string groupId = "default", bool enableBatch = false, int batchSize = 100, string? batchTimeout = null)
{
this.Topic = topic;
this.GroupId = groupId;
this.EnableBatch = enableBatch;
this.BatchSize = batchSize;
this.BatchTimeout = batchTimeout != null? TimeSpan.Parse(batchTimeout): null;
}
///
/// 订阅主题
///
/// batchTimeout格式:("00:05:00")
public KafkaSubscribeAttribute(string topic, int partition, string groupId = "default", bool enableBatch = false, int batchSize = 100, string? batchTimeout = null)
{
this.Topic = topic;
this.Partition = partition;
this.GroupId = groupId;
this.TaskCount = 1;
this.EnableBatch = enableBatch;
this.BatchSize = batchSize;
this.BatchTimeout = batchTimeout != null ? TimeSpan.Parse(batchTimeout) : null;
}
}
}