|
@@ -1,14 +1,31 @@
|
|
|
|
+import org.apache.kafka.clients.consumer.ConsumerConfig;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
|
|
|
+import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
import org.apache.kafka.common.serialization.StringDeserializer;
|
|
import org.apache.kafka.common.serialization.StringDeserializer;
|
|
|
|
|
|
|
|
+import java.util.Properties;
|
|
|
|
+
|
|
public class KafkaConsumerCommon {
|
|
public class KafkaConsumerCommon {
|
|
|
|
+ public static final String GROUP = "test-group";
|
|
public static final String STRING_DESERIALIZER = StringDeserializer.class.getName();
|
|
public static final String STRING_DESERIALIZER = StringDeserializer.class.getName();
|
|
- public static final Integer TIMEOUT = 200;
|
|
+ public static final Integer TIMEOUT = 10;
|
|
protected static Boolean started = false;
|
|
protected static Boolean started = false;
|
|
protected static Integer pass = 0;
|
|
protected static Integer pass = 0;
|
|
|
|
|
|
- static void process(ConsumerRecords<String, String> records) {
|
|
+ static void configure(Properties props) {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, KafkaCommon.BROKERS);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, STRING_DESERIALIZER);
|
|
|
|
+ props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, STRING_DESERIALIZER);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static void process(KafkaConsumer<String, String> c) {
|
|
|
|
+ ConsumerRecords<String, String> records = c.poll(KafkaConsumerCommon.TIMEOUT);
|
|
if (!started) {
|
|
if (!started) {
|
|
started = true;
|
|
started = true;
|
|
System.out.printf("Started");
|
|
System.out.printf("Started");
|