Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TopicController.cs 1.5KB

il y a 5 mois
12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Confluent.Kafka.Admin;
  2. using Microsoft.AspNetCore.Mvc;
  3. using TelpoKafkaConsole.Service;
  4. using TelpoKafkaConsole.WebApi.Controllers.Api;
  5. using TelpoKafkaConsole.WebApi.Model.Request;
  6. // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  7. namespace TelpoKafkaConsole.WebApi.Controllers
  8. {
  9. [Route("api/[controller]")]
  10. [ApiController]
  11. public class TopicController : ControllerBase
  12. {
  13. private readonly KafkaAdminService _servicekafkaAdmin;
  14. public TopicController(KafkaAdminService kafkaAdminService) { _servicekafkaAdmin = kafkaAdminService; }
  15. [HttpGet("{topic}")]
  16. public async Task<ApiResponse<List<TopicDescription>>> Get(string topic)
  17. {
  18. var topicInfo = await _servicekafkaAdmin.DescribeTopicsAsync(new List<string>() { topic });
  19. return ApiResponse<List<TopicDescription>>.Success(topicInfo);
  20. }
  21. [HttpPost]
  22. public async Task<ApiResponse<string>> Post([FromBody] TopicReq topic)
  23. {
  24. await _servicekafkaAdmin.CreateTopic(topic.TopicName,TimeSpan.FromDays(3), topic.NumPartitions);
  25. return ApiResponse<string>.Success($"创建 Topic {topic} 成功");
  26. }
  27. [HttpDelete("{topic}")]
  28. public async Task<ApiResponse<string>> Delete(string topic)
  29. {
  30. await _servicekafkaAdmin.DeleteTopics(new List<string>() {topic});
  31. return ApiResponse<string>.Success($"删除 Topic {topic} 成功");
  32. }
  33. }
  34. }