Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 cannot send messages to a topic. You can enable it with:

```
--message.sendEnabled=true
```

## Actuator
Health and info endpoints are available at the following path: `/actuator`

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/kafdrop/controller/MessageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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()) {

Expand Down Expand Up @@ -250,6 +256,9 @@ public String addMessage(
@ModelAttribute("addMessageForm") CreateMessageVO body,
Model model) {
try {
if (!sendEnabled) {
throw new IllegalStateException("Message sending is not enabled.");
}
final MessageFormat defaultFormat = messageFormatProperties.getFormat();
final MessageFormat defaultKeyFormat = messageFormatProperties.getKeyFormat();

Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/templates/message-inspector.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@
<span class="badge badge-light">Size:</span> <span
id="partitionSize">${curPartition.size - curPartition.firstOffset}</span>
</div>

<div>
<a class="btn btn-success top-nav-buttons" href="<@spring.url '/topic/${topic.name}/allmessages'/>">
<i class="fa fa-eye"></i> All Messages
</a>
<a href="javascript:void(0)" class="btn btn-success top-nav-buttons" data-toggle="modal" data-target="#addMessageModal"> Add Message </a>
<#if sendEnabled>
<a href="javascript:void(0)" class="btn btn-success top-nav-buttons" data-toggle="modal" data-target="#addMessageModal"> Add Message </a>
</#if>
</div>


<div class="modal" id="addMessageModal" tabindex="-1" role="dialog" aria-labelledby="addMessageModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
Expand Down