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