Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MessagePack Support #172

Merged
merged 1 commit into from
Aug 8, 2020
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
<artifactId>avro</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>
<version>0.8.20</version>
</dependency>

<!-- Spring Boot -->
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/kafdrop/controller/MessageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ private MessageFormat getSelectedMessageFormat(String format) {
return MessageFormat.AVRO;
} else if ("PROTOBUF".equalsIgnoreCase(format)) {
return MessageFormat.PROTOBUF;
} else if ("MSGPACK".equalsIgnoreCase(format)){
return MessageFormat.MSGPACK;
} else {
return MessageFormat.DEFAULT;
}
Expand Down Expand Up @@ -268,6 +270,8 @@ private MessageDeserializer getDeserializer(String topicName, MessageFormat form
.replaceAll("/", "");
final var fullDescFile = protobufProperties.getDirectory() + File.separator + descFileName + ".desc";
deserializer = new ProtobufMessageDeserializer(topicName, fullDescFile, msgTypeName);
} else if (format == MessageFormat.MSGPACK) {
deserializer = new MsgPackMessageDeserializer();
} else {
deserializer = new DefaultMessageDeserializer();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kafdrop/util/MessageFormat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package kafdrop.util;

public enum MessageFormat {
DEFAULT, AVRO, PROTOBUF
DEFAULT, AVRO, PROTOBUF, MSGPACK
}
27 changes: 27 additions & 0 deletions src/main/java/kafdrop/util/MsgPackMessageDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kafdrop.util;

import java.io.IOException;
import java.nio.ByteBuffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.msgpack.core.MessagePack;
import org.msgpack.core.MessageUnpacker;

public class MsgPackMessageDeserializer implements MessageDeserializer {

private static final Logger LOG = LoggerFactory.getLogger(MsgPackMessageDeserializer.class);

@Override
public String deserializeMessage(ByteBuffer buffer) {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(buffer);
try {
return unpacker.unpackValue().toJson();
} catch (IOException e) {
final String errorMsg = "Unable to unpack msgpack message";
LOG.error(errorMsg, e);
throw new DeserializationException(errorMsg);
}
}
}