From: Kai Moritz Date: Fri, 30 Oct 2020 10:57:01 +0000 (+0100) Subject: Added Google Guava for byte-conversions X-Git-Tag: part-2~7 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=bdc7b089e14ddc16f7e76f6a736b27b608e35ab4;p=demos%2Fkafka%2Foutbox Added Google Guava for byte-conversions --- 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) -> {