You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,37 +5,37 @@ It accompanies the blog post [Building Audit Logs with Change Data Capture and S
5
5
6
6
There are two applications (based on [Quarkus](https://quarkus.io/)):
7
7
8
-
*_vegetables-service_: a simple REST service for inserting and updating vegetable data into a Postgres database;
9
-
as part of its processing, it will not only update its actual "business table" `vegetable`,
10
-
but also insert some auditing metadata into a dedicated metadata table `transaction_context_data`:
11
-
the user (as obtained from the passed JWT token), the client's date (as passed via the HTTP 1.1 `Date` header)
12
-
and a use case identifier (as specified in an annotation on the REST API methods).
13
-
*_log-enricher_: a Kafka Streams application,
14
-
which joins the CDC topic holding the `vegetable` change events (`dbserver1.inventory.vegetable`) with the corresponding metadata in the `dbserver1.inventory.transaction_context_data` topic sourced from the `transaction_context_data` table;
15
-
this table is keyed by transaction id, allowing for joining the vegetable `KStream` with the metadata `KTable`.
16
-
The enriched vegetable change events are written to the `dbserver1.inventory.vegetable.enriched` topic.
8
+
-_vegetables-service_: a simple REST service for inserting and updating vegetable data into a Postgres database;
9
+
as part of its processing, it will not only update its actual "business table" `vegetable`,
10
+
but also insert some auditing metadata into a dedicated metadata table `transaction_context_data`:
11
+
the user (as obtained from the passed JWT token), the client's date (as passed via the HTTP 1.1 `Date` header)
12
+
and a use case identifier (as specified in an annotation on the REST API methods).
13
+
-_log-enricher_: a Kafka Streams application,
14
+
which joins the CDC topic holding the `vegetable` change events (`dbserver1.inventory.vegetable`) with the corresponding metadata in the `dbserver1.inventory.transaction_context_data` topic sourced from the `transaction_context_data` table;
15
+
this table is keyed by transaction id, allowing for joining the vegetable `KStream` with the metadata `KTable`.
16
+
The enriched vegetable change events are written to the `dbserver1.inventory.vegetable.enriched` topic.
17
17
18
18
## Building the Demo
19
19
20
20
```console
21
-
$ mvn clean package
21
+
mvn clean package
22
22
```
23
23
24
24
```console
25
-
$ export DEBEZIUM_VERSION=1.8
26
-
$ docker-compose up --build
25
+
export DEBEZIUM_VERSION=1.8
26
+
docker-compose up --build
27
27
```
28
28
29
29
## Deploy the Debezium Postgres Connector
30
30
31
31
```console
32
-
$ http PUT http://localhost:8083/connectors/inventory-connector/config < register-postgres.json
32
+
http PUT http://localhost:8083/connectors/inventory-connector/config < register-postgres.json
33
33
```
34
34
35
35
## Modifying Some Data and Observing the Audit Log
36
36
37
37
```console
38
-
$ http POST http://localhost:8080/vegetables 'Authorization:Bearer eyJraWQiOiJqd3Qua2V5IiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJmYXJtZXJib2IiLCJ1cG4iOiJmYXJtZXJib2IiLCJhdXRoX3RpbWUiOjE1NjY0NTgxMTMsImlzcyI6ImZhcm1zaG9wIiwiZ3JvdXBzIjpbImZhcm1lcnMiLCJjdXN0b21lcnMiXSwiZXhwIjo0MTAyNDQ0Nzk5LCJpYXQiOjE1NjY0NTgxMTMsImp0aSI6IjQyIn0.CscbJN8amqKryYvnVO1184J8F67HN2iTEjVN2VOPodcnoeOd7_iQVKUjC3h-ye5apkJjvAsQKrjzlrGCHRfl-n6jC9F7IkOtjoWnJ4wQ9BBo1SAtPw_Czt1I_Ujm-Kb1p5-BWACCBCVVFgYZTWP_laz5JZS7dIvs6VqoNnw7A4VpA6iPfTVfYlNY3u86-k1FvEg_hW-N9Y9RuihMsPuTdpHK5xdjCrJiD0VJ7-0eRQ8RXpycHuHN4xfmV8MqXBYjYSYDOhbnYbdQVbf0YJoFFqfb75my5olN-97ITsi2MS62W_y-RNT0qZrbytqINA3fF3VQsSY6VcaqRAeygrKm_Q''Date:Thu, 22 Aug 2019 08:12:31 GMT' name=Tomatoe description=Yummy!
38
+
http POST http://localhost:8080/vegetables 'Authorization:Bearer eyJraWQiOiJqd3Qua2V5IiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJmYXJtZXJib2IiLCJ1cG4iOiJmYXJtZXJib2IiLCJhdXRoX3RpbWUiOjE1NjY0NTgxMTMsImlzcyI6ImZhcm1zaG9wIiwiZ3JvdXBzIjpbImZhcm1lcnMiLCJjdXN0b21lcnMiXSwiZXhwIjo0MTAyNDQ0Nzk5LCJpYXQiOjE1NjY0NTgxMTMsImp0aSI6IjQyIn0.CscbJN8amqKryYvnVO1184J8F67HN2iTEjVN2VOPodcnoeOd7_iQVKUjC3h-ye5apkJjvAsQKrjzlrGCHRfl-n6jC9F7IkOtjoWnJ4wQ9BBo1SAtPw_Czt1I_Ujm-Kb1p5-BWACCBCVVFgYZTWP_laz5JZS7dIvs6VqoNnw7A4VpA6iPfTVfYlNY3u86-k1FvEg_hW-N9Y9RuihMsPuTdpHK5xdjCrJiD0VJ7-0eRQ8RXpycHuHN4xfmV8MqXBYjYSYDOhbnYbdQVbf0YJoFFqfb75my5olN-97ITsi2MS62W_y-RNT0qZrbytqINA3fF3VQsSY6VcaqRAeygrKm_Q' 'Date:Thu, 22 Aug 2019 08:12:31 GMT' name=Tomatoe description=Yummy!
39
39
```
40
40
41
41
This uses a pre-generated JWT token (with expiration date set to 2099-12-31 and user set to "farmerbob").
@@ -44,13 +44,13 @@ To regenerate the token with different data, use the [Jwtenizr](https://github.c
44
44
You can also update an existing vegetable record (this token is for "farmermargaret"):
45
45
46
46
```console
47
-
$ http PUT http://localhost:8080/vegetables/10 'Authorization:Bearer eyJraWQiOiJqd3Qua2V5IiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJmYXJtZXJtYXJnYXJldCIsInVwbiI6ImZhcm1lcm1hcmdhcmV0IiwiYXV0aF90aW1lIjoxNTY5ODM1Mzk5LCJpc3MiOiJmYXJtc2hvcCIsImdyb3VwcyI6WyJmYXJtZXJzIiwiY3VzdG9tZXJzIl0sImV4cCI6NDEwMjQ0NDc5OSwiaWF0IjoxNTY5ODM1Mzk5LCJqdGkiOiI0MiJ9.DTEUA3p-xyK5nveoJIVhjfKNFdVszYIb55Qj4Xrm70DDbAXuOU2FMkffuUAUm2s7ACkp2KEmg6brRwSjvA-zhW61kDR9ZgEb9NWeDjr6Eue08xcSODKt7SGV-M7h3yhuDIhU7uaZrxRUAQTWqm1vxd2rmN_QH0frhKMUNFFsLIOGLG0zHcLosRcwZ4tAKXSSB9VE0fth6srIQCUebDkF7ucA_WSYjPRvahCBd8JvnV4VUGQxZW8zcRhTEwcaLq20ODO-dr85xgWI2Yr_1A7PDuDL4oUjCb90YyhtzaIzs2vQMjcxJ6TWmTcqJpgCfkjE-TeVwjaafcNJu0fBmcP8jA''Date:Thu, 22 Aug 2019 08:12:31 GMT' name=Tomatoe description=Tasty!
47
+
http PUT http://localhost:8080/vegetables/10 'Authorization:Bearer eyJraWQiOiJqd3Qua2V5IiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiJmYXJtZXJtYXJnYXJldCIsInVwbiI6ImZhcm1lcm1hcmdhcmV0IiwiYXV0aF90aW1lIjoxNTY5ODM1Mzk5LCJpc3MiOiJmYXJtc2hvcCIsImdyb3VwcyI6WyJmYXJtZXJzIiwiY3VzdG9tZXJzIl0sImV4cCI6NDEwMjQ0NDc5OSwiaWF0IjoxNTY5ODM1Mzk5LCJqdGkiOiI0MiJ9.DTEUA3p-xyK5nveoJIVhjfKNFdVszYIb55Qj4Xrm70DDbAXuOU2FMkffuUAUm2s7ACkp2KEmg6brRwSjvA-zhW61kDR9ZgEb9NWeDjr6Eue08xcSODKt7SGV-M7h3yhuDIhU7uaZrxRUAQTWqm1vxd2rmN_QH0frhKMUNFFsLIOGLG0zHcLosRcwZ4tAKXSSB9VE0fth6srIQCUebDkF7ucA_WSYjPRvahCBd8JvnV4VUGQxZW8zcRhTEwcaLq20ODO-dr85xgWI2Yr_1A7PDuDL4oUjCb90YyhtzaIzs2vQMjcxJ6TWmTcqJpgCfkjE-TeVwjaafcNJu0fBmcP8jA' 'Date:Thu, 22 Aug 2019 08:12:31 GMT' name=Tomatoe description=Tasty!
48
48
```
49
49
50
50
Or delete a record (again using the "farmerbob" token):
Doing so, observe the contents of the `dbserver1.inventory.vegetable`, `dbserver1.inventory.transaction_context_data` and `dbserver1.inventory.vegetable.enriched` topics:
@@ -144,19 +144,102 @@ http POST http://localhost:8085/vegetables/{uuid}/auditData/{tuuid} audit:='{"us
144
144
145
145
This would then fix the missing event in the transaction context data topic and trigger the enricher to provide a new log entry.
146
146
147
-
## Stopping All Services
147
+
## Fowarding Events to a Downstream Postgres Database
This will show you the enriched events fowarded to the `dbserver1.inventory.vegetable.enriched` topic.
158
+
We need to pass this events to lightweight `postgres-sink` database defined in `docker-compose.yaml` using the [Debezium JDBC connector](https://debezium.io/documentation/reference/stable/connectors/jdbc.html).
159
+
160
+
Download the connector plugin `.tar.gz` from the Debzium [plugin archive](https://repo1.maven.org/maven2/io/debezium/debezium-connector-jdbc/) and save it to the `/config/plugins/debezium-connector-jdbc` directory.
161
+
162
+
Restart your Kafka connect container to pick up the new plugin
163
+
164
+
```console
165
+
docker compose down -v connect
166
+
docker compose up -d connect
167
+
```
168
+
169
+
Create your debezium sink connector by running
170
+
171
+
```console
172
+
http POST http://localhost:8083/connectors < connector-config/config/jdbc-connector-config.json
173
+
```
174
+
175
+
The connector should read from the `dbserver1.inventory.vegetable.enriched` topic and populate the `dbserver1_inventory_vegetable` table.
176
+
177
+
Confirm the changes by running the `exec` command into your `postgres-sink` container
0 commit comments