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

Encode Kafka messages with UTF8 #38728

Merged
merged 1 commit into from
Feb 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ private void assertRequestedPartitionsExist(String topicName, Collection<Integer
}

public void createMessage(KafkaMessageCreateRequest request) {
var record = new ProducerRecord<>(request.getTopic(), request.getPartition(), Bytes.wrap(request.getKey().getBytes()),
Bytes.wrap(request.getValue().getBytes()));
var record = new ProducerRecord<>(request.getTopic(), request.getPartition(),
Bytes.wrap(request.getKey().getBytes(StandardCharsets.UTF_8)),
Bytes.wrap(request.getValue().getBytes(StandardCharsets.UTF_8)));

Optional.ofNullable(request.getHeaders())
.orElseGet(Collections::emptyMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ public KafkaMessage convert(ConsumerRecord<Bytes, Bytes> message) {
message.partition(),
message.offset(),
message.timestamp(),
Optional.ofNullable(message.key()).map(Bytes::toString).orElse(null),
Optional.ofNullable(message.value()).map(Bytes::toString).orElse(null),
Optional.ofNullable(message.key()).map((t) -> {
return new String(t.get(), StandardCharsets.UTF_8);
}).orElse(null),
Optional.ofNullable(message.value()).map((t) -> {
return new String(t.get(), StandardCharsets.UTF_8);
}).orElse(null),
headers(message));
}

Expand Down
Loading