2025-04-15 11:15:22 +08:00
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 订阅的主题
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string[] Topics { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 分区
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int Partition { get; set; } = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 消费者组
|
|
|
|
|
|
/// </summary>
|
2025-04-15 15:49:22 +08:00
|
|
|
|
public string GroupId { get; set; }
|
2025-04-15 11:15:22 +08:00
|
|
|
|
|
2025-04-15 15:49:22 +08:00
|
|
|
|
public KafkaSubscribeAttribute(string[] topics, string groupId = "default")
|
2025-04-15 11:15:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.Topics = topics;
|
2025-04-15 15:49:22 +08:00
|
|
|
|
this.GroupId = groupId;
|
2025-04-15 11:15:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-15 15:49:22 +08:00
|
|
|
|
public KafkaSubscribeAttribute(string topic, string groupId = "default")
|
2025-04-15 11:15:22 +08:00
|
|
|
|
{
|
2025-04-15 15:49:22 +08:00
|
|
|
|
this.Topics = new string[] { topic };
|
2025-04-15 11:15:22 +08:00
|
|
|
|
this.GroupId = groupId;
|
|
|
|
|
|
}
|
2025-04-15 15:49:22 +08:00
|
|
|
|
public KafkaSubscribeAttribute(string[] topics, int partition, string groupId = "default")
|
2025-04-15 11:15:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.Topics = topics;
|
|
|
|
|
|
this.Partition = partition;
|
2025-04-15 15:49:22 +08:00
|
|
|
|
this.GroupId = groupId;
|
2025-04-15 11:15:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-15 15:49:22 +08:00
|
|
|
|
|
|
|
|
|
|
public KafkaSubscribeAttribute(string topic, int partition, string groupId = "default")
|
2025-04-15 11:15:22 +08:00
|
|
|
|
{
|
2025-04-15 15:49:22 +08:00
|
|
|
|
this.Topics = new string[] { topic };
|
2025-04-15 11:15:22 +08:00
|
|
|
|
this.Partition = partition;
|
|
|
|
|
|
this.GroupId = groupId;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|