Added Google Guava for byte-conversions
authorKai Moritz <kai@juplo.de>
Fri, 30 Oct 2020 10:57:01 +0000 (11:57 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 16 May 2021 15:48:48 +0000 (17:48 +0200)
outbox/pom.xml
outbox/src/main/java/de/juplo/kafka/outbox/OutboxProducer.java

index 2d57a06..5bea7c9 100644 (file)
@@ -21,6 +21,7 @@
 
   <properties>
     <java.version>11</java.version>
+    <guava.version>30.0-jre</guava.version>
   </properties>
 
   <dependencies>
       <groupId>org.projectlombok</groupId>
       <artifactId>lombok</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>${guava.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.postgresql</groupId>
       <artifactId>postgresql</artifactId>
index 627ca05..30bef96 100644 (file)
@@ -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) ->
     {