<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-json</artifactId>
- </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.errors.WakeupException;
-import org.apache.kafka.common.serialization.LongDeserializer;
import org.apache.kafka.common.serialization.StringDeserializer;
import javax.annotation.PreDestroy;
props.put("bootstrap.servers", bootstrapServer);
props.put("group.id", groupId);
props.put("client.id", clientId);
- props.put("key.deserializer", LongDeserializer.class.getName());
+ props.put("key.deserializer", StringDeserializer.class.getName());
props.put("value.deserializer", StringDeserializer.class.getName());
consumer = new KafkaConsumer<>(props);
{
log.info("{} - RIIING!", id);
}
+ catch(Exception e)
+ {
+ log.error("{} - Unexpected error: {}", id, e.toString());
+ }
finally
{
log.info("{} - Unsubscribing...", id);
}
}
+
+ public void seek(long offset)
+ {
+ consumer
+ .partitionsFor(topic)
+ .forEach(partition ->
+ consumer.seek(
+ new TopicPartition(topic, partition.partition()),
+ offset));
+ }
+
+
public synchronized void start()
{
if (running)
future.get();
}
+
@PreDestroy
public void destroy() throws ExecutionException, InterruptedException
{
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.ExecutionException;
{
consumer.stop();
}
+
+
+ @PostMapping("seek")
+ public void seek(@RequestBody long offset)
+ {
+ consumer.seek(offset);
+ }
}