From efcdb2ec50b06adf95eed5e7bd14c31de16b46f9 Mon Sep 17 00:00:00 2001 From: Nhan Nguyen Date: Sun, 20 Jul 2025 14:53:16 +0700 Subject: [PATCH 1/2] Added feature flag for send message --- README.md | 7 +++++++ .../java/kafdrop/controller/MessageController.java | 12 +++++++++++- src/main/resources/templates/message-inspector.ftlh | 7 ++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8e3b414..2bda85da 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,13 @@ By default, you could create a topic. If you don't want this feature, you could --topic.createEnabled=false ``` +## Message Configuration +By default, you couldn't send messages to a topic. If you want to enable this feature, you could enable it with: + +``` +--message.sendEnabled=true +``` + ## Actuator Health and info endpoints are available at the following path: `/actuator` diff --git a/src/main/java/kafdrop/controller/MessageController.java b/src/main/java/kafdrop/controller/MessageController.java index 663c3004..3b8eddf1 100644 --- a/src/main/java/kafdrop/controller/MessageController.java +++ b/src/main/java/kafdrop/controller/MessageController.java @@ -58,6 +58,7 @@ import kafdrop.util.ProtobufSchemaRegistryMessageDeserializer; import kafdrop.util.Serializers; import org.apache.kafka.clients.producer.RecordMetadata; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -92,15 +93,19 @@ public final class MessageController { private final ProtobufDescriptorProperties protobufProperties; + private final boolean sendEnabled; + public MessageController(KafkaMonitor kafkaMonitor, MessageInspector messageInspector, MessageFormatProperties messageFormatProperties, SchemaRegistryProperties schemaRegistryProperties, - ProtobufDescriptorProperties protobufProperties) { + ProtobufDescriptorProperties protobufProperties, + @Value("${message.sendEnabled:false}") boolean sendEnabled) { this.kafkaMonitor = kafkaMonitor; this.messageInspector = messageInspector; this.messageFormatProperties = messageFormatProperties; this.schemaRegistryProperties = schemaRegistryProperties; this.protobufProperties = protobufProperties; + this.sendEnabled = sendEnabled; } /** @@ -221,6 +226,7 @@ public String viewMessageForm(@PathVariable("name") String topicName, model.addAttribute("keyFormats", KeyFormat.values()); model.addAttribute("descFiles", protobufProperties.getDescFilesList()); model.addAttribute("isAnyProtoOpts", List.of(true, false)); + model.addAttribute("sendEnabled", sendEnabled); if (!messageForm.isEmpty() && !errors.hasErrors()) { @@ -249,6 +255,10 @@ public String addMessage( String topicName, @ModelAttribute("addMessageForm") CreateMessageVO body, Model model) { + if (!sendEnabled) { + model.addAttribute("errorMessage", "Message sending is not enabled."); + return "message-inspector"; + } try { final MessageFormat defaultFormat = messageFormatProperties.getFormat(); final MessageFormat defaultKeyFormat = messageFormatProperties.getKeyFormat(); diff --git a/src/main/resources/templates/message-inspector.ftlh b/src/main/resources/templates/message-inspector.ftlh index c97576bf..541ff338 100644 --- a/src/main/resources/templates/message-inspector.ftlh +++ b/src/main/resources/templates/message-inspector.ftlh @@ -88,14 +88,15 @@ Size: ${curPartition.size - curPartition.firstOffset} -
All Messages - Add Message + <#if sendEnabled> + Add Message +
- +