|
- using Confluent.Kafka.Admin;
- using Microsoft.AspNetCore.Mvc;
- using TelpoKafkaConsole.Service;
- using TelpoKafkaConsole.WebApi.Controllers.Api;
- using TelpoKafkaConsole.WebApi.Model.Request;
-
- // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
-
- namespace TelpoKafkaConsole.WebApi.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class TopicController : ControllerBase
- {
- private readonly KafkaAdminService _servicekafkaAdmin;
-
- public TopicController(KafkaAdminService kafkaAdminService) { _servicekafkaAdmin = kafkaAdminService; }
-
- [HttpGet("{topic}")]
- public async Task<ApiResponse<List<TopicDescription>>> Get(string topic)
- {
- var topicInfo = await _servicekafkaAdmin.DescribeTopicsAsync(new List<string>() { topic });
- return ApiResponse<List<TopicDescription>>.Success(topicInfo);
- }
-
- [HttpPost]
- public async Task<ApiResponse<string>> Post([FromBody] TopicReq topic)
- {
- await _servicekafkaAdmin.CreateTopic(topic.TopicName,TimeSpan.FromDays(3), topic.NumPartitions);
- return ApiResponse<string>.Success($"创建 Topic {topic} 成功");
- }
-
- [HttpDelete("{topic}")]
- public async Task<ApiResponse<string>> Delete(string topic)
- {
- await _servicekafkaAdmin.DeleteTopics(new List<string>() {topic});
- return ApiResponse<string>.Success($"删除 Topic {topic} 成功");
- }
- }
- }
|