+++ /dev/null
-#!/bin/bash
-
-IMAGE=juplo/spring-consumer:1.1-seek-SNAPSHOT
-
-if [ "$1" = "cleanup" ]
-then
- docker compose -f docker/docker-compose.yml down -t0 -v --remove-orphans
- mvn clean
- exit
-fi
-
-docker compose -f docker/docker-compose.yml up -d --remove-orphans kafka-1 kafka-2 kafka-3
-docker compose -f docker/docker-compose.yml rm -svf consumer seek
-
-if [[
- $(docker image ls -q $IMAGE) == "" ||
- "$1" = "build"
-]]
-then
- mvn clean install || exit
-else
- echo "Using image existing images:"
- docker image ls $IMAGE
-fi
-
-docker compose -f docker/docker-compose.yml up --remove-orphans setup || exit 1
-
-
-docker compose -f docker/docker-compose.yml up -d producer
-docker compose -f docker/docker-compose.yml up -d consumer
-
-sleep 5
-docker compose -f docker/docker-compose.yml stop producer
-docker compose -f docker/docker-compose.yml up -d seek
-sleep 5
-docker compose -f docker/docker-compose.yml stop consumer
-sleep 5
-docker compose -f docker/docker-compose.yml restart seek
-sleep 10
-docker compose -f docker/docker-compose.yml logs seek
consumer.subscribe(Arrays.asList(topic), this);
running = true;
+ log.info("{} - Fetching PartitionInfo for topic {}", id, topic);
+ consumer
+ .partitionsFor(topic)
+ .forEach(info ->
+ {
+ TopicPartition partition = new TopicPartition(topic, info.partition());
+ Long offset = offsets.get(partition);
+ if (offset != null)
+ {
+ log.info("{} - Seeking to offset {} for partition {}", id, offset, partition);
+ consumer.seek(partition, offset);
+ offsets.remove(partition);
+ }
+ });
+
while (running)
{
ConsumerRecords<String, String> records =
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions)
{
- partitions.forEach(partition ->
- {
- Long offset = offsets.get(partition);
- if (offset != null)
- {
- log.info("{} - Seeking to offset {} for partition {}", id, offset, partition);
- consumer.seek(partition, offset);
- offsets.remove(partition);
- }
- });
}
@Override