From bdc7b089e14ddc16f7e76f6a736b27b608e35ab4 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 30 Oct 2020 11:57:01 +0100 Subject: [PATCH] Added Google Guava for byte-conversions --- outbox/pom.xml | 6 ++++++ .../src/main/java/de/juplo/kafka/outbox/OutboxProducer.java | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/outbox/pom.xml b/outbox/pom.xml index 2d57a06..5bea7c9 100644 --- a/outbox/pom.xml +++ b/outbox/pom.xml @@ -21,6 +21,7 @@ 11 + 30.0-jre @@ -40,6 +41,11 @@ org.projectlombok lombok + + com.google.guava + guava + ${guava.version} + org.postgresql postgresql diff --git a/outbox/src/main/java/de/juplo/kafka/outbox/OutboxProducer.java b/outbox/src/main/java/de/juplo/kafka/outbox/OutboxProducer.java index 627ca05..30bef96 100644 --- a/outbox/src/main/java/de/juplo/kafka/outbox/OutboxProducer.java +++ b/outbox/src/main/java/de/juplo/kafka/outbox/OutboxProducer.java @@ -1,8 +1,8 @@ package de.juplo.kafka.outbox; +import com.google.common.primitives.Longs; import org.apache.kafka.common.serialization.StringSerializer; -import java.nio.ByteBuffer; import java.time.Duration; import java.util.List; import java.util.Properties; @@ -64,9 +64,7 @@ public class OutboxProducer new ProducerRecord<>(topic, item.getKey(), item.getValue()); sequenceNumber = item.getSequenceNumber(); - ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); - buffer.putLong(item.getSequenceNumber()); - record.headers().add("SEQ#", buffer.array()); + record.headers().add("SEQ#", Longs.toByteArray(sequenceNumber)); producer.send(record, (metadata, e) -> { -- 2.20.1