Added data-jdbc as git submodule jdbc
authorKai Moritz <kai@juplo.de>
Sat, 31 Oct 2020 15:59:17 +0000 (16:59 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 16 May 2021 15:48:17 +0000 (17:48 +0200)
.gitignore [new file with mode: 0644]
.gitmodules [new file with mode: 0644]
README.md [new file with mode: 0644]
README.sh [new file with mode: 0755]
docker-compose.yml [new file with mode: 0644]
jdbc [new submodule]
pom.xml [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..612c5bc
--- /dev/null
@@ -0,0 +1,3 @@
+target
+.idea
+*.iml
diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..a9ff7f6
--- /dev/null
@@ -0,0 +1,4 @@
+[submodule "data-jdbc"]
+       path = jdbc
+       url = https://juplo.de/git/demos/spring/data-jdbc
+       branch = outbox
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..2748ed9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,40 @@
+# Implementation of the Outbox-Pattern for Apache Kafka
+
+This Repository holds the source code for
+[a blog-series that explains a technically complete implementation of the outbox-pattern for Apache Kafka](https://juplo.de/implementing-the-outbox-pattern-with-kafka-part-1-the-outbox-table/).
+
+Execute [README.sh](README.sh) in a shell to demonstrate the example:
+
+    ./README.sh
+
+The script will...
+
+* compile the component,
+* package it as Docker-Images,
+* start up the component and a PostreSQL as containers in a [Compose-Setup](docker-compose.yml),
+* execute example-queries (CREATE / DELETE) against the API of [the example-project](https://juplo.de/implementing-the-outbox-pattern-with-kafka-part-0-the-example/) and
+* tail the logs of the containers `jdbc` to show what is going on.
+
+You can verify the expected outcome of the demonstration by running a command like the following:
+
+    $ docker-compose exec postgres psql -Uoutbox -c'SELECT * FROM outbox;' -Ppager=0  outbox | grep peter
+      1 | peter1  | "CREATED" | 2021-05-16 13:20:36.849
+     10 | peter2  | "CREATED" | 2021-05-16 13:20:42.141
+     19 | peter3  | "CREATED" | 2021-05-16 13:20:47.136
+     28 | peter4  | "CREATED" | 2021-05-16 13:20:52.087
+     37 | peter5  | "CREATED" | 2021-05-16 13:20:57.512
+     46 | peter6  | "CREATED" | 2021-05-16 13:21:02.493
+     55 | peter7  | "CREATED" | 2021-05-16 13:21:07.503
+    $
+
+The example-output shows, that the CREATE-event for users with "peter" in their username are only stored exactly once in the outbox-table, although the script issues several requests for each of these users.
+
+Be aware, that the outcome of the script will be different, if you run it several times.
+In order to reproduce the same behaviour, you have to shut down the Compose-Setup before rerunning the script:
+
+    docker-compose down -v
+    ./README.sh
+
+To clean up all created artifacts one can run:
+
+    ./README.sh cleanup
diff --git a/README.sh b/README.sh
new file mode 100755 (executable)
index 0000000..89aa269
--- /dev/null
+++ b/README.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+if [ "$1" = "cleanup" ]
+then
+  docker-compose down -v
+  mvn clean
+  docker image rm juplo/data-jdbc:polling-outbox-2-SNAPSHOT
+  exit
+fi
+
+if [[
+  $(docker image ls -q juplo/data-jdbc:polling-outbox-2-SNAPSHOT) == "" ||
+  "$1" = "build"
+]]
+then
+  mvn install || exit
+else
+  echo "Using image existing images:"
+  docker image ls juplo/data-jdbc:polling-outbox-2-SNAPSHOT
+fi
+
+docker-compose up -d jdbc
+
+while ! [[ $(http :8080/actuator/health 2>/dev/null | jq -r .status) == "UP" ]];
+do
+  echo "Waiting for User-Service...";
+  sleep 1;
+done
+
+
+docker-compose logs --tail=0 -f jdbc &
+
+for i in `seq 1 7`;
+do
+  echo peter$i | http :8080/users
+  echo uwe$i | http :8080/users
+  echo peter$i | http :8080/users
+  echo simone$i | http :8080/users
+  echo beate$i | http :8080/users
+  http DELETE :8080/users/franz$i
+  http DELETE :8080/users/simone$i
+  echo beate$i | http :8080/users
+  http DELETE :8080/users/beate$i
+  echo franz$i | http :8080/users
+  echo franz$i | http :8080/users
+  echo beate$i | http :8080/users
+  http DELETE :8080/users/uwe$i
+  sleep 1
+done;
+
+docker-compose exec postgres psql -Uoutbox -c'SELECT * FROM outbox;' -Ppager=0  outbox
+docker-compose stop
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644 (file)
index 0000000..d04c665
--- /dev/null
@@ -0,0 +1,27 @@
+version: "3"
+
+services:
+
+  jdbc:
+    image: juplo/data-jdbc:polling-outbox-2-SNAPSHOT
+    ports:
+      - 8080:8080
+    environment:
+      spring.profiles.active: prod
+    depends_on:
+      - postgres
+
+
+  postgres:
+    image: postgres:13
+    ports:
+      - 5432:5432
+    environment:
+      POSTGRES_USER: outbox
+      POSTGRES_PASSWORD: outbox
+      POSTGRES_DB: outbox
+    volumes:
+      - pgdata:/var/lib/postgresql/data/
+
+volumes:
+  pgdata:
diff --git a/jdbc b/jdbc
new file mode 160000 (submodule)
index 0000000..d2fbbf0
--- /dev/null
+++ b/jdbc
@@ -0,0 +1 @@
+Subproject commit d2fbbf029e151e37fcd48cbbdb90c3c14a48aa8d
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..3e46567
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>de.juplo.kafka.outbox</groupId>
+  <artifactId>polling-outbox-parent</artifactId>
+  <version>polling-outbox-2-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <name>polling-outbox-parent</name>
+  <description>Simple example-implementation of the Polling-Outbox-Pattern</description>
+
+  <modules>
+    <module>jdbc</module>
+  </modules>
+
+</project>