├── .gitignore ├── LICENSE ├── README.md ├── cdc-with-debezium ├── docker-compose.yml ├── mysql-connector.json └── mysql-data │ ├── 00_setup_database.sql │ ├── 01_create_table_customers.sql │ └── 02_populate_customers.sql ├── images └── pulsar-summit-session.png ├── kill-container.sh ├── microservice-with-kafka ├── .dockerignore ├── .gitignore ├── Dockerfile ├── pom.xml ├── run-microservice.sh └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── summit │ │ │ └── pulsar │ │ │ └── demo │ │ │ ├── App.java │ │ │ ├── Constants.java │ │ │ └── FiveSecondsTom.java │ └── resources │ │ └── application.properties │ └── test │ └── resources │ └── .gitkeep ├── shared-infrastructure ├── brokers.yml └── persistence.yml ├── start-brokers.sh ├── start-cdc-with-debezium.sh ├── start-persistence.sh ├── start-stream-processing.sh ├── stop-brokers.sh ├── stop-cdc-with-debezium.sh ├── stop-everything.sh ├── stop-persistence.sh ├── stop-stream-processing.sh ├── stream-processing ├── docker-compose.yml └── statements.sql └── view-container-logs.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | .DS_Store 25 | connect-integration/.DS_Store 26 | stream-processing/.DS_Store 27 | microservices/.DS_Store 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Is Using KoP (Kafka-On-Pulsar) a Good Idea? 2 | =========================================== 3 | 4 | Building microservices around Apache Kafka is your job, and life is great. One day, you hear community members talking about some neat Apache Pulsar features, and get you intrigued. I mean, we all love Kafka, but you can't avoid wondering if migrating one of your projects to Pulsar is a good idea. Then it happens. You find Pulsar supports Kafka clients natively via a [protocol handler](https://github.com/apache/pulsar/wiki/PIP-41:-Pluggable-Protocol-Handler) called KoP: [Kafka-On-Pulsar](https://github.com/streamnative/kop). 5 | 6 | This gets you pumped. Is that it? Can I go ahead and simply point my microservices to Pulsar and be a hero with this migration? But you must be responsible; and history says you shouldn't believe migrations like this are refactoring free. This is why you may get interested in what this repository offers. To prove that KoP is worth your time, use it in scenarios that would really put the technology to stress, going way beyond the bread-and-buttter of producing and consuming messages. Follow the instructions below to test KoP in the following scenarios: 7 | 8 | - **Microservice built for Apache Kafka**: microservice written in [Spring Boot](https://spring.io/projects/spring-boot), that connects to a "Kafka Cluster" using two endpoints exposed by Apache Pulsar with KoP enabled. 9 | 10 | - **CDC using Debezium for MySQL**: Kafka Connect with a connector from [Debezium](https://debezium.io) to capture in near real-time changes made to a [MySQL](https://www.mysql.com) database. Kafka Connect uses an endpoint exposed by Apache Pulsar with KoP enabled. 11 | 12 | - **Stream processing using ksqlDB**: Stream processing pipeline using [ksqlDB](https://ksqldb.io) to flat out events produced to Kafka. ksqlDB uses an endpoint exposed by Apache Pulsar with KoP enabled. 13 | 14 | 💡 This repository was created as part of the session entitled **Is Using KoP (Kafka-On-Pulsar) a Good Idea?** delivered in the [Pulsar Summit 2022](https://pulsar-summit.org/event/san-francisco-2022) conference, in San Francisco, CA. Click in the image below to access slides and recording of this session. 15 | 16 | [![Is Using KoP (Kafka-On-Pulsar) a Good Idea?](/images/pulsar-summit-session.png "https://talks.riferrei.com/LgUiHy")](https://talks.riferrei.com/LgUiHy) 17 | 18 | Requirements 19 | ------------ 20 | 21 | - [Docker](https://www.docker.com/get-started) 4.11+ 22 | - [Java](https://openjdk.org/install/) 17+ 23 | - [Maven](https://maven.apache.org/download.cgi) 3.8.6+ 24 | - [Apache Pulsar](https://pulsar.apache.org/download) 2.10.1+ 25 | - [Confluent Platform](https://www.confluent.io/get-started/?product=software) 7.0.5+ 26 | 27 | 🏢 Shared Apache Pulsar Infrastructure 28 | -------------------------------------- 29 | 30 | Before jumping into any of the scenarios, you must start the shared infrastructure all of them will use. This includes one Zookeeper instance, two Bookkeepers, and two Pulsar brokers. 31 | 32 | 1️⃣ Start the persistence layer 33 | 34 | ```bash 35 | sh start-persistence.sh 36 | ``` 37 | 38 | 👀 You must wait until the containers `zookeeper`, `persistence-bookie-1`, and `persistence-bookie-2` are healthy to proceed with the next step. 39 | 40 | 2️⃣ Start the Pulsar brokers with KoP enabled 41 | 42 | ```bash 43 | sh start-brokers.sh 44 | ``` 45 | 46 | 👀 You must wait until the containers `kafka-1` and `kafka-2` are healthy to proceed with any next step. 47 | 48 | ✅ Scenario: Microservice built for Apache Kafka 49 | ------------------------------------------------- 50 | 51 | This scenario checks two things. First, if KoP provides a truly Kafka-compatible API where third-party frameworks such as [Spring Boot](https://spring.io/projects/spring-boot) can connect with without deployment problems. Second, to check whether KoP is capable of mimic the distributed protocol from Kafka. Kafka is not just a one-directional typical client-server protocol. Instead, it is a bi-directional protocol where messages are exchanged from both parties. A good example is when a producer connects to the Kafka cluster using one bootstrap server endpoint, and the cluster keeps periodically updating that list back to the producer with metadata about the new cluster formation. Same for the consumer, which after joining a group, may be eventually removed by the cluster for the absence of valid heartbeats. 52 | 53 | To validate this scenario, two Apache Pulsar brokers with KoP enabled will be executed, and the microservice will use the endpoint of only one broker to bootstrap the cluster. When everything is up-and-running and working as expected, the broker being used by the microservice will be killed, and the assumption is that the microservice should fallback to the other available broker, and continue its execution. If that ever happens, it means that the bootstrap worked as expected, giving the specifications of how Kafka manages clusters and sends this information to its clients. 54 | 55 | 1️⃣ Run the Spring Boot microservice 56 | 57 | ```bash 58 | sh microservice-with-kafka/run-microservice.sh 59 | ``` 60 | 61 | 👀 You must wait until the microservice connects with the brokers and start producing and consuming messages like this: 62 | 63 | ```console 64 | org.summit.pulsar.demo.FiveSecondsTom : Hi, I'm Tom 😄 65 | ``` 66 | 67 | 2️⃣ Find out which broker is the leader of the partition 68 | 69 | ```bash 70 | $PULSAR_HOME/bin/pulsar-admin --admin-url http://localhost:8081 topics lookup persistent://public/default/fiveSecondsTomTopic 71 | ``` 72 | 73 | 👀 Take a note of which broker shows up in this lookup. 74 | 75 | 3️⃣ Forcing a fail-over situation by killing the leader 76 | 77 | ```bash 78 | sh kill-broker.sh 79 | ``` 80 | 81 | 👀 Observe the microservice for a couple minutes. It must continue its processing. 82 | 83 | #️⃣ stop all containers if you're done for the day. 84 | 85 | ```bash 86 | sh stop-everything.sh 87 | ``` 88 | 89 | ✅ Scenario: CDC using Debezium for MySQL 90 | ----------------------------------------- 91 | 92 | One of the most popular use cases for [Apache Kafka](https://kafka.apache.org) is using it to replicate data from relational databases to purpose-built systems, while Kafka acts as a persistent layer for the data streams. To enable this use case, [Kafka Connect](https://kafka.apache.org/documentation/#connect), which is an integration technology from the Kafka ecosystem, is usually used with connectors capable of pulling data from relational databases either using a polling query or via CDC (Change-Data Capture). 93 | 94 | This scenario check if an [Apache Pulsar](https://pulsar.apache.org) broker with [KoP](https://github.com/streamnative/kop) enabled can be used as the data stream layer for Kafka Connect, which uses a connector from [Debezium](https://debezium.io) to stream data changes made in near real-time in a [MySQL](https://www.mysql.com) database. The validation process is very simple: you just need to set this up as you would using Apache Kafka — but use Apache Pulsar with KoP enabled instead. Everything must work as advertised. 95 | 96 | 1️⃣ Start the containers for this scenario 97 | 98 | ```bash 99 | sh start-cdc-with-debezium.sh 100 | ``` 101 | 102 | 👀 You must wait until the containers `mysql` and `connect` are healthy to proceed with the next step. 103 | 104 | 2️⃣ Connect with the MySQL database and check the data 105 | 106 | ```bash 107 | docker compose -f cdc-with-debezium/docker-compose.yml exec mysql bash -c 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD cdc_with_debezium' 108 | ``` 109 | 110 | Then, in the MySQL shell, execute the following command: 111 | 112 | ```sql 113 | select * from customers; 114 | ``` 115 | 116 | You should see an output like this: 117 | 118 | ```console 119 | +------+------------+-----------+-----------------------+ 120 | | id | first_name | last_name | email | 121 | +------+------------+-----------+-----------------------+ 122 | | 1001 | Sally | Thomas | sally.thomas@acme.com | 123 | | 1002 | George | Bailey | gbailey@foobar.com | 124 | | 1003 | Edward | Walker | ed@walker.com | 125 | | 1004 | Anne | Kretchmar | annek@noanswer.org | 126 | +------+------------+-----------+-----------------------+ 127 | ``` 128 | 129 | 3️⃣ Deploy the Debezium connector 130 | 131 | ```bash 132 | curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @cdc-with-debezium/mysql-connector.json 133 | ``` 134 | 135 | To verify if the connector has been sucessfully deployed, execute the following command: 136 | 137 | ```bash 138 | curl -X GET http://localhost:8083/connectors/cdc-with-debezium 139 | ``` 140 | 141 | You should see an output like this: 142 | 143 | ```json 144 | {"name":"cdc-with-debezium","config":{"connector.class":"io.debezium.connector.mysql.MySqlConnector","database.user":"debezium","database.server.id":"184054","tasks.max":"1","database.hostname":"mysql","database.password":"dbz","database.history.kafka.bootstrap.servers":"kafka-1:9092,kafka-2:9093","database.history.kafka.topic":"dbhistory.cdc_with_debezium","name":"cdc-with-debezium","database.server.name":"mysql","database.port":"3306","database.include.list":"cdc_with_debezium"},"tasks":[{"connector":"cdc-with-debezium","task":0}],"type":"source"} 145 | ``` 146 | 147 | 4️⃣ Use the `kafka-console-consumer` to monitor data streams 148 | 149 | ```bash 150 | $KAFKA_HOME/bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic mysql.cdc_with_debezium.customers 151 | ``` 152 | 153 | 👀 Leave this console open so you can see the data coming in. 154 | 155 | 5️⃣ Insert a new record into the `customers` table. 156 | 157 | ```bash 158 | docker compose -f cdc-with-debezium/docker-compose.yml exec mysql bash -c 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD cdc_with_debezium' 159 | ``` 160 | 161 | Then, in the MySQL shell, execute the following command: 162 | 163 | ```sql 164 | insert into customers values (1006, "Ricardo", "Ferreira", "riferrei@riferrei.com"); 165 | ``` 166 | 167 | 6️⃣ Look to the `kafka-console-consumer` output. You should see an output like this: 168 | 169 | ```console 170 | Struct{after=Struct{id=1006,first_name=Ricardo,last_name=Ferreira,email=riferrei@riferrei.com},source=Struct{version=1.9.3.Final,connector=mysql,name=mysql,ts_ms=1660957053000,db=cdc_with_debezium,table=customers,server_id=1,file=binlog.000002,pos=406,row=0,thread=36},op=c,ts_ms=1660957053478} 171 | ``` 172 | 173 | #️⃣ Stop the containers from this scenario. 174 | 175 | ```bash 176 | sh stop-cdc-with-debezium.sh 177 | ``` 178 | 179 | Alternatively, you can also stop all containers if you're done for the day. 180 | 181 | ```bash 182 | sh stop-everything.sh 183 | ``` 184 | 185 | ### This scenario was created based on the following tutorial: 186 | 187 | 🧑🏻‍💻 https://github.com/debezium/debezium-examples/tree/main/tutorial#using-mysql 188 | 189 | ✅ Scenario: Stream processing using ksqlDB 190 | ------------------------------------------- 191 | 192 | Another popular use case for [Apache Kafka](https://kafka.apache.org) is using it as a persistent layer for stream processing pipelines. The idea is to have events being stored into Kafka, and stream processing technologies such as [Kafka Streams](https://kafka.apache.org/documentation/streams), [ksqlDB](https://ksqldb.io), [Apache Flink](https://flink.apache.org) be able to execute event processing pipelines that compute near real-time results as new events arrive. 193 | 194 | This scenario check if an [Apache Pulsar](https://pulsar.apache.org) broker with [KoP](https://github.com/streamnative/kop) enabled can be used as the data stream layer for ksqlDB, which implements a stream processing pipeline that flattens out events with a complex nested layout and also changes the data format from [JSON](https://www.json.org/json-en.html) to [Protobuf](https://developers.google.com/protocol-buffers). The validation process is very simple: you just need to set this up as you would using Apache Kafka — but use Apache Pulsar with KoP enabled instead. Everything must work as advertised. 195 | 196 | 1️⃣ Start the containers for this scenario 197 | 198 | ```bash 199 | sh start-stream-processing.sh 200 | ``` 201 | 202 | 👀 You must wait until the containers `schema-registry` and `ksqldb-server` are healthy to proceed with the next step. 203 | 204 | 2️⃣ Connect with the ksqlDB server via CLI: 205 | 206 | ```bash 207 | $KAFKA_HOME/bin/ksql http://localhost:8088 208 | ``` 209 | 210 | Then, in the ksqlDB shell, execute the following command: 211 | 212 | ```sql 213 | RUN SCRIPT 'stream-processing/statements.sql'; 214 | ``` 215 | 216 | Once this command finishes, you should have two streams created. Before moving further, it is a good idea to check if they were really created by executing the following command: 217 | 218 | ```sql 219 | SHOW STREAMS; 220 | ``` 221 | 222 | You should see an output like this: 223 | 224 | ```console 225 | Stream Name | Kafka Topic | Key Format | Value Format | Windowed 226 | ---------------------------------------------------------------------------- 227 | FLATTENED_ORDERS | FLATTENED_ORDERS | KAFKA | PROTOBUF | false 228 | ORDERS | ORDERS | KAFKA | JSON | false 229 | ---------------------------------------------------------------------------- 230 | ``` 231 | 232 | 3️⃣ Execute a continuous query 233 | 234 | ```sql 235 | SELECT 236 | ORDER_ID, 237 | ORDER_TS, 238 | ORDER_AMOUNT, 239 | CUST_FIRST_NAME, 240 | CUST_LAST_NAME, 241 | CUST_PHONE_NUMBER, 242 | CUST_ADDR_STREET, 243 | CUST_ADDR_NUMBER, 244 | CUST_ADDR_ZIPCODE, 245 | CUST_ADDR_CITY, 246 | CUST_ADDR_STATE, 247 | PROD_SKU, 248 | PROD_NAME, 249 | PROD_VENDOR_NAME, 250 | PROD_VENDOR_COUNTRY 251 | FROM FLATTENED_ORDERS 252 | EMIT CHANGES; 253 | ``` 254 | 255 | 👀 This query never stops, unless you press Cmd+C to interrupt its execution. Leave this console open so you can see the data coming in. 256 | 257 | 4️⃣ Ingest data into the input topic 258 | 259 | ```bash 260 | $KAFKA_HOME/bin/kafka-console-producer --bootstrap-server localhost:9092 --topic ORDERS 261 | ``` 262 | 263 | Copy-and-paste the events below to the `kafka-console-producer` CLI: 264 | 265 | ```json 266 | {"id": "1", "timestamp": "2020-01-18 01:12:05", "amount": 84.02, "customer": {"firstName": "Ricardo", "lastName": "Ferreira", "phoneNumber": "1234567899", "address": {"street": "Street SDF", "number": "8602", "zipcode": "27640", "city": "Raleigh", "state": "NC"}}, "product": {"sku": "P12345", "name": "Highly Durable Glue", "vendor": {"vendorName": "Acme Corp", "country": "US"}}} 267 | {"id": "2", "timestamp": "2020-01-18 01:35:12", "amount": 84.02, "customer": {"firstName": "Tim", "lastName": "Berglund", "phoneNumber": "9987654321", "address": {"street": "Street UOI", "number": "1124", "zipcode": "85756", "city": "Littletown", "state": "CO"}}, "product": {"sku": "P12345", "name": "Highly Durable Glue", "vendor": {"vendorName": "Acme Corp", "country": "US"}}} 268 | {"id": "3", "timestamp": "2020-01-18 01:58:55", "amount": 84.02, "customer": {"firstName": "Robin", "lastName": "Moffatt", "phoneNumber": "4412356789", "address": {"street": "Street YUP", "number": "9066", "zipcode": "BD111NE", "city": "Leeds", "state": "YS"}}, "product": {"sku": "P12345", "name": "Highly Durable Glue", "vendor": {"vendorName": "Acme Corp", "country": "US"}}} 269 | {"id": "4", "timestamp": "2020-01-18 02:31:43", "amount": 84.02, "customer": {"firstName": "Viktor", "lastName": "Gamov", "phoneNumber": "9874563210", "address": {"street": "Street SHT", "number": "12450", "zipcode": "07003", "city": "New Jersey", "state": "NJ"}}, "product": {"sku": "P12345", "name": "Highly Durable Glue", "vendor": {"vendorName": "Acme Corp", "country": "US"}}} 270 | 271 | ``` 272 | 273 | 5️⃣ Verify if the pipeline executed correctly 274 | 275 | Go back to the continuous query that you started on step 3️⃣. With new events arriving, you should see that the query generated an output similar to this: 276 | 277 | ```console 278 | +-----------+--------------+-----------------+-----------------+-----------------+-----------------+-----------------+------------+----------------------+ 279 | |ORDER_ID |ORDER_AMOUNT |CUST_FIRST_NAME |CUST_LAST_NAME |CUST_PHONE_NUMBER|CUST_ADDR_STREET |CUST_ADDR_NUMBER |PROD_SKU |PROD_NAME | 280 | +-----------+--------------+-----------------+-----------------+-----------------+-----------------+-----------------+------------+----------------------+ 281 | |1 |84.02 |Ricardo |Ferreira |1234567899 |Street SDF |8602 |P12345 |Highly Durable Glue | 282 | |2 |84.02 |Tim |Berglund |9987654321 |Street UOI |1124 |P12345 |Highly Durable Glue | 283 | |3 |84.02 |Robin |Moffatt |4412356789 |Street YUP |9066 |P12345 |Highly Durable Glue | 284 | |4 |84.02 |Viktor |Gamov |9874563210 |Street SHT |12450 |P12345 |Highly Durable Glue | 285 | ``` 286 | 287 | 💡 The actual output includes more columns that what is shown above. 288 | 289 | #️⃣ Stop the containers from this scenario 290 | 291 | ```bash 292 | sh stop-stream-processing.sh 293 | ``` 294 | 295 | Alternatively, you can also stop all containers if you're done for the day. 296 | 297 | ```bash 298 | sh stop-everything.sh 299 | ``` 300 | 301 | ### This scenario was created based on the following tutorial: 302 | 303 | 🧑🏻‍💻 https://developer.confluent.io/tutorials/flatten-nested-data/ksql.html 304 | 305 | # License 306 | 307 | This project is licensed under the [Apache 2.0 License](./LICENSE). 308 | -------------------------------------------------------------------------------- /cdc-with-debezium/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | mysql: 6 | image: mysql:8.0 7 | container_name: mysql 8 | hostname: mysql 9 | environment: 10 | - MYSQL_ROOT_PASSWORD=debezium 11 | - MYSQL_USER=mysqluser 12 | - MYSQL_PASSWORD=mysqlpw 13 | volumes: 14 | - ${PWD}/mysql-data:/docker-entrypoint-initdb.d 15 | - ${PWD}/mysql-data:/data 16 | healthcheck: 17 | interval: 5s 18 | retries: 20 19 | test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] 20 | ports: 21 | - 3306:3306 22 | 23 | connect: 24 | image: confluentinc/cp-kafka-connect:7.0.5 25 | container_name: connect 26 | hostname: connect 27 | depends_on: 28 | mysql: 29 | condition: service_healthy 30 | ports: 31 | - 8083:8083 32 | environment: 33 | CONNECT_BOOTSTRAP_SERVERS: kafka-1:9092,kafka-2:9093 34 | CONNECT_GROUP_ID: kafka-connect 35 | CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter 36 | CONNECT_VALUE_CONVERTER: org.apache.kafka.connect.storage.StringConverter 37 | CONNECT_CONFIG_STORAGE_TOPIC: _connect-configs 38 | CONNECT_OFFSET_STORAGE_TOPIC: _connect-offsets 39 | CONNECT_STATUS_STORAGE_TOPIC: _connect-status 40 | CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1 41 | CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1 42 | CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1 43 | CONNECT_PLUGIN_PATH: /usr/share/java,/usr/share/confluent-hub-components,/data/connect-jars 44 | CONNECT_REST_ADVERTISED_HOST_NAME: "connect" 45 | CONNECT_REST_PORT: 8083 46 | command: 47 | - bash 48 | - -c 49 | - | 50 | echo "Installing Connector" 51 | confluent-hub install --no-prompt debezium/debezium-connector-mysql:1.9.3 52 | # 53 | echo "Launching Kafka Connect worker" 54 | /etc/confluent/docker/run & 55 | # 56 | sleep infinity 57 | healthcheck: 58 | interval: 5s 59 | retries: 20 60 | test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8083/connectors 61 | 62 | networks: 63 | default: 64 | name: is-using-kop-a-good-idea 65 | -------------------------------------------------------------------------------- /cdc-with-debezium/mysql-connector.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cdc-with-debezium", 3 | "config": { 4 | "connector.class": "io.debezium.connector.mysql.MySqlConnector", 5 | "tasks.max": "1", 6 | "database.hostname": "mysql", 7 | "database.port": "3306", 8 | "database.user": "debezium", 9 | "database.password": "dbz", 10 | "database.server.id": "184054", 11 | "database.server.name": "mysql", 12 | "database.include.list": "cdc_with_debezium", 13 | "database.history.kafka.bootstrap.servers": "kafka-1:9092,kafka-2:9093", 14 | "database.history.kafka.topic": "dbhistory.cdc_with_debezium" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cdc-with-debezium/mysql-data/00_setup_database.sql: -------------------------------------------------------------------------------- 1 | CREATE USER 'debezium'@'%' IDENTIFIED WITH mysql_native_password BY 'dbz'; 2 | CREATE USER 'replicator'@'%' IDENTIFIED BY 'replpass'; 3 | 4 | GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'debezium'; 5 | GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replicator'; 6 | 7 | create database cdc_with_debezium; 8 | 9 | GRANT ALL PRIVILEGES ON cdc_with_debezium.* TO 'mysqluser'@'%'; 10 | GRANT ALL PRIVILEGES ON cdc_with_debezium.* TO 'debezium'@'%'; 11 | -------------------------------------------------------------------------------- /cdc-with-debezium/mysql-data/01_create_table_customers.sql: -------------------------------------------------------------------------------- 1 | use cdc_with_debezium; 2 | 3 | create table customers ( 4 | id MEDIUMINT NOT NULL PRIMARY KEY, 5 | first_name VARCHAR(50), 6 | last_name VARCHAR(50), 7 | email VARCHAR(100) 8 | ); 9 | -------------------------------------------------------------------------------- /cdc-with-debezium/mysql-data/02_populate_customers.sql: -------------------------------------------------------------------------------- 1 | use cdc_with_debezium; 2 | 3 | insert into customers (id, first_name, last_name, email) values (1001, 'Sally', 'Thomas', 'sally.thomas@acme.com'); 4 | insert into customers (id, first_name, last_name, email) values (1002, 'George', 'Bailey', 'gbailey@foobar.com'); 5 | insert into customers (id, first_name, last_name, email) values (1003, 'Edward', 'Walker', 'ed@walker.com'); 6 | insert into customers (id, first_name, last_name, email) values (1004, 'Anne', 'Kretchmar', 'annek@noanswer.org'); 7 | -------------------------------------------------------------------------------- /images/pulsar-summit-session.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riferrei/is-using-kop-a-good-idea/770d1486b4b55b6f7da35c43b734120773582d71/images/pulsar-summit-session.png -------------------------------------------------------------------------------- /kill-container.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker kill $1 4 | docker rm -f $1 5 | -------------------------------------------------------------------------------- /microservice-with-kafka/.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .cache 3 | README.md 4 | 5 | .vscode 6 | docker-compose.yml 7 | run-microservice.sh 8 | target 9 | -------------------------------------------------------------------------------- /microservice-with-kafka/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | target 26 | .vscode 27 | -------------------------------------------------------------------------------- /microservice-with-kafka/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3.8.1-openjdk-17-slim 2 | 3 | VOLUME /tmp 4 | ADD . /usr/src/app 5 | WORKDIR /usr/src/app 6 | 7 | RUN mvn clean package -DskipTests 8 | ENTRYPOINT [ "java", "-jar", "target/five-seconds-tom-1.0.jar" ] 9 | -------------------------------------------------------------------------------- /microservice-with-kafka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.summit.pulsar.demo 7 | five-seconds-tom 8 | 1.0 9 | jar 10 | 11 | Spring Boot Microservice using Apache Pulsar with KoP enabled 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 2.7.2 17 | 18 | 19 | 20 | 17 21 | 17 22 | UTF-8 23 | org.summit.pulsar.demo.App 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | org.springframework.kafka 33 | spring-kafka 34 | 2.9.0 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-actuator 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /microservice-with-kafka/run-microservice.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | msWithKafkaFolder="microservice-with-kafka" 4 | workingDir=$PWD 5 | 6 | if [[ $workingDir != *$msWithKafkaFolder ]] 7 | then 8 | cd $msWithKafkaFolder 9 | fi 10 | 11 | mvn clean package -Dmaven.test.skip=true 12 | 13 | export BOOTSTRAP_SERVERS=localhost:9092 14 | java -jar target/five-seconds-tom-1.0.jar 15 | -------------------------------------------------------------------------------- /microservice-with-kafka/src/main/java/org/summit/pulsar/demo/App.java: -------------------------------------------------------------------------------- 1 | package org.summit.pulsar.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | @EnableScheduling 8 | @SpringBootApplication 9 | public class App { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(App.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /microservice-with-kafka/src/main/java/org/summit/pulsar/demo/Constants.java: -------------------------------------------------------------------------------- 1 | package org.summit.pulsar.demo; 2 | 3 | public interface Constants { 4 | 5 | public static final String TOPIC_NAME = "fiveSecondsTomTopic"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /microservice-with-kafka/src/main/java/org/summit/pulsar/demo/FiveSecondsTom.java: -------------------------------------------------------------------------------- 1 | package org.summit.pulsar.demo; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.kafka.annotation.KafkaListener; 8 | import org.springframework.kafka.core.KafkaTemplate; 9 | import org.springframework.messaging.handler.annotation.Payload; 10 | import org.springframework.scheduling.annotation.Scheduled; 11 | import org.springframework.stereotype.Service; 12 | 13 | import static org.summit.pulsar.demo.Constants.*; 14 | 15 | @Service 16 | public class FiveSecondsTom { 17 | 18 | private final Logger logger = LoggerFactory.getLogger(FiveSecondsTom.class); 19 | 20 | @Autowired 21 | private KafkaTemplate kafkaTemplate; 22 | 23 | @Scheduled(fixedRate = 5000) 24 | public void forgetAndMoveOn() { 25 | 26 | final String message = "Hi, I'm Tom 😄"; 27 | kafkaTemplate.send(TOPIC_NAME, message); 28 | 29 | } 30 | 31 | @KafkaListener(topics = Constants.TOPIC_NAME) 32 | public void sayHi(@Payload String message) { 33 | logger.info(message); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /microservice-with-kafka/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=five-seconds-tom 2 | spring.kafka.bootstrap-servers=${BOOTSTRAP_SERVERS} 3 | spring.kafka.producer.acks=1 4 | spring.kafka.consumer.group-id=five-seconds-tom-group 5 | -------------------------------------------------------------------------------- /microservice-with-kafka/src/test/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riferrei/is-using-kop-a-good-idea/770d1486b4b55b6f7da35c43b734120773582d71/microservice-with-kafka/src/test/resources/.gitkeep -------------------------------------------------------------------------------- /shared-infrastructure/brokers.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | kafka-1: 6 | image: streamnative/sn-pulsar:2.10.1.4 7 | container_name: kafka-1 8 | hostname: kafka-1 9 | command: > 10 | bash -c "bin/apply-config-from-env.py conf/broker.conf && 11 | exec bin/pulsar broker" 12 | environment: 13 | PULSAR_PREFIX_messagingProtocols: kafka 14 | PULSAR_PREFIX_allowAutoTopicCreationType: partitioned 15 | PULSAR_PREFIX_kafkaTransactionCoordinatorEnabled: "true" 16 | PULSAR_PREFIX_brokerDeleteInactiveTopicsEnabled: "false" 17 | PULSAR_PREFIX_kafkaListeners: PLAINTEXT://0.0.0.0:9092 18 | PULSAR_PREFIX_kafkaAdvertisedListeners: PLAINTEXT://kafka-1:9092 19 | PULSAR_PREFIX_brokerEntryMetadataInterceptors: org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor 20 | PULSAR_PREFIX_zookeeperServers: zookeeper:2181 21 | PULSAR_PREFIX_configurationStoreServers: zookeeper:2181 22 | PULSAR_PREFIX_clusterName: pulsar-cluster 23 | PULSAR_PREFIX_managedLedgerDefaultEnsembleSize: 1 24 | PULSAR_PREFIX_managedLedgerDefaultWriteQuorum: 1 25 | PULSAR_PREFIX_managedLedgerDefaultAckQuorum: 1 26 | ports: 27 | - 6650:6650 28 | - 8080:8080 29 | - 9092:9092 30 | healthcheck: 31 | interval: 5s 32 | retries: 20 33 | test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8080/admin/v2/clusters/pulsar-cluster 34 | 35 | kafka-2: 36 | image: streamnative/sn-pulsar:2.10.1.4 37 | container_name: kafka-2 38 | hostname: kafka-2 39 | command: > 40 | bash -c "bin/apply-config-from-env.py conf/broker.conf && 41 | exec bin/pulsar broker" 42 | environment: 43 | PULSAR_PREFIX_messagingProtocols: kafka 44 | PULSAR_PREFIX_allowAutoTopicCreationType: partitioned 45 | PULSAR_PREFIX_kafkaTransactionCoordinatorEnabled: "true" 46 | PULSAR_PREFIX_brokerDeleteInactiveTopicsEnabled: "false" 47 | PULSAR_PREFIX_kafkaListeners: PLAINTEXT://0.0.0.0:9093 48 | PULSAR_PREFIX_kafkaAdvertisedListeners: PLAINTEXT://kafka-2:9093 49 | PULSAR_PREFIX_brokerEntryMetadataInterceptors: org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor 50 | PULSAR_PREFIX_zookeeperServers: zookeeper:2181 51 | PULSAR_PREFIX_configurationStoreServers: zookeeper:2181 52 | PULSAR_PREFIX_clusterName: pulsar-cluster 53 | PULSAR_PREFIX_managedLedgerDefaultEnsembleSize: 1 54 | PULSAR_PREFIX_managedLedgerDefaultWriteQuorum: 1 55 | PULSAR_PREFIX_managedLedgerDefaultAckQuorum: 1 56 | ports: 57 | - 6651:6650 58 | - 8081:8080 59 | - 9093:9093 60 | healthcheck: 61 | interval: 5s 62 | retries: 20 63 | test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8080/admin/v2/clusters/pulsar-cluster 64 | 65 | networks: 66 | default: 67 | name: is-using-kop-a-good-idea 68 | -------------------------------------------------------------------------------- /shared-infrastructure/persistence.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | zookeeper: 6 | image: streamnative/sn-pulsar:2.10.1.4 7 | container_name: zookeeper 8 | hostname: zookeeper 9 | command: > 10 | bash -c "bin/apply-config-from-env.py conf/zookeeper.conf && 11 | exec bin/pulsar zookeeper" 12 | environment: 13 | PULSAR_PREFIX_clientPortAddress: zookeeper 14 | PULSAR_PREFIX_clientPort: 2181 15 | healthcheck: 16 | interval: 5s 17 | retries: 20 18 | test: echo ruok | nc zookeeper 2181 19 | 20 | init-cluster: 21 | image: streamnative/sn-pulsar:2.10.1.4 22 | container_name: init-cluster 23 | hostname: init-cluster 24 | depends_on: 25 | zookeeper: 26 | condition: service_healthy 27 | command: > 28 | bash -c "bin/pulsar initialize-cluster-metadata -c pulsar-cluster -zk zookeeper:2181 -cs zookeeper:2181 -uw http://pulsar-cluster-kafka-1:8080,pulsar-cluster-kafka-2:8080" 29 | 30 | bookie: 31 | image: streamnative/sn-pulsar:2.10.1.4 32 | deploy: 33 | mode: replicated 34 | replicas: 2 35 | endpoint_mode: vip 36 | depends_on: 37 | zookeeper: 38 | condition: service_healthy 39 | init-cluster: 40 | condition: service_completed_successfully 41 | command: > 42 | bash -c "bin/apply-config-from-env.py conf/bookkeeper.conf && 43 | exec bin/bookkeeper bookie" 44 | environment: 45 | PULSAR_PREFIX_zkServers: zookeeper:2181 46 | PULSAR_PREFIX_useHostNameAsBookieID: "true" 47 | PULSAR_PREFIX_bookiePort: 3181 48 | healthcheck: 49 | interval: 5s 50 | retries: 20 51 | test: echo ruok | nc localhost 3181 52 | 53 | networks: 54 | default: 55 | name: is-using-kop-a-good-idea 56 | -------------------------------------------------------------------------------- /start-brokers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name brokers --file shared-infrastructure/brokers.yml up -d 4 | -------------------------------------------------------------------------------- /start-cdc-with-debezium.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd cdc-with-debezium 4 | docker compose --project-name cdc-with-debezium --file docker-compose.yml up -d 5 | cd ../ 6 | -------------------------------------------------------------------------------- /start-persistence.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name persistence --file shared-infrastructure/persistence.yml up -d 4 | -------------------------------------------------------------------------------- /start-stream-processing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name stream-processing --file stream-processing/docker-compose.yml up -d 4 | -------------------------------------------------------------------------------- /stop-brokers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name brokers --file shared-infrastructure/brokers.yml down 4 | -------------------------------------------------------------------------------- /stop-cdc-with-debezium.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name cdc-with-debezium --file cdc-with-debezium/docker-compose.yml down 4 | -------------------------------------------------------------------------------- /stop-everything.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./stop-stream-processing.sh 4 | ./stop-cdc-with-debezium.sh 5 | ./stop-brokers.sh 6 | ./stop-persistence.sh 7 | -------------------------------------------------------------------------------- /stop-persistence.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name persistence --file shared-infrastructure/persistence.yml down 4 | -------------------------------------------------------------------------------- /stop-stream-processing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker compose --project-name stream-processing --file stream-processing/docker-compose.yml down 4 | -------------------------------------------------------------------------------- /stream-processing/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | schema-registry: 6 | image: confluentinc/cp-schema-registry:7.0.5 7 | container_name: schema-registry 8 | hostname: schema-registry 9 | environment: 10 | SCHEMA_REGISTRY_HOST_NAME: schema-registry 11 | SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka-1:9092,kafka-2:9093 12 | SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:7081 13 | ports: 14 | - 7081:7081 15 | healthcheck: 16 | interval: 5s 17 | retries: 20 18 | test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:7081 19 | 20 | ksqldb-server: 21 | image: confluentinc/cp-ksqldb-server:7.0.5 22 | container_name: ksqldb-server 23 | hostname: ksqldb-server 24 | depends_on: 25 | schema-registry: 26 | condition: service_healthy 27 | environment: 28 | KSQL_BOOTSTRAP_SERVERS: kafka-1:9092,kafka-2:9093 29 | KSQL_HOST_NAME: ksqldb-server 30 | KSQL_LISTENERS: http://0.0.0.0:8088 31 | KSQL_KSQL_SCHEMA_REGISTRY_URL: http://schema-registry:7081 32 | ports: 33 | - 8088:8088 34 | healthcheck: 35 | interval: 5s 36 | retries: 20 37 | test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8088/info 38 | 39 | networks: 40 | default: 41 | name: is-using-kop-a-good-idea 42 | -------------------------------------------------------------------------------- /stream-processing/statements.sql: -------------------------------------------------------------------------------- 1 | CREATE STREAM ORDERS ( 2 | id VARCHAR, 3 | timestamp VARCHAR, 4 | amount DOUBLE, 5 | customer STRUCT>, 13 | product STRUCT>) 17 | WITH (KAFKA_TOPIC = 'ORDERS', 18 | VALUE_FORMAT = 'JSON', 19 | TIMESTAMP = 'TIMESTAMP', 20 | TIMESTAMP_FORMAT = 'yyyy-MM-dd HH:mm:ss', 21 | PARTITIONS = 1); 22 | 23 | CREATE STREAM FLATTENED_ORDERS 24 | WITH (VALUE_FORMAT = 'PROTOBUF') AS 25 | SELECT 26 | ID AS ORDER_ID, 27 | TIMESTAMP AS ORDER_TS, 28 | AMOUNT AS ORDER_AMOUNT, 29 | CUSTOMER->FIRSTNAME AS CUST_FIRST_NAME, 30 | CUSTOMER->LASTNAME AS CUST_LAST_NAME, 31 | CUSTOMER->PHONENUMBER AS CUST_PHONE_NUMBER, 32 | CUSTOMER->ADDRESS->STREET AS CUST_ADDR_STREET, 33 | CUSTOMER->ADDRESS->NUMBER AS CUST_ADDR_NUMBER, 34 | CUSTOMER->ADDRESS->ZIPCODE AS CUST_ADDR_ZIPCODE, 35 | CUSTOMER->ADDRESS->CITY AS CUST_ADDR_CITY, 36 | CUSTOMER->ADDRESS->STATE AS CUST_ADDR_STATE, 37 | PRODUCT->SKU AS PROD_SKU, 38 | PRODUCT->NAME AS PROD_NAME, 39 | PRODUCT->VENDOR->VENDORNAME AS PROD_VENDOR_NAME, 40 | PRODUCT->VENDOR->COUNTRY AS PROD_VENDOR_COUNTRY 41 | FROM 42 | ORDERS; -------------------------------------------------------------------------------- /view-container-logs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker logs -f $1 4 | --------------------------------------------------------------------------------