echo "Waiting for the Kafka-Cluster to become ready..."
docker-compose exec cli cub kafka-ready -b kafka:9092 1 60 > /dev/null 2>&1 || exit 1
docker-compose up setup
-docker-compose up -d gateway requests-1 requests-2 adder-1 adder-2
+docker-compose up -d gateway requests-1 requests-2
while ! [[ $(http 0:8080/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for gateway..."; sleep 1; done
while ! [[ $(http 0:8081/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for requests-1..."; sleep 1; done
while ! [[ $(http 0:8082/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for requests-2..."; sleep 1; done
-while ! [[ $(http 0:8091/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-1..."; sleep 1; done
-while ! [[ $(http 0:8092/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-2..."; sleep 1; done
docker-compose up -d peter klaus
+docker-compose up -d adder-1
+while ! [[ $(http 0:8091/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-1..."; sleep 1; done
while [[ "$(http :8091/results | jq -r .)" == "{}" ]]; do echo "Waiting for some results to show up on adder-1..."; sleep 1; done
http -v --pretty none -S :8091/results
echo
-while [[ "$(http :8092/results | jq -r .)" == "{}" ]]; do echo "Waiting for some results to show up on adder-2..."; sleep 1; done
-http -v --pretty none -S :8092/results
-echo
+
sleep 3
echo "Resultate für adder-1"
http -v --pretty none -S :8091/results
echo
+
echo "Resultate für peter von adder-1"
http :8091/results/peter | jq .[].sum | uniq
echo "Resultate für klaus von adder-1"
http :8091/results/klaus | jq .[].sum | uniq
-echo "Resultate für adder-2"
+
+
+docker-compose up -d adder-2
+while ! [[ $(http 0:8092/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-2..."; sleep 1; done
+while [[ "$(http :8092/results | jq -r .)" == "{}" ]]; do echo "Waiting for some results to show up on adder-2..."; sleep 1; done
http -v --pretty none -S :8092/results
echo
-echo "Resultate für peter von adder-2"
-http :8092/results/peter | jq .[].sum | uniq
-echo "Resultate für klaus von adder-2"
-http :8092/results/klaus | jq .[].sum | uniq
-docker-compose stop adder-1
-sleep 1
+sleep 3
echo "Resultate für adder-2"
http -v --pretty none -S :8092/results
echo
+
+echo "Resultate für peter von adder-1"
+http :8091/results/peter | jq .[].sum | uniq
+echo "Resultate für klaus von adder-1"
+http :8091/results/klaus | jq .[].sum | uniq
+
echo "Resultate für peter von adder-2"
http :8092/results/peter | jq .[].sum | uniq
echo "Resultate für klaus von adder-2"
http :8092/results/klaus | jq .[].sum | uniq
docker-compose stop adder-2
-docker-compose start adder-1
-while ! [[ $(http 0:8091/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-1..."; sleep 1; done
-while [[ "$(http :8091/results | jq -r .)" == "{}" ]]; do echo "Waiting for some results to show up on adder-1..."; sleep 1; done
+while [[ "$(http :8091/results | jq -r '.[]|contains({peter})' | grep true)" != "true" ]]; do echo "Waiting for some results for peter to show up on adder-1..."; sleep 1; done
+while [[ "$(http :8091/results | jq -r '.[]|contains({klaus})' | grep true)" != "true" ]]; do echo "Waiting for some results for klaus to show up on adder-1..."; sleep 1; done
+
echo "Resultate für adder-1"
http -v --pretty none -S :8091/results
echo
+
echo "Resultate für peter von adder-1"
http :8091/results/peter | jq .[].sum | uniq
echo "Resultate für klaus von adder-1"
http :8091/results/klaus | jq .[].sum | uniq
-docker-compose start adder-2
-while ! [[ $(http 0:8092/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-2..."; sleep 1; done
-while [[ "$(http :8092/results | jq -r .)" == "{}" ]]; do echo "Waiting for some results to show up on adder-2..."; sleep 1; done
+docker-compose kill -s 9 adder-1
+docker-compose start adder-1
+while ! [[ $(http 0:8091/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-1..."; sleep 1; done
+while [[ "$(http :8091/results | jq -r '.[]|contains({peter})' | grep true)" != "true" ]]; do echo "Waiting for some results for peter to show up on adder-1..."; sleep 1; done
+while [[ "$(http :8091/results | jq -r '.[]|contains({klaus})' | grep true)" != "true" ]]; do echo "Waiting for some results for klaus to show up on adder-1..."; sleep 1; done
+
echo "Resultate für adder-1"
http -v --pretty none -S :8091/results
echo
-echo "Resultate für adder-2"
-http -v --pretty none -S :8092/results
-echo
+
echo "Resultate für peter von adder-1"
http :8091/results/peter | jq .[].sum | uniq
echo "Resultate für klaus von adder-1"
http :8091/results/klaus | jq .[].sum | uniq
-echo "Resultate für peter von adder-2"
-http :8092/results/peter | jq .[].sum | uniq
-echo "Resultate für klaus von adder-2"
-http :8092/results/klaus | jq .[].sum | uniq
-
-docker-compose kill -s 9 adder-1
-docker-compose start adder-1
-while ! [[ $(http 0:8091/actuator/health 2> /dev/null) =~ "UP" ]]; do echo "Waiting for adder-1..."; sleep 1; done
-while [[ "$(http :8091/results | jq -r .)" == "{}" ]]; do echo "Waiting for some results to show up on adder-1..."; sleep 1; done
docker-compose kill -s 9 peter klaus
-echo "Resultate für peter von adder-1"
-http :8091/results/peter | jq .[].sum | uniq
-echo "Resultate für klaus von adder-1"
-http :8091/results/klaus | jq .[].sum | uniq
-echo "Resultate für peter von adder-2"
-http :8092/results/peter | jq .[].sum | uniq
-echo "Resultate für klaus von adder-2"
-http :8092/results/klaus | jq .[].sum | uniq
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
+import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
import org.apache.kafka.common.TopicPartition;
import java.util.*;
@RequiredArgsConstructor
@Slf4j
-public class ApplicationRebalanceListener implements RebalanceListener
+public class ApplicationRebalanceListener implements ConsumerRebalanceListener
{
private final ApplicationRecordHandler recordHandler;
private final AdderResults adderResults;
private final Set<Integer> partitions = new HashSet<>();
- private boolean commitsEnabled = true;
-
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions)
{
@Override
public void onPartitionsRevoked(Collection<TopicPartition> partitions)
{
- if (commitsEnabled)
+ log.info("{} - Commiting offsets for all previously assigned partitions", id);
+ try
{
- log.info("{} - Commiting offsets for all previously assigned partitions", id);
- try
- {
- consumer.commitSync();
- }
- catch (Exception e)
- {
- log.warn("{} - Could not commit offsets in onPartitionsRevoked():", id, e);
- }
+ consumer.commitSync();
+ }
+ catch (Exception e)
+ {
+ log.warn("{} - Could not commit offsets in onPartitionsRevoked():", id, e);
}
partitions.forEach(tp ->
stateRepository.save(new StateDocument(partition, state, results));
});
}
-
- @Override
- public void enableCommits()
- {
- commitsEnabled = true;
- }
-
- @Override
- public void disableCommits()
- {
- commitsEnabled = false;
- }
}