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, 1 Nov 2020 12:21:12 +0000 (13:21 +0100)
outbox/pom.xml
outbox/src/main/java/de/juplo/kafka/outbox/OutboxProducer.java

index f904537..e8b48b6 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) ->
     {