Review comment incorporation
This commit is contained in:
parent
1d1aaeedb6
commit
2dd76f7e78
@ -1,6 +1,7 @@
|
|||||||
package com.baeldung.kafka.message.ordering;
|
package com.baeldung.kafka.message.ordering;
|
||||||
|
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -2,6 +2,7 @@ package com.baeldung.kafka.message.ordering.payload;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class Message implements Comparable<Message> {
|
public class Message implements Comparable<Message> {
|
||||||
private long insertPosition;
|
private long insertPosition;
|
||||||
@ -44,7 +45,7 @@ public class Message implements Comparable<Message> {
|
|||||||
|
|
||||||
public static long getRandomMessageId() {
|
public static long getRandomMessageId() {
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
return rand.nextInt(1000);
|
return ThreadLocalRandom.current().nextInt(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class JacksonDeserializer<T> implements Deserializer<T> {
|
public class JacksonDeserializer<T> implements Deserializer<T> {
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private Class<T> tClass;
|
private Class<T> type;
|
||||||
|
|
||||||
public JacksonDeserializer(Class<T> tClass) {
|
public JacksonDeserializer(Class<T> type) {
|
||||||
this.tClass = tClass;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JacksonDeserializer() {
|
public JacksonDeserializer() {
|
||||||
@ -18,7 +18,7 @@ public class JacksonDeserializer<T> implements Deserializer<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(Map<String, ?> configs, boolean isKey) {
|
public void configure(Map<String, ?> configs, boolean isKey) {
|
||||||
this.tClass = (Class<T>) configs.get("value.deserializer.serializedClass");
|
this.type = (Class<T>) configs.get("value.deserializer.serializedClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,7 +27,7 @@ public class JacksonDeserializer<T> implements Deserializer<T> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(bytes, tClass);
|
return objectMapper.readValue(bytes, type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Error deserializing value", e);
|
throw new RuntimeException("Error deserializing value", e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user