├── .env ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── avro-model ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── avro-model.iml ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ └── resources │ └── avro │ └── stock-quote-v1.avsc ├── docker-compose-monitoring.yml ├── docker-compose.yml ├── documentation └── project-overview.png ├── http-calls ├── rest-api-requests.http └── schema-registry-requests.http ├── monitoring ├── grafana │ ├── dashboards │ │ ├── jvm-micrometer_rev9.json │ │ ├── kafka-cluster-confluent.json │ │ ├── kafka-consumer-community.json │ │ └── kafka-topics-confluent.json │ └── provisioning │ │ ├── dashboards │ │ └── grafana-dashboard.yml │ │ └── datasources │ │ └── grafana-datasource.yml ├── jmx-exporter │ ├── jmx_prometheus_javaagent-0.16.1.jar │ └── kafka_broker.yml └── prometheus │ └── prometheus.yml ├── mvnw ├── mvnw.cmd ├── pom.xml ├── spring-kafka-consumer ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── nl │ │ │ └── jtim │ │ │ └── spring │ │ │ └── kafka │ │ │ └── consumer │ │ │ ├── ShakyStockQuoteService.java │ │ │ ├── SpringKafkaConsumerApplication.java │ │ │ ├── StockQuoteConsumer.java │ │ │ ├── StockQuoteService.java │ │ │ └── config │ │ │ └── KafkaExceptionHandlingConfiguration.java │ └── resources │ │ └── application.yml │ └── test │ ├── java │ └── nl │ │ └── jtim │ │ └── spring │ │ └── kafka │ │ └── consumer │ │ ├── EmbeddedKafkaAvroExampleIntegrationTest.java │ │ ├── KafkaMockSchemaRegistryTestConfiguration.java │ │ ├── KafkaTestContainersIntegrationTest.java │ │ ├── KafkaTestTopicTestConfiguration.java │ │ └── SpringKafkaConsumerApplicationTests.java │ └── resources │ └── application.yml ├── spring-kafka-producer ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── nl │ │ │ └── jtim │ │ │ └── spring │ │ │ └── kafka │ │ │ └── producer │ │ │ ├── ScheduledStockQuoteProducer.java │ │ │ ├── SpringKafkaProducerApplication.java │ │ │ ├── StockQuoteProducer.java │ │ │ ├── config │ │ │ ├── KafkaProducerConfiguration.java │ │ │ ├── KafkaTopicsConfiguration.java │ │ │ └── SchedulingConfiguration.java │ │ │ ├── generator │ │ │ ├── AbstractRandomStockQuoteGenerator.java │ │ │ └── RandomStockQuoteGenerator.java │ │ │ └── rest │ │ │ ├── RestResource.java │ │ │ └── StockQuoteRequest.java │ └── resources │ │ └── application.yml │ └── test │ ├── java │ └── nl │ │ └── jtim │ │ └── spring │ │ └── kafka │ │ └── producer │ │ └── SpringKafkaProducerApplicationTests.java │ └── resources │ └── application.yml └── spring-kafka-streams ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── nl │ │ └── jtim │ │ └── kafka │ │ └── streams │ │ ├── SpringKafkaStreamsApplication.java │ │ └── config │ │ ├── KafkaStreamsConfig.java │ │ ├── KafkaStreamsExceptionHandlingConfig.java │ │ └── KafkaTopicsConfiguration.java └── resources │ └── application.yml └── test └── java └── nl └── jtim └── kafka └── streams └── TopologyTestDriverAvroTest.java /.env: -------------------------------------------------------------------------------- 1 | TZ=Europe/Amsterdam 2 | 3 | # https://docs.confluent.io/platform/current/installation/versions-interoperability.html 4 | # Confluent Platform: 5.5.x = Apache Kafka: 2.5.x 5 | # Confluent Platform: 6.0.x = Apache Kafka: 2.6.x 6 | # Confluent Platform: 6.1.x = Apache Kafka: 2.7.x 7 | # Confluent Platform: 6.2.x = Apache Kafka: 2.8.x 8 | # Confluent Platform: 7.0.x = Apache Kafka: 3.0.x 9 | # Confluent Platform: 7.1.x = Apache Kafka: 3.1.x 10 | CONFLUENT_PLATFORM_VERSION=7.1.0 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring I/O Barcelona 2022 - Spring Kafka beyond the basics 2 | 3 | Codebase for [my talk on Spring I/O 2022](https://2022.springio.net/sessions/spring-kafka-beyond-the-basics-lessons-learned-on-our-kafka-journey-at-ing-bank) in Barcelona about Spring for Apache Kafka 4 | 5 | [Slides](https://speakerdeck.com/timvanbaarsen/spring-kafka-beyond-the-basics-lessons-learned-on-our-kafka-journey-at-ing-bank) 6 | 7 | For a more up to date version please also take a look at the code base I used for my talk at JFall 2022: 8 | [https://github.com/j-tim/jfall-2022-spring-kafka-beyond-the-basics](https://github.com/j-tim/jfall-2022-spring-kafka-beyond-the-basics) 9 | 10 | ## Project modules and applications 11 | 12 | | Applications | Port | Avro | Topic(s) | Description | 13 | |--------------------------------|------|-------|---------------|--------------------------------------------------------------------------| 14 | | spring-kafka-producer | 8080 | YES | stock-quotes | Simple producer of random stock quotes using Spring Kafka & Apache Avro. | 15 | | spring-kafka-consumer | 8082 | YES | stock-quotes | Simple consumer of stock quotes using using Spring Kafka & Apache Avro. | 16 | | spring-kafka-streams | 8083 | YES | stock-quotes | Simple Kafka Streams application using Spring Kafka & Apache Avro. | 17 | 18 | | Module | Description | 19 | |------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 20 | | avro-model | Holds the Avro schema for the Stock Quote including `avro-maven-plugin` to generate Java code based on the Avro Schema. This module is used by both the producer, consumer and Kafka streams application. | 21 | 22 | Note Confluent Schema Registry is running on port: `8081` using Docker see: [docker-compose.yml](docker-compose.yml). 23 | 24 | 25 | ![](documentation/project-overview.png) 26 | 27 | ## Version 28 | 29 | * Confluent Kafka 7.1.x 30 | * Confluent Schema Registry 7.1.x 31 | * Java 11 32 | * Spring Boot 2.6.x 33 | * Spring Kafka 2.8.5 34 | * Apache Avro 1.11 35 | 36 | ## Components running in Docker 37 | 38 | * Kafka (port 9092) 39 | * Zookeeper (port 2181) 40 | * [Schema Registry](http://localhost:8081) 41 | * [Kafka UI](http://localhost:9000) 42 | * [Zipkin](http://localhost:9411) 43 | * [Prometheus](http://localhost:9090) 44 | * [Grafana](http://localhost:3000/) 45 | 46 | ## Build 47 | 48 | ``` 49 | ./mvnw clean package 50 | ``` 51 | 52 | ## Run 53 | 54 | ### without monitoring 55 | 56 | ``` 57 | docker-compose up -d 58 | ``` 59 | 60 | ### with monitoring 61 | 62 | ``` 63 | docker-compose -f docker-compose.yml -f docker-compose-monitoring.yml up -d 64 | ``` 65 | 66 | ## Poison pill scenario: Deserialization exceptions 67 | 68 | Start the Kafka console producer from the command line 69 | 70 | ``` 71 | docker exec -it kafka bash 72 | unset JMX_PORT 73 | ``` 74 | 75 | ``` 76 | kafka-console-producer --bootstrap-server localhost:9092 --topic stock-quotes 77 | ``` 78 | 79 | The console is waiting for input. Now publish the poison pill: 80 | 81 | ``` 82 | 💊 83 | ``` 84 | 85 | Result: 86 | 87 | Kafka streams application: 88 | 89 | * Streams thread will stop 90 | 91 | ``` 92 | 2022-05-23 14:44:00.014 INFO [streams-application,,] 20635 --- [-StreamThread-1] o.a.k.s.p.internals.StreamThread : stream-thread [streams-application-6095314e-a3d3-4027-8215-dc9270a3b341-StreamThread-1] Shutdown complete 93 | Exception in thread "streams-application-6095314e-a3d3-4027-8215-dc9270a3b341-StreamThread-1" org.apache.kafka.streams.errors.StreamsException: Deserialization exception handler is set to fail upon a deserialization error. If you would rather have the streaming pipeline continue after a deserialization error, please set the default.deserialization.exception.handler appropriately. 94 | at org.apache.kafka.streams.processor.internals.RecordDeserializer.deserialize(RecordDeserializer.java:83) 95 | at org.apache.kafka.streams.processor.internals.RecordQueue.updateHead(RecordQueue.java:176) 96 | at org.apache.kafka.streams.processor.internals.RecordQueue.addRawRecords(RecordQueue.java:112) 97 | at org.apache.kafka.streams.processor.internals.PartitionGroup.addRawRecords(PartitionGroup.java:304) 98 | at org.apache.kafka.streams.processor.internals.StreamTask.addRecords(StreamTask.java:960) 99 | at org.apache.kafka.streams.processor.internals.TaskManager.addRecordsToTasks(TaskManager.java:1000) 100 | at org.apache.kafka.streams.processor.internals.StreamThread.pollPhase(StreamThread.java:914) 101 | at org.apache.kafka.streams.processor.internals.StreamThread.runOnce(StreamThread.java:720) 102 | at org.apache.kafka.streams.processor.internals.StreamThread.runLoop(StreamThread.java:583) 103 | at org.apache.kafka.streams.processor.internals.StreamThread.run(StreamThread.java:555) 104 | Caused by: org.apache.kafka.common.errors.SerializationException: Unknown magic byte! 105 | at io.confluent.kafka.serializers.AbstractKafkaSchemaSerDe.getByteBuffer(AbstractKafkaSchemaSerDe.java:250) 106 | at io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer$DeserializationContext.(AbstractKafkaAvroDeserializer.java:322) 107 | at io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer.deserialize(AbstractKafkaAvroDeserializer.java:112) 108 | at io.confluent.kafka.serializers.KafkaAvroDeserializer.deserialize(KafkaAvroDeserializer.java:55) 109 | at io.confluent.kafka.streams.serdes.avro.SpecificAvroDeserializer.deserialize(SpecificAvroDeserializer.java:66) 110 | at io.confluent.kafka.streams.serdes.avro.SpecificAvroDeserializer.deserialize(SpecificAvroDeserializer.java:38) 111 | at org.apache.kafka.common.serialization.Deserializer.deserialize(Deserializer.java:60) 112 | at org.apache.kafka.streams.processor.internals.SourceNode.deserializeValue(SourceNode.java:58) 113 | at org.apache.kafka.streams.processor.internals.RecordDeserializer.deserialize(RecordDeserializer.java:66) 114 | ... 9 more 115 | ``` 116 | 117 | Consumer application: 118 | 119 | * Will end up in an infinite loop of Deserialization exceptions 120 | 121 | ``` 122 | 2022-05-23 14:44:22.864 ERROR [consumer-application,,] 20179 --- [eListener-0-C-1] o.s.k.l.KafkaMessageListenerContainer : Consumer exception 123 | 124 | java.lang.IllegalStateException: This error handler cannot process 'SerializationException's directly; please consider configuring an 'ErrorHandlingDeserializer' in the value and/or key deserializer 125 | at org.springframework.kafka.listener.DefaultErrorHandler.handleOtherException(DefaultErrorHandler.java:149) ~[spring-kafka-2.8.5.jar:2.8.5] 126 | at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.handleConsumerException(KafkaMessageListenerContainer.java:1790) ~[spring-kafka-2.8.5.jar:2.8.5] 127 | at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1297) ~[spring-kafka-2.8.5.jar:2.8.5] 128 | at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na] 129 | at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na] 130 | at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na] 131 | Caused by: org.apache.kafka.common.errors.RecordDeserializationException: Error deserializing key/value for partition stock-quotes-0 at offset 76. If needed, please seek past the record to continue consumption. 132 | at org.apache.kafka.clients.consumer.internals.Fetcher.parseRecord(Fetcher.java:1429) ~[kafka-clients-3.0.1.jar:na] 133 | at org.apache.kafka.clients.consumer.internals.Fetcher.access$3400(Fetcher.java:134) ~[kafka-clients-3.0.1.jar:na] 134 | at org.apache.kafka.clients.consumer.internals.Fetcher$CompletedFetch.fetchRecords(Fetcher.java:1652) ~[kafka-clients-3.0.1.jar:na] 135 | at org.apache.kafka.clients.consumer.internals.Fetcher$CompletedFetch.access$1800(Fetcher.java:1488) ~[kafka-clients-3.0.1.jar:na] 136 | at org.apache.kafka.clients.consumer.internals.Fetcher.fetchRecords(Fetcher.java:721) ~[kafka-clients-3.0.1.jar:na] 137 | at org.apache.kafka.clients.consumer.internals.Fetcher.fetchedRecords(Fetcher.java:672) ~[kafka-clients-3.0.1.jar:na] 138 | at org.apache.kafka.clients.consumer.KafkaConsumer.pollForFetches(KafkaConsumer.java:1277) ~[kafka-clients-3.0.1.jar:na] 139 | at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1238) ~[kafka-clients-3.0.1.jar:na] 140 | at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1166) ~[kafka-clients-3.0.1.jar:na] 141 | at jdk.internal.reflect.GeneratedMethodAccessor89.invoke(Unknown Source) ~[na:na] 142 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] 143 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] 144 | at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.19.jar:5.3.19] 145 | at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-5.3.19.jar:5.3.19] 146 | at com.sun.proxy.$Proxy138.poll(Unknown Source) ~[na:na] 147 | at brave.kafka.clients.TracingConsumer.poll(TracingConsumer.java:89) ~[brave-instrumentation-kafka-clients-5.13.7.jar:na] 148 | at brave.kafka.clients.TracingConsumer.poll(TracingConsumer.java:83) ~[brave-instrumentation-kafka-clients-5.13.7.jar:na] 149 | at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollConsumer(KafkaMessageListenerContainer.java:1521) ~[spring-kafka-2.8.5.jar:2.8.5] 150 | at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doPoll(KafkaMessageListenerContainer.java:1511) ~[spring-kafka-2.8.5.jar:2.8.5] 151 | at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:1339) ~[spring-kafka-2.8.5.jar:2.8.5] 152 | at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1251) ~[spring-kafka-2.8.5.jar:2.8.5] 153 | ... 3 common frames omitted 154 | Caused by: org.apache.kafka.common.errors.SerializationException: Unknown magic byte! 155 | at io.confluent.kafka.serializers.AbstractKafkaSchemaSerDe.getByteBuffer(AbstractKafkaSchemaSerDe.java:250) ~[kafka-schema-serializer-7.1.0.jar:na] 156 | at io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer$DeserializationContext.(AbstractKafkaAvroDeserializer.java:322) ~[kafka-avro-serializer-7.1.0.jar:na] 157 | at io.confluent.kafka.serializers.AbstractKafkaAvroDeserializer.deserialize(AbstractKafkaAvroDeserializer.java:112) ~[kafka-avro-serializer-7.1.0.jar:na] 158 | at io.confluent.kafka.serializers.KafkaAvroDeserializer.deserialize(KafkaAvroDeserializer.java:55) ~[kafka-avro-serializer-7.1.0.jar:na] 159 | at org.apache.kafka.common.serialization.Deserializer.deserialize(Deserializer.java:60) ~[kafka-clients-3.0.1.jar:na] 160 | at org.apache.kafka.clients.consumer.internals.Fetcher.parseRecord(Fetcher.java:1420) ~[kafka-clients-3.0.1.jar:na] 161 | ... 23 common frames omitted 162 | ``` 163 | 164 | Magic byte? 165 | 166 | The first byte of the message is a magic byte marker. 167 | This as an Avro serialized message. 168 | Without the magic byte marker the KafkaAvroDeserializer will refuse to read the message! 169 | Since we published a message without Avro using the console consumer we don't have a magic byte. 170 | 171 | After configuring the dead letter topic recoverer you should see something in you log file like: 172 | 173 | ``` 174 | 2022-05-23 15:49:51.969 DEBUG [consumer-application,14f637ce05adcec2,5263c9f7713ba810] 50590 --- [ad | producer-1] o.s.k.l.DeadLetterPublishingRecoverer : Successful dead-letter publication: stock-quotes-1@2270 to stock-quotes.DLT-1@0 175 | ``` 176 | 177 | ## Exception handling in consumer 178 | 179 | Publish a record to Kafka to trigger an exception in the StockQuoteConsumer see: ShakyStockQuoteService. 180 | 181 | ``` 182 | curl -v -X POST http://localhost:8080/api/quotes -H 'Content-Type: application/json' -d '{ "symbol": "KABOOM", "exchange": "AMS", "tradeValue": "101.99", "currency": "EUR", "description": "Trigger exception!" }' 183 | ``` 184 | 185 | Or using IntelliJ http client [rest-api-requests.http](http-calls/rest-api-requests.http) 186 | 187 | ## More advances configuration 188 | 189 | ### Error handling based on exception type 190 | 191 | In case you want to send messages to handle exception in a different way take a look at Spring Kafka's: CommonDelegatingErrorHandler. 192 | 193 | See Spring Kafka [documentation](https://docs.spring.io/spring-kafka/docs/current/reference/html/#cond-eh) 194 | 195 | ### Publish to different deadletter topic based on exception type 196 | 197 | In case you want to send messages to different dead letter topics based on the exception take a look at custom destination resolvers: 198 | 199 | ``` 200 | private static final BiFunction, Exception, TopicPartition> CUSTOM_DESTINATION_RESOLVER = (record, exception) -> { 201 | 202 | if (exception.getCause() != null && exception.getCause() instanceof DeserializationException) { 203 | return new TopicPartition(record.topic() + ".deserialization.failures", record.partition()); 204 | } 205 | 206 | if (exception.getCause() instanceof MethodArgumentNotValidException) { 207 | return new TopicPartition(record.topic() + ".validation.failures", record.partition()); 208 | } 209 | 210 | else { 211 | return new TopicPartition(record.topic() + ".other.failures", record.partition()); 212 | } 213 | }; 214 | 215 | @Bean 216 | public DeadLetterPublishingRecoverer recoverer(KafkaTemplate bytesKafkaTemplate, KafkaTemplate kafkaTemplate) { 217 | Map, KafkaOperations> templates = new LinkedHashMap<>(); 218 | templates.put(byte[].class, bytesKafkaTemplate); 219 | templates.put(StockQuote.class, kafkaTemplate); 220 | return new DeadLetterPublishingRecoverer(templates, CUSTOM_DESTINATION_RESOLVER); 221 | } 222 | ``` 223 | 224 | ## Shutdown 225 | 226 | ``` 227 | docker-compose down -v 228 | ``` 229 | 230 | ``` 231 | docker-compose -f docker-compose.yml -f docker-compose-monitoring.yml down -v 232 | ``` 233 | -------------------------------------------------------------------------------- /avro-model/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /avro-model/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/avro-model/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /avro-model/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /avro-model/avro-model.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /avro-model/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /avro-model/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /avro-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | nl.jtim 6 | avro-model 7 | 0.0.1-SNAPSHOT 8 | avro-model 9 | Module for Avro files and Java Generated Code 10 | 11 | 12 | 13 | 11 14 | 11 15 | true 16 | UTF-8 17 | 18 | 1.11.0 19 | UTF-8 20 | 21 | 22 | 23 | 24 | 25 | org.apache.avro 26 | avro 27 | ${avro.version} 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.apache.avro 36 | avro-maven-plugin 37 | ${avro.version} 38 | 39 | 40 | generate-sources 41 | 42 | schema 43 | 44 | 45 | src/main/resources/avro 46 | ${project.build.directory}/generated-sources 47 | PRIVATE 48 | String 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /avro-model/src/main/resources/avro/stock-quote-v1.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "nl.jtim.spring.kafka.avro.stock.quote", 3 | "type": "record", 4 | "name": "StockQuote", 5 | "version": 1, 6 | "doc": "Avro schema for our stock quote.", 7 | "fields": [ 8 | { 9 | "name": "symbol", 10 | "type": "string", 11 | "doc": "The identifier of the stock." 12 | }, 13 | { 14 | "name": "exchange", 15 | "type": "string", 16 | "doc": "The stock exchange the stock was traded." 17 | }, 18 | { 19 | "name": "tradeValue", 20 | "type": "string", 21 | "doc": "The value the stock was traded for." 22 | }, 23 | { 24 | "name": "currency", 25 | "type": "string", 26 | "doc": "The currency the stock was traded in." 27 | }, 28 | { 29 | "name": "description", 30 | "type": "string", 31 | "doc": "Description about the stock." 32 | }, 33 | { 34 | "name": "tradeTime", 35 | "type": { 36 | "type": "long", 37 | "logicalType": "timestamp-millis" 38 | }, 39 | "doc": "Epoch millis timestamp at which the stock trade took place." 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /docker-compose-monitoring.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | # On linux make sure you have set DOCKER_HOST_IP=172.17.0.1 4 | # Get the correct IP address from docker0 interface by executing: ifconfig 5 | 6 | services: 7 | 8 | # This docker-compose file contains all the monitoring setup. 9 | # Please remember the Kafka service is already configured to expose metrics see docker-compose.yml! 10 | # To run the stack with monitoring: docker-compose -f docker-compose.yml -f docker-compose-monitoring.yml up -d 11 | 12 | # https://hub.docker.com/r/grafana/grafana 13 | # http://localhost:3000 14 | grafana: 15 | image: grafana/grafana:7.5.15 16 | container_name: grafana 17 | environment: 18 | TZ: ${TZ} 19 | GF_USERS_ALLOW_SIGN_UP: "false" 20 | GF_AUTH_DISABLE_LOGIN_FORM: "true" 21 | GF_AUTH_ANONYMOUS_ENABLED: "true" 22 | GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin" 23 | ports: 24 | - 3000:3000 25 | volumes: 26 | - ${PWD}/monitoring/grafana/provisioning/datasources/grafana-datasource.yml:/etc/grafana/provisioning/datasources/grafana-datasource.yml 27 | - ${PWD}/monitoring/grafana/provisioning/dashboards/grafana-dashboard.yml:/etc/grafana/provisioning/dashboards/grafana-dashboard.yml 28 | - ${PWD}/monitoring/grafana/dashboards:/etc/grafana/dashboards 29 | depends_on: 30 | - prometheus 31 | 32 | # https://hub.docker.com/r/prom/prometheus 33 | # http://localhost:9090 34 | prometheus: 35 | image: prom/prometheus:v2.35.0 36 | container_name: prometheus 37 | environment: 38 | TZ: ${TZ} 39 | ports: 40 | - 9090:9090 41 | extra_hosts: 42 | - "host.docker.internal:host-gateway" 43 | volumes: 44 | - ${PWD}/monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | # Docker compose file format 3.7 Required Docker Engine 18.06.0+ 2 | # For more information see: https://docs.docker.com/compose/compose-file/compose-versioning/ 3 | version: '3.7' 4 | 5 | services: 6 | 7 | # Confluent Kafka Docker image see: https://hub.docker.com/r/confluentinc/cp-kafka/ 8 | # Confluent Platform and Apache Kafka Compatibility: 9 | # https://docs.confluent.io/current/installation/versions-interoperability.html 10 | kafka: 11 | image: confluentinc/cp-kafka:${CONFLUENT_PLATFORM_VERSION} 12 | container_name: kafka 13 | hostname: kafka 14 | # Just in case Zookeeper isn't up yet restart 15 | restart: always 16 | environment: 17 | # KAFKA_ADVERTISED_LISTENERS: comma-separated list of listeners with their the host/ip and port. 18 | # This is the metadata that’s passed back to clients. 19 | # LISTENER_DOCKER_INTERNAL: This will make Kafka accessible from outside of the Docker network (your machine) port: 9092. 20 | # LISTENER_DOCKER_EXTERNAL: This will make Kafka accessible to other Docker containers by advertising it’s 21 | # location on the Docker network port: 29092 22 | KAFKA_LISTENERS: LISTENER_DOCKER_INTERNAL://:29092,LISTENER_DOCKER_EXTERNAL://:9092 23 | KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka:29092,LISTENER_DOCKER_EXTERNAL://localhost:9092 24 | # Key/value pairs for the security protocol to use, per listener name 25 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT 26 | # The same ZooKeeper port is specified here as the previous container. 27 | KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 28 | KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL 29 | # The KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR is set to 1 for a single-node cluster. Unless you have three or more 30 | # nodes you do not need to change this from the default. 31 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 32 | KAFKA_DEFAULT_REPLICATION_FACTOR: 1 33 | KAFKA_NUM_PARTITIONS: 3 34 | # Whether or not to auto create topics when data is published for the first time to a topic 35 | KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true" 36 | JMX_PORT: 9999 37 | KAFKA_JMX_OPTS: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=kafka -Dcom.sun.management.jmxremote.rmi.port=9999 38 | KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO" 39 | CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous' 40 | KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer 41 | KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: 'true' 42 | EXTRA_ARGS: -javaagent:/usr/share/jmx-exporter/jmx_prometheus_javaagent-0.16.1.jar=1234:/usr/share/jmx-exporter/kafka_broker.yml 43 | ports: 44 | - 9092:9092 45 | - 9999:9999 46 | volumes: 47 | - ${PWD}/monitoring/jmx-exporter/:/usr/share/jmx-exporter 48 | depends_on: 49 | - zookeeper 50 | 51 | # Confluent Zookeeper Docker image see: https://hub.docker.com/r/confluentinc/cp-zookeeper/ 52 | zookeeper: 53 | container_name: zookeeper 54 | hostname: zookeeper 55 | image: confluentinc/cp-zookeeper:${CONFLUENT_PLATFORM_VERSION} 56 | environment: 57 | ZOOKEEPER_CLIENT_PORT: 2181 58 | ports: 59 | - 2181:2181 60 | 61 | # Confluent Schema Registry Docker image see: https://hub.docker.com/r/confluentinc/cp-schema-registry 62 | # Schema Registry: http://localhost:8081 63 | schema-registry: 64 | image: confluentinc/cp-schema-registry:${CONFLUENT_PLATFORM_VERSION} 65 | hostname: schema-registry 66 | container_name: schema-registry 67 | restart: always 68 | environment: 69 | # Connects to the docker internal network port: 29092 70 | SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: "kafka:29092" 71 | SCHEMA_REGISTRY_HOST_NAME: schema-registry 72 | SCHEMA_REGISTRY_LISTENERS: "http://0.0.0.0:8081" 73 | ports: 74 | - 8081:8081 75 | depends_on: 76 | - zookeeper 77 | 78 | kafka-ui: 79 | image: provectuslabs/kafka-ui:latest 80 | container_name: kafka-ui 81 | environment: 82 | KAFKA_CLUSTERS_0_NAME: local 83 | KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092 84 | KAFKA_CLUSTERS_0_JMXPORT: 9999 85 | KAFKA_CLUSTERS_0_SCHEMAREGISTRY: "http://schema-registry:8081" 86 | depends_on: 87 | - kafka 88 | ports: 89 | - 9000:8080 90 | 91 | # The zipkin process services the UI, and also exposes a POST endpoint that 92 | # instrumentation can send trace data to. Scribe is disabled by default. 93 | # Zipkin: http://localhost:9411 94 | zipkin: 95 | image: openzipkin/zipkin 96 | container_name: zipkin 97 | ports: 98 | # Port used for the Zipkin UI and HTTP Api 99 | - 9411:9411 100 | environment: 101 | JAVA_OPTS: "-Xms1024m -Xmx2048m -XX:+ExitOnOutOfMemoryError" -------------------------------------------------------------------------------- /documentation/project-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/documentation/project-overview.png -------------------------------------------------------------------------------- /http-calls/rest-api-requests.http: -------------------------------------------------------------------------------- 1 | ### Produce to Kafka (via Rest API) to an trigger exception in the consumer. 2 | 3 | POST http://localhost:8080/api/quotes 4 | Content-Type: application/json 5 | 6 | { 7 | "symbol": "KABOOM", 8 | "exchange": "AMS", 9 | "tradeValue": "101.99", 10 | "currency": "EUR", 11 | "description": "Trigger exception!" 12 | } -------------------------------------------------------------------------------- /http-calls/schema-registry-requests.http: -------------------------------------------------------------------------------- 1 | ### Check Schema registry is up and running 2 | 3 | GET http://localhost:8081 4 | Accept: application/json 5 | 6 | ### Show subjects 7 | 8 | GET http://localhost:8081/subjects 9 | Accept: application/json 10 | 11 | ### Delete subject 12 | 13 | DELETE http://localhost:8081/subjects/stock-quotes-value/versions/1?permanent=true 14 | 15 | ### Delete most recent 16 | 17 | DELETE http://localhost:8081/subjects/stock-quotes-value/versions/latest 18 | 19 | ### Show versions 20 | 21 | GET http://localhost:8081/subjects/stock-quotes-value/versions 22 | 23 | ### Show schema of specific subject version 24 | 25 | GET http://localhost:8081/subjects/stock-quotes-value/versions/1 26 | 27 | ### Show schema of specific subject version 2 28 | 29 | GET http://localhost:8081/subjects/stock-quotes-value/versions/2 30 | 31 | ### Show schemas 32 | 33 | GET http://localhost:8081/schemas 34 | Accept: application/json 35 | 36 | ### Show schema by specific id 37 | 38 | GET http://localhost:8081/schemas/ids/1 39 | Accept: application/json -------------------------------------------------------------------------------- /monitoring/grafana/provisioning/dashboards/grafana-dashboard.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | providers: 4 | - name: 'default' 5 | folder: 'Dashboards' 6 | type: file 7 | options: 8 | path: /etc/grafana/dashboards 9 | -------------------------------------------------------------------------------- /monitoring/grafana/provisioning/datasources/grafana-datasource.yml: -------------------------------------------------------------------------------- 1 | apiVersion: 1 2 | 3 | datasources: 4 | - name: prometheus 5 | type: prometheus 6 | access: direct 7 | # Note Grafana will do calls from the frontend! So don't change this to the docker host name! 8 | url: http://localhost:9090 9 | isDefault: true -------------------------------------------------------------------------------- /monitoring/jmx-exporter/jmx_prometheus_javaagent-0.16.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/monitoring/jmx-exporter/jmx_prometheus_javaagent-0.16.1.jar -------------------------------------------------------------------------------- /monitoring/jmx-exporter/kafka_broker.yml: -------------------------------------------------------------------------------- 1 | --- 2 | startDelaySeconds: 10 3 | lowercaseOutputName: true 4 | lowercaseOutputLabelNames: true 5 | blacklistObjectNames: 6 | - "kafka.consumer:type=*,id=*" 7 | - "kafka.consumer:type=*,client-id=*" 8 | - "kafka.consumer:type=*,client-id=*,node-id=*" 9 | - "kafka.producer:type=*,id=*" 10 | - "kafka.producer:type=*,client-id=*" 11 | - "kafka.producer:type=*,client-id=*,node-id=*" 12 | - "kafka.*:type=kafka-metrics-count,*" 13 | # This will ignore the admin client metrics from Kafka Brokers and will blacklist certain metrics 14 | # that do not make sense for ingestion. 15 | # "kafka.admin.client:type=*, node-id=*, client-id=*" 16 | # "kafka.admin.client:type=*, client-id=*" 17 | # "kafka.admin.client:type=*, id=*" 18 | - "kafka.admin.client:*" 19 | - "kafka.server:type=*,cipher=*,protocol=*,listener=*,networkProcessor=*" 20 | - "kafka.server:type=*" 21 | rules: 22 | # This is by far the biggest contributor to the number of sheer metrics being produced. 23 | # Always keep it on the top for the case of probability when so many metrics will hit the first condition and exit. 24 | # "kafka.cluster:type=*, name=*, topic=*, partition=*" 25 | # "kafka.log:type=*,name=*, topic=*, partition=*" 26 | - pattern: kafka.(\w+)<>Value 27 | name: kafka_$1_$2_$3 28 | type: GAUGE 29 | labels: 30 | topic: "$4" 31 | partition: "$5" 32 | # "kafka.server:type=*,name=*, client-id=*, topic=*, partition=*" 33 | - pattern: kafka.server<>Value 34 | name: kafka_server_$1_$2 35 | type: GAUGE 36 | labels: 37 | clientId: "$3" 38 | topic: "$4" 39 | partition: "$5" 40 | - pattern: kafka.server<>Value 41 | name: kafka_server_$1_$2 42 | type: GAUGE 43 | labels: 44 | clientId: "$3" 45 | broker: "$4:$5" 46 | # "kafka.network:type=*, name=*, request=*, error=*" 47 | # "kafka.network:type=*, name=*, request=*, version=*" 48 | - pattern: kafka.(\w+)<>(Count|Value) 49 | name: kafka_$1_$2_$3 50 | labels: 51 | "$4": "$5" 52 | "$6": "$7" 53 | - pattern: kafka.(\w+)<>(\d+)thPercentile 54 | name: kafka_$1_$2_$3 55 | type: GAUGE 56 | labels: 57 | "$4": "$5" 58 | "$6": "$7" 59 | quantile: "0.$8" 60 | # "kafka.rest:type=*, topic=*, partition=*, client-id=*" 61 | # "kafka.rest:type=*, cipher=*, protocol=*, client-id=*" 62 | - pattern: kafka.(\w+)<>Value 63 | name: kafka_$1_$2 64 | labels: 65 | "$3": "$4" 66 | "$5": "$6" 67 | "$7": "$8" 68 | # Count and Value 69 | # "kafka.server:type=*, name=*, topic=*" 70 | # "kafka.server:type=*, name=*, clientId=*" 71 | # "kafka.server:type=*, name=*, delayedOperation=*" 72 | # "kafka.server:type=*, name=*, fetcherType=*" 73 | # "kafka.network:type=*, name=*, networkProcessor=*" 74 | # "kafka.network:type=*, name=*, processor=*" 75 | # "kafka.network:type=*, name=*, request=*" 76 | # "kafka.network:type=*, name=*, listener=*" 77 | # "kafka.log:type=*, name=*, logDirectory=*" 78 | # "kafka.log:type=*, name=*, op=*" 79 | # "kafka.rest:type=*, node-id=*, client-id=*" 80 | - pattern: kafka.(\w+)<>(Count|Value) 81 | name: kafka_$1_$2_$3 82 | labels: 83 | "$4": "$5" 84 | # "kafka.consumer:type=*, topic=*, client-id=*" 85 | # "kafka.producer:type=*, topic=*, client-id=*" 86 | # "kafka.rest:type=*, topic=*, client-id=*" 87 | # "kafka.server:type=*, broker-id=*, fetcher-id=*" 88 | # "kafka.server:type=*, listener=*, networkProcessor=*" 89 | - pattern: kafka.(\w+)<>(Count|Value) 90 | name: kafka_$1_$2 91 | labels: 92 | "$3": "$4" 93 | "$5": "$6" 94 | # "kafka.network:type=*, name=*" 95 | # "kafka.server:type=*, name=*" 96 | # "kafka.controller:type=*, name=*" 97 | # "kafka.databalancer:type=*, name=*" 98 | # "kafka.log:type=*, name=*" 99 | # "kafka.utils:type=*, name=*" 100 | - pattern: kafka.(\w+)<>(Count|Value) 101 | name: kafka_$1_$2_$3 102 | # "kafka.producer:type=*, client-id=*" 103 | # "kafka.producer:type=*, id=*" 104 | # "kafka.rest:type=*, client-id=*" 105 | # "kafka.rest:type=*, http-status-code=*" 106 | # "kafka.server:type=*, BrokerId=*" 107 | # "kafka.server:type=*, listener=*" 108 | # "kafka.server:type=*, id=*" 109 | - pattern: kafka.(\w+)<>Value 110 | name: kafka_$1_$2 111 | labels: 112 | "$3": "$4" 113 | 114 | - pattern: kafka.server<>OneMinuteRate 115 | name: kafka_server_kafkarequesthandlerpool_requesthandleravgidlepercent_total 116 | type: GAUGE 117 | # "kafka.server:type=*, listener=*, networkProcessor=*, clientSoftwareName=*, clientSoftwareVersion=*" 118 | - pattern: kafka.server<>connections 119 | name: kafka_server_socketservermetrics_connections 120 | type: GAUGE 121 | labels: 122 | client_software_name: "$1" 123 | client_software_version: "$2" 124 | listener: "$3" 125 | network_processor: "$4" 126 | - pattern: "kafka.server<>(.+):" 127 | name: kafka_server_socketservermetrics_$3 128 | type: GAUGE 129 | labels: 130 | listener: "$1" 131 | network_processor: "$2" 132 | # "kafka.coordinator.group:type=*, name=*" 133 | # "kafka.coordinator.transaction:type=*, name=*" 134 | - pattern: kafka.coordinator.(\w+)<>(Count|Value) 135 | name: kafka_coordinator_$1_$2_$3 136 | # Percentile 137 | - pattern: kafka.(\w+)<>(\d+)thPercentile 138 | name: kafka_$1_$2_$3 139 | type: GAUGE 140 | labels: 141 | "$4": "$5" 142 | quantile: "0.$6" 143 | - pattern: kafka.(\w+)<>(\d+)thPercentile 144 | name: kafka_$1_$2_$3 145 | type: GAUGE 146 | labels: 147 | quantile: "0.$4" 148 | # Additional Rules for Confluent Server Metrics 149 | # 'confluent.metadata:type=*, name=*, topic=*, partition=*' 150 | - pattern: confluent.(\w+)<>Value 151 | name: confluent_$1_$2 152 | type: GAUGE 153 | labels: 154 | "$3": "$4" 155 | "$5": "$6" 156 | "$7": "$8" 157 | # 'confluent.metadata.service:type=*, node-id=*, client-id=*' 158 | - pattern: confluent.(.+)<>Value 159 | name: confluent_$1_$2 160 | type: GAUGE 161 | labels: 162 | "$3": "$4" 163 | "$5": "$6" 164 | # 'confluent.metadata.service:type=*, client-id=*' 165 | # 'confluent.metadata.service:type=*, id=*' 166 | # 'confluent.metadata:type=*, name=*' 167 | # 'confluent.license:type=*, name=*' 168 | - pattern: confluent.(.+)<>Value 169 | name: confluent_$1_$2 170 | type: GAUGE 171 | labels: 172 | "$3": "$4" 173 | 174 | # Quotas 175 | - pattern : 'kafka.server<>(.+):' 176 | name: kafka_server_$1_$4 177 | type: GAUGE 178 | labels: 179 | user: "$2" 180 | client-id: "$3" 181 | 182 | - pattern : 'kafka.server<>(.+):' 183 | name: kafka_server_$1_$3 184 | type: GAUGE 185 | labels: 186 | user: "$2" 187 | 188 | - pattern : 'kafka.server<>(.+):' 189 | name: kafka_server_$1_$3 190 | type: GAUGE 191 | labels: 192 | client-id: "$2" 193 | -------------------------------------------------------------------------------- /monitoring/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s # By default, scrape targets every 15 seconds. 3 | scrape_configs: 4 | - job_name: 'prometheus' 5 | scrape_interval: 5s 6 | static_configs: 7 | - targets: [ 'localhost:9090' ] 8 | 9 | - job_name: "kafka-broker" 10 | static_configs: 11 | - targets: 12 | - "kafka:1234" 13 | labels: 14 | env: "local" 15 | relabel_configs: 16 | - source_labels: [__address__] 17 | target_label: hostname 18 | regex: '([^:]+)(:[0-9]+)?' 19 | replacement: '${1}' 20 | 21 | - job_name: 'producer' 22 | scrape_interval: 15s 23 | metrics_path: '/actuator/prometheus' 24 | static_configs: 25 | - targets: [ 'host.docker.internal:8080' ] 26 | 27 | - job_name: 'consumer' 28 | scrape_interval: 15s 29 | metrics_path: '/actuator/prometheus' 30 | static_configs: 31 | - targets: [ 'host.docker.internal:8082' ] -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | nl.jtim 7 | spring-io-barcelona-2022-talk 8 | 0.0.1-SNAPSHOT 9 | spring-io-barcelona-2022-talk 10 | Spring Kafka project for Spring I/O 2022 Barcelona talk 11 | 12 | 11 13 | 14 | 15 | pom 16 | 17 | 18 | avro-model 19 | spring-kafka-consumer 20 | spring-kafka-producer 21 | spring-kafka-streams 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /spring-kafka-consumer/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /spring-kafka-consumer/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/spring-kafka-consumer/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-kafka-consumer/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /spring-kafka-consumer/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /spring-kafka-consumer/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /spring-kafka-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | nl.jtim 12 | spring-kafka-consumer 13 | 0.0.1-SNAPSHOT 14 | spring-kafka-consumer 15 | Demo project for Spring Boot 16 | 17 | 11 18 | 7.1.0 19 | 20 | 21 | 1.16.3 22 | 23 | 2021.0.2 24 | 25 | 26 | 27 | 28 | nl.jtim 29 | avro-model 30 | ${project.version} 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-webflux 40 | 41 | 42 | org.springframework.kafka 43 | spring-kafka 44 | 45 | 46 | org.projectlombok 47 | lombok 48 | true 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-test 53 | test 54 | 55 | 56 | io.projectreactor 57 | reactor-test 58 | test 59 | 60 | 61 | org.springframework.kafka 62 | spring-kafka-test 63 | test 64 | 65 | 66 | 69 | 70 | io.confluent 71 | kafka-avro-serializer 72 | ${confluent.kafka.version} 73 | 74 | 75 | 76 | 77 | org.springframework.cloud 78 | spring-cloud-sleuth-zipkin 79 | 80 | 81 | org.springframework.cloud 82 | spring-cloud-starter-sleuth 83 | 84 | 85 | 89 | 90 | org.springframework.boot 91 | spring-boot-starter-validation 92 | 93 | 94 | 95 | 96 | io.micrometer 97 | micrometer-registry-prometheus 98 | 99 | 100 | 101 | org.testcontainers 102 | kafka 103 | test 104 | 105 | 106 | org.testcontainers 107 | junit-jupiter 108 | test 109 | 110 | 111 | 112 | 113 | 114 | 115 | org.springframework.boot 116 | spring-boot-maven-plugin 117 | 118 | 119 | 120 | org.projectlombok 121 | lombok 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | confluent 133 | https://packages.confluent.io/maven/ 134 | 135 | 136 | 137 | 138 | 139 | 140 | org.springframework.cloud 141 | spring-cloud-dependencies 142 | ${spring-cloud.version} 143 | pom 144 | import 145 | 146 | 147 | org.testcontainers 148 | testcontainers-bom 149 | ${testcontainers.version} 150 | pom 151 | import 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/main/java/nl/jtim/spring/kafka/consumer/ShakyStockQuoteService.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class ShakyStockQuoteService implements StockQuoteService { 8 | 9 | @Override 10 | public void handle(StockQuote stockQuote) { 11 | if ("KABOOM".equalsIgnoreCase(stockQuote.getSymbol())) { 12 | throw new RuntimeException("Whoops something went wrong..."); 13 | } 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/main/java/nl/jtim/spring/kafka/consumer/SpringKafkaConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.ApplicationRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.kafka.annotation.EnableKafka; 9 | import org.springframework.kafka.config.KafkaListenerEndpointRegistry; 10 | import org.springframework.kafka.listener.ConcurrentMessageListenerContainer; 11 | import org.springframework.kafka.listener.MessageListenerContainer; 12 | 13 | import java.util.Collection; 14 | 15 | @SpringBootApplication 16 | @Slf4j 17 | @EnableKafka 18 | public class SpringKafkaConsumerApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(SpringKafkaConsumerApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/main/java/nl/jtim/spring/kafka/consumer/StockQuoteConsumer.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 5 | import org.springframework.kafka.annotation.KafkaListener; 6 | import org.springframework.kafka.support.KafkaHeaders; 7 | import org.springframework.messaging.handler.annotation.Header; 8 | import org.springframework.messaging.handler.annotation.Payload; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.validation.Valid; 12 | 13 | @Component 14 | @Slf4j 15 | public class StockQuoteConsumer { 16 | 17 | public final static String STOCK_QUOTES_TOPIC_NAME = "stock-quotes"; 18 | public final static String STOCK_QUOTES_KAFKA_LISTENER_ID = "stockQuoteListener"; 19 | 20 | private final StockQuoteService service; 21 | 22 | public StockQuoteConsumer(StockQuoteService service) { 23 | this.service = service; 24 | } 25 | 26 | @KafkaListener(topics = STOCK_QUOTES_TOPIC_NAME, id = STOCK_QUOTES_KAFKA_LISTENER_ID, idIsGroup = false) 27 | public void on(StockQuote stockQuote, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) String partition) { 28 | log.info("Consumed from partition: {} value: {}", partition, stockQuote); 29 | 30 | service.handle(stockQuote); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/main/java/nl/jtim/spring/kafka/consumer/StockQuoteService.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 4 | 5 | public interface StockQuoteService { 6 | 7 | 8 | void handle(StockQuote stockQuote); 9 | } 10 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/main/java/nl/jtim/spring/kafka/consumer/config/KafkaExceptionHandlingConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer.config; 2 | 3 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 4 | import org.apache.kafka.clients.producer.ProducerConfig; 5 | import org.apache.kafka.common.serialization.ByteArraySerializer; 6 | import org.apache.kafka.common.utils.Bytes; 7 | import org.springframework.beans.factory.ObjectProvider; 8 | import org.springframework.boot.autoconfigure.kafka.DefaultKafkaProducerFactoryCustomizer; 9 | import org.springframework.boot.autoconfigure.kafka.KafkaProperties; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 13 | import org.springframework.kafka.core.KafkaOperations; 14 | import org.springframework.kafka.core.KafkaTemplate; 15 | import org.springframework.kafka.core.ProducerFactory; 16 | import org.springframework.kafka.listener.*; 17 | import org.springframework.kafka.support.ProducerListener; 18 | import org.springframework.kafka.support.converter.RecordMessageConverter; 19 | import org.springframework.util.backoff.BackOff; 20 | import org.springframework.util.backoff.BackOffExecution; 21 | import org.springframework.util.backoff.ExponentialBackOff; 22 | import org.springframework.util.backoff.FixedBackOff; 23 | 24 | import java.util.LinkedHashMap; 25 | import java.util.Map; 26 | 27 | import static java.util.concurrent.TimeUnit.MINUTES; 28 | 29 | /** 30 | * Uncomment to demo the exception handling scenarios. 31 | */ 32 | //@Configuration 33 | public class KafkaExceptionHandlingConfiguration { 34 | 35 | private final KafkaProperties properties; 36 | 37 | 38 | public KafkaExceptionHandlingConfiguration(KafkaProperties properties) { 39 | this.properties = properties; 40 | } 41 | 42 | /** 43 | * This is the default error handler. 44 | * Spring will 'autoconfigure' this error handler for you in case you don't specify the bean. 45 | */ 46 | @Bean 47 | public DefaultErrorHandler errorHandler() { 48 | return new DefaultErrorHandler(); 49 | } 50 | 51 | // @Bean 52 | // public DefaultErrorHandler errorHandler(DeadLetterPublishingRecoverer recoverer) { 53 | // return new DefaultErrorHandler(recoverer); 54 | // } 55 | 56 | /** 57 | * Configure the {@link DeadLetterPublishingRecoverer} to publish poison pill bytes to a dead letter topic: 58 | * "stock-quotes.DLT". 59 | */ 60 | @Bean 61 | public DeadLetterPublishingRecoverer recoverer(KafkaTemplate bytesKafkaTemplate, KafkaTemplate kafkaTemplate) { 62 | Map, KafkaOperations> templates = new LinkedHashMap<>(); 63 | templates.put(byte[].class, bytesKafkaTemplate); 64 | templates.put(StockQuote.class, kafkaTemplate); 65 | return new DeadLetterPublishingRecoverer(templates); 66 | } 67 | 68 | /** 69 | * In case you don't specify a {@link org.springframework.util.backoff.BackOff} 70 | * the {@link org.springframework.kafka.listener.SeekUtils#DEFAULT_BACK_OFF} will be configured. 71 | * 72 | * It's a {@link FixedBackOff} with 0 interval and will try 10 times. 73 | */ 74 | // @Bean 75 | // public DefaultErrorHandler errorHandler(DeadLetterPublishingRecoverer recoverer) { 76 | // return new DefaultErrorHandler(recoverer, new FixedBackOff(0, 5)); 77 | // } 78 | 79 | 80 | 81 | /** 82 | * Implementation of {@link BackOff} that increases the back off period for each 83 | * retry attempt. When the interval has reached the {@link ExponentialBackOff#setMaxInterval(long) 84 | * max interval}, it is no longer increased. Stops retrying once the 85 | * {@link ExponentialBackOff#setMaxElapsedTime(long) max elapsed time} has been reached. 86 | * 87 | *

Example: The default interval is {@value ExponentialBackOff#DEFAULT_INITIAL_INTERVAL} ms, 88 | * the default multiplier is {@value ExponentialBackOff#DEFAULT_MULTIPLIER}, and the default max 89 | * interval is {@value ExponentialBackOff#DEFAULT_MAX_INTERVAL}. For 10 attempts the sequence will be 90 | * as follows: 91 | * 92 | *

 93 |      * request#     back off
 94 |      *
 95 |      *  1              2000
 96 |      *  2              3000
 97 |      *  3              4500
 98 |      *  4              6750
 99 |      *  5             10125
100 |      *  6             15187
101 |      *  7             22780
102 |      *  8             30000
103 |      *  9             30000
104 |      * 10             30000
105 |      * 
106 | * 107 | *

Note that the default max elapsed time is {@link Long#MAX_VALUE}. Use 108 | * {@link ExponentialBackOff#setMaxElapsedTime(long)} to limit the maximum length of time 109 | * that an instance should accumulate before returning 110 | * {@link BackOffExecution#STOP}. 111 | */ 112 | // @Bean 113 | // public DefaultErrorHandler errorHandlerWithExponentialBackOff(DeadLetterPublishingRecoverer recoverer) { 114 | // ExponentialBackOff backOff = new ExponentialBackOff(2_000, 1.5); 115 | // backOff.setMaxElapsedTime(MINUTES.toMillis(2)); 116 | // return new DefaultErrorHandler(recoverer, backOff); 117 | // } 118 | // 119 | // @Bean 120 | // public DefaultErrorHandler errorHandler() { 121 | // ExponentialBackOffWithMaxRetries backOffWithMaxRetries = new ExponentialBackOffWithMaxRetries(10); 122 | // backOffWithMaxRetries.setInitialInterval(1_000); 123 | // backOffWithMaxRetries.setMultiplier(2.0); 124 | // backOffWithMaxRetries.setMaxInterval(10_000); 125 | // 126 | // return new DefaultErrorHandler(backOffWithMaxRetries); 127 | // } 128 | // 129 | // /** 130 | // * We can also use the {@link CommonLoggingErrorHandler} in case we only want to 131 | // * log the error and continue. 132 | // * 133 | // * Boot will autowire this into the container factory. 134 | // */ 135 | // @Bean 136 | // public CommonLoggingErrorHandler loggingErrorHandler() { 137 | // return new CommonLoggingErrorHandler(); 138 | // } 139 | // 140 | // @Bean 141 | // public CommonContainerStoppingErrorHandler containerStoppingErrorHandler() { 142 | // return new CommonContainerStoppingErrorHandler(); 143 | // } 144 | // 145 | // /** 146 | // * To mix and match error handlers based on different exception 147 | // */ 148 | // @Bean 149 | // public CommonDelegatingErrorHandler delegatingErrorHandler() { 150 | // DefaultErrorHandler defaultErrorHandler = new DefaultErrorHandler(); 151 | // CommonDelegatingErrorHandler delegatingErrorHandler = new CommonDelegatingErrorHandler(defaultErrorHandler); 152 | // CommonContainerStoppingErrorHandler containerStoppingErrorHandler = new CommonContainerStoppingErrorHandler(); 153 | // 154 | // delegatingErrorHandler.addDelegate(DeserializationException.class, containerStoppingErrorHandler); 155 | // 156 | // return delegatingErrorHandler; 157 | // } 158 | 159 | 160 | 161 | /** 162 | * This is the specific Producer for serialization exceptions. 163 | * We configure ByteArraySerializer for both the key and value serializer. 164 | * Because we don't know upfront in what 'format' the record from the topic caused the deserialization exception. 165 | */ 166 | @Bean 167 | public ProducerFactory bytesProducerFactory(KafkaProperties kafkaProperties) { 168 | Map producerProperties = kafkaProperties.buildProducerProperties(); 169 | producerProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class); 170 | producerProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class); 171 | return new DefaultKafkaProducerFactory<>(producerProperties); 172 | } 173 | 174 | /** 175 | * This is the specific Kafka template for serialization exceptions. 176 | */ 177 | @Bean 178 | public KafkaTemplate bytesKafkaTemplate(ProducerFactory bytesProducerFactory) { 179 | return new KafkaTemplate<>(bytesProducerFactory); 180 | } 181 | 182 | /** 183 | * We have to also create the "default" kafkaProducerFactory. 184 | * The code is basically copied from: 185 | * {@link org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration#kafkaProducerFactory(ObjectProvider)} 186 | */ 187 | @Bean 188 | public ProducerFactory kafkaProducerFactory( 189 | ObjectProvider customizers) { 190 | DefaultKafkaProducerFactory factory = new DefaultKafkaProducerFactory<>( 191 | this.properties.buildProducerProperties()); 192 | String transactionIdPrefix = this.properties.getProducer().getTransactionIdPrefix(); 193 | if (transactionIdPrefix != null) { 194 | factory.setTransactionIdPrefix(transactionIdPrefix); 195 | } 196 | customizers.orderedStream().forEach((customizer) -> customizer.customize(factory)); 197 | return factory; 198 | } 199 | 200 | /** 201 | * We have to also create the "default" kafkaTemplate. 202 | * The code is basically copied from: 203 | * {@link org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration#kafkaTemplate(ProducerFactory, ProducerListener, ObjectProvider)} 204 | */ 205 | @Bean 206 | public KafkaTemplate kafkaTemplate(ProducerFactory kafkaProducerFactory, 207 | ProducerListener kafkaProducerListener, 208 | ObjectProvider messageConverter) { 209 | KafkaTemplate kafkaTemplate = new KafkaTemplate<>(kafkaProducerFactory); 210 | messageConverter.ifUnique(kafkaTemplate::setMessageConverter); 211 | kafkaTemplate.setProducerListener(kafkaProducerListener); 212 | kafkaTemplate.setDefaultTopic(this.properties.getTemplate().getDefaultTopic()); 213 | return kafkaTemplate; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | 4 | spring: 5 | application: 6 | name: consumer-application 7 | 8 | kafka: 9 | bootstrap-servers: localhost:9092 10 | 11 | producer: 12 | # Important! 13 | # In case you publish to a 'dead letter topic' your consumer application becomes 14 | # a producer as well! So you need to specify the producer properties! 15 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 16 | value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer 17 | 18 | consumer: 19 | group-id: my-consumer-group 20 | auto-offset-reset: earliest 21 | # Configures the Spring Kafka ErrorHandlingDeserializer that delegates to the 'real' deserializers 22 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 23 | value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer 24 | # Uncomment to protect against deserialization exception 25 | # key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer 26 | # value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer 27 | properties: 28 | # Tells Kafka / Schema Registry that we will be using a specific Avro type 29 | # otherwise Kafka will expect GenericRecord to be used on the topic. 30 | specific.avro.reader: true 31 | # Delegate deserializers 32 | spring.deserializer.key.delegate.class: org.apache.kafka.common.serialization.StringDeserializer 33 | spring.deserializer.value.delegate.class: io.confluent.kafka.serializers.KafkaAvroDeserializer 34 | 35 | properties: 36 | schema.registry.url: http://localhost:8081 37 | 38 | # Open up all Spring Boot Actuator endpoints 39 | management: 40 | endpoints: 41 | web: 42 | exposure: 43 | include: "*" 44 | 45 | endpoint: 46 | health: 47 | show-details: always 48 | 49 | metrics: 50 | tags: 51 | application: ${spring.application.name} 52 | env: local 53 | 54 | 55 | logging: 56 | level: 57 | org.springframework.kafka.listener.DeadLetterPublishingRecoverer: debug -------------------------------------------------------------------------------- /spring-kafka-consumer/src/test/java/nl/jtim/spring/kafka/consumer/EmbeddedKafkaAvroExampleIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.context.annotation.Import; 9 | import org.springframework.kafka.config.KafkaListenerEndpointRegistry; 10 | import org.springframework.kafka.core.KafkaTemplate; 11 | import org.springframework.kafka.listener.MessageListenerContainer; 12 | import org.springframework.kafka.test.EmbeddedKafkaBroker; 13 | import org.springframework.kafka.test.context.EmbeddedKafka; 14 | import org.springframework.kafka.test.utils.ContainerTestUtils; 15 | 16 | import java.time.Instant; 17 | 18 | import static nl.jtim.spring.kafka.consumer.StockQuoteConsumer.STOCK_QUOTES_KAFKA_LISTENER_ID; 19 | import static nl.jtim.spring.kafka.consumer.StockQuoteConsumer.STOCK_QUOTES_TOPIC_NAME; 20 | import static org.mockito.Mockito.timeout; 21 | import static org.mockito.Mockito.verify; 22 | 23 | /** 24 | * Example integration test with Avro producer and consumer. 25 | * We mock out the schema registry using {@link io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient}. 26 | */ 27 | @Slf4j 28 | @EmbeddedKafka 29 | @SpringBootTest 30 | @Import(KafkaMockSchemaRegistryTestConfiguration.class) 31 | public class EmbeddedKafkaAvroExampleIntegrationTest { 32 | 33 | @Autowired 34 | private EmbeddedKafkaBroker embeddedKafkaBroker; 35 | 36 | @Autowired 37 | private KafkaListenerEndpointRegistry registry; 38 | 39 | @Autowired 40 | private StockQuoteService stockQuoteService; 41 | 42 | @Autowired 43 | private KafkaTemplate kafkaTemplate; 44 | 45 | @Test 46 | public void consumerAvroTest() { 47 | String kafkaBrokers = embeddedKafkaBroker.getBrokersAsString(); 48 | log.info("Kafka Brokers: {}", kafkaBrokers); 49 | 50 | // Get access to the listenerContainer 'consumer' 51 | MessageListenerContainer listenerContainer = registry.getListenerContainer(STOCK_QUOTES_KAFKA_LISTENER_ID); 52 | 53 | // Wait until all partitions are assigned to the 'consumer' 54 | ContainerTestUtils.waitForAssignment(listenerContainer, embeddedKafkaBroker.getPartitionsPerTopic()); 55 | 56 | // Produce message 57 | StockQuote stockQuote = new StockQuote("INGA", "AMS", "10.99", "EUR", "Description", Instant.now()); 58 | kafkaTemplate.send(STOCK_QUOTES_TOPIC_NAME, stockQuote.getSymbol(), stockQuote); 59 | 60 | // Verify the message has been consumed 61 | verify(stockQuoteService, timeout(1000)).handle(stockQuote); 62 | } 63 | } -------------------------------------------------------------------------------- /spring-kafka-consumer/src/test/java/nl/jtim/spring/kafka/consumer/KafkaMockSchemaRegistryTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient; 4 | import io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient; 5 | import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient; 6 | import io.confluent.kafka.serializers.KafkaAvroDeserializer; 7 | import io.confluent.kafka.serializers.KafkaAvroSerializer; 8 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 9 | import org.apache.kafka.common.serialization.StringDeserializer; 10 | import org.apache.kafka.common.serialization.StringSerializer; 11 | import org.springframework.boot.autoconfigure.kafka.KafkaProperties; 12 | import org.springframework.boot.test.context.TestConfiguration; 13 | import org.springframework.context.annotation.Bean; 14 | import org.springframework.context.annotation.Primary; 15 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 16 | import org.springframework.kafka.core.DefaultKafkaConsumerFactory; 17 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 18 | import org.springframework.kafka.core.KafkaTemplate; 19 | import org.springframework.kafka.test.context.EmbeddedKafka; 20 | 21 | import static org.mockito.Mockito.mock; 22 | 23 | @TestConfiguration 24 | public class KafkaMockSchemaRegistryTestConfiguration { 25 | 26 | private final KafkaProperties kafkaProperties; 27 | 28 | public KafkaMockSchemaRegistryTestConfiguration(KafkaProperties kafkaProperties) { 29 | this.kafkaProperties = kafkaProperties; 30 | } 31 | 32 | /** 33 | * We don't want to use the default {@link CachedSchemaRegistryClient} since it will try to 34 | * connect to a `real` schema registry. 35 | *

36 | * Spring Kafka's {@link EmbeddedKafka} doesn't support a schema registry out of the box. 37 | * We will use the {@link MockSchemaRegistryClient} 38 | */ 39 | @Bean 40 | public SchemaRegistryClient schemaRegistryClient() { 41 | return new MockSchemaRegistryClient(); 42 | } 43 | 44 | /** 45 | * We also need to mock our 'service' to be able to verify 46 | * messages are consumed in the consumer. 47 | */ 48 | @Bean 49 | @Primary 50 | public StockQuoteService stockQuoteService() { 51 | return mock(StockQuoteService.class); 52 | } 53 | 54 | // ============ For consuming ====================================================================================== 55 | 56 | @Bean 57 | public KafkaAvroDeserializer kafkaAvroDeserializer(SchemaRegistryClient schemaRegistryClient) { 58 | return new KafkaAvroDeserializer(schemaRegistryClient, kafkaProperties.buildConsumerProperties()); 59 | } 60 | 61 | @Bean 62 | public DefaultKafkaConsumerFactory consumerFactory(KafkaAvroDeserializer kafkaAvroDeserializer) { 63 | return new DefaultKafkaConsumerFactory(kafkaProperties.buildConsumerProperties(), new StringDeserializer(), kafkaAvroDeserializer); 64 | } 65 | 66 | @Bean 67 | public ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory(DefaultKafkaConsumerFactory defaultKafkaConsumerFactory) { 68 | ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>(); 69 | factory.setConsumerFactory(defaultKafkaConsumerFactory); 70 | return factory; 71 | } 72 | 73 | // ============ For producing ====================================================================================== 74 | 75 | @Bean 76 | public KafkaAvroSerializer kafkaAvroSerializer(SchemaRegistryClient schemaRegistryClient) { 77 | return new KafkaAvroSerializer(schemaRegistryClient); 78 | } 79 | 80 | @Bean 81 | public DefaultKafkaProducerFactory producerFactory(KafkaAvroSerializer kafkaAvroSerializer) { 82 | return new DefaultKafkaProducerFactory(kafkaProperties.buildProducerProperties(), new StringSerializer(), kafkaAvroSerializer); 83 | } 84 | 85 | @Bean 86 | public KafkaTemplate kafkaTemplate(DefaultKafkaProducerFactory producerFactory) { 87 | return new KafkaTemplate<>(producerFactory); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/test/java/nl/jtim/spring/kafka/consumer/KafkaTestContainersIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.boot.test.system.CapturedOutput; 10 | import org.springframework.boot.test.system.OutputCaptureExtension; 11 | import org.springframework.context.annotation.Import; 12 | import org.springframework.kafka.config.KafkaListenerEndpointRegistry; 13 | import org.springframework.kafka.core.KafkaTemplate; 14 | import org.springframework.kafka.listener.MessageListenerContainer; 15 | import org.springframework.kafka.test.utils.ContainerTestUtils; 16 | import org.springframework.test.annotation.DirtiesContext; 17 | import org.springframework.test.context.DynamicPropertyRegistry; 18 | import org.springframework.test.context.DynamicPropertySource; 19 | import org.testcontainers.containers.KafkaContainer; 20 | import org.testcontainers.junit.jupiter.Container; 21 | import org.testcontainers.junit.jupiter.Testcontainers; 22 | import org.testcontainers.utility.DockerImageName; 23 | 24 | import java.time.Instant; 25 | 26 | import static nl.jtim.spring.kafka.consumer.StockQuoteConsumer.STOCK_QUOTES_KAFKA_LISTENER_ID; 27 | import static nl.jtim.spring.kafka.consumer.StockQuoteConsumer.STOCK_QUOTES_TOPIC_NAME; 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | import static org.mockito.Mockito.timeout; 30 | import static org.mockito.Mockito.verify; 31 | 32 | @Slf4j 33 | @Testcontainers(disabledWithoutDocker = true) 34 | @DirtiesContext 35 | @SpringBootTest 36 | @Import({KafkaTestTopicTestConfiguration.class, KafkaMockSchemaRegistryTestConfiguration.class}) 37 | @ExtendWith(OutputCaptureExtension.class) 38 | public class KafkaTestContainersIntegrationTest { 39 | 40 | @Container 41 | private static final KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.1.0")) 42 | .withReuse(true); 43 | 44 | @Autowired 45 | private StockQuoteService stockQuoteService; 46 | 47 | @Autowired 48 | private KafkaTemplate kafkaTemplate; 49 | 50 | @Autowired 51 | private KafkaListenerEndpointRegistry registry; 52 | 53 | @DynamicPropertySource 54 | static void setDatasourceProperties(DynamicPropertyRegistry propertyRegistry) { 55 | propertyRegistry.add("spring.kafka.properties.bootstrap.servers", kafka::getBootstrapServers); 56 | propertyRegistry.add("spring.kafka.producer.properties.bootstrap.servers", kafka::getBootstrapServers); 57 | } 58 | 59 | @Test 60 | void consumerAvroTest() { 61 | // Get access to the listenerContainer 'consumer' 62 | MessageListenerContainer listenerContainer = registry.getListenerContainer(STOCK_QUOTES_KAFKA_LISTENER_ID); 63 | assertThat(listenerContainer).isNotNull(); 64 | 65 | // Wait until all partitions are assigned to the 'consumer' 66 | ContainerTestUtils.waitForAssignment(listenerContainer, 3); 67 | 68 | // Produce message 69 | StockQuote stockQuote = new StockQuote("INGA", "AMS", "10.99", "EUR", "ING Stock", Instant.now()); 70 | kafkaTemplate.send(STOCK_QUOTES_TOPIC_NAME, stockQuote.getSymbol(), stockQuote); 71 | 72 | // Verify the message has been consumed 73 | verify(stockQuoteService, timeout(1000)).handle(stockQuote); 74 | } 75 | 76 | @Test 77 | public void consumerAvroTestWithoutServiceMock(CapturedOutput output) throws InterruptedException { 78 | // Get access to the listenerContainer 'consumer' 79 | MessageListenerContainer listenerContainer = registry.getListenerContainer(STOCK_QUOTES_KAFKA_LISTENER_ID); 80 | assertThat(listenerContainer).isNotNull(); 81 | 82 | // Wait until all partitions are assigned to the 'consumer' 83 | ContainerTestUtils.waitForAssignment(listenerContainer, 3); 84 | 85 | // Produce message 86 | StockQuote stockQuote = new StockQuote("INGA", "AMS", "10.99", "EUR", "ING Stock", Instant.now()); 87 | kafkaTemplate.send(STOCK_QUOTES_TOPIC_NAME, stockQuote.getSymbol(), stockQuote); 88 | 89 | Thread.sleep(1000); 90 | 91 | assertThat(output.getOut()).contains("{\"symbol\": \"INGA\", \"exchange\": \"AMS\", \"tradeValue\": \"10.99\", \"currency\": \"EUR\", \"description\": \"ING Stock\","); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/test/java/nl/jtim/spring/kafka/consumer/KafkaTestTopicTestConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import org.apache.kafka.clients.admin.NewTopic; 4 | import org.springframework.boot.test.context.TestConfiguration; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.kafka.config.TopicBuilder; 7 | 8 | import static nl.jtim.spring.kafka.consumer.StockQuoteConsumer.STOCK_QUOTES_TOPIC_NAME; 9 | 10 | /** 11 | * Test configuration to create topic in Embedded Kafka integration test. 12 | */ 13 | @TestConfiguration 14 | public class KafkaTestTopicTestConfiguration { 15 | 16 | @Bean 17 | public NewTopic stockQuoteTestTopic() { 18 | return TopicBuilder.name(STOCK_QUOTES_TOPIC_NAME) 19 | .partitions(3) 20 | .replicas(1) 21 | .build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/test/java/nl/jtim/spring/kafka/consumer/SpringKafkaConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.consumer; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.kafka.test.context.EmbeddedKafka; 6 | 7 | @SpringBootTest 8 | @EmbeddedKafka 9 | class SpringKafkaConsumerApplicationTests { 10 | 11 | @Test 12 | void contextLoads() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-kafka-consumer/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | bootstrap-servers: ${spring.embedded.kafka.brokers} 4 | 5 | producer: 6 | bootstrap-servers: ${spring.embedded.kafka.brokers} 7 | properties: 8 | schema.registry.url: http://mock:8081 9 | 10 | consumer: 11 | group-id: my-consumer-group 12 | auto-offset-reset: earliest 13 | properties: 14 | specific.avro.reader: true 15 | 16 | properties: 17 | schema.registry.url: http://mock:8081 18 | 19 | # We don't want to send spans to Zipkin in tests! 20 | zipkin: 21 | enabled: false 22 | -------------------------------------------------------------------------------- /spring-kafka-producer/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /spring-kafka-producer/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/spring-kafka-producer/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-kafka-producer/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /spring-kafka-producer/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /spring-kafka-producer/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /spring-kafka-producer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | nl.jtim 12 | spring-kafka-producer 13 | 0.0.1-SNAPSHOT 14 | spring-kafka-producer 15 | Demo project for Spring Boot 16 | 17 | 11 18 | 7.1.0 19 | 20 | 21 | 1.0.2 22 | 23 | 24 | 3.6.1 25 | 26 | 2021.0.2 27 | 28 | 29 | 30 | 31 | nl.jtim 32 | avro-model 33 | ${project.version} 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-actuator 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-webflux 43 | 44 | 45 | org.springframework.kafka 46 | spring-kafka 47 | 48 | 49 | 50 | com.github.javafaker 51 | javafaker 52 | ${javafaker.version} 53 | 54 | 55 | org.apache.commons 56 | commons-math3 57 | ${commons.math3.version} 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-devtools 63 | runtime 64 | true 65 | 66 | 67 | org.projectlombok 68 | lombok 69 | true 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-starter-test 74 | test 75 | 76 | 77 | io.projectreactor 78 | reactor-test 79 | test 80 | 81 | 82 | org.springframework.kafka 83 | spring-kafka-test 84 | test 85 | 86 | 87 | 90 | 91 | io.confluent 92 | kafka-avro-serializer 93 | ${confluent.kafka.version} 94 | 95 | 96 | 97 | 98 | org.springframework.cloud 99 | spring-cloud-sleuth-zipkin 100 | 101 | 102 | org.springframework.cloud 103 | spring-cloud-starter-sleuth 104 | 105 | 106 | 107 | 108 | io.micrometer 109 | micrometer-registry-prometheus 110 | 111 | 112 | 113 | 114 | 115 | 116 | org.springframework.boot 117 | spring-boot-maven-plugin 118 | 119 | 120 | 121 | org.projectlombok 122 | lombok 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | confluent 134 | https://packages.confluent.io/maven/ 135 | 136 | 137 | 138 | 139 | 140 | 141 | org.springframework.cloud 142 | spring-cloud-dependencies 143 | ${spring-cloud.version} 144 | pom 145 | import 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/ScheduledStockQuoteProducer.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 5 | import nl.jtim.spring.kafka.producer.generator.RandomStockQuoteGenerator; 6 | import org.springframework.scheduling.annotation.Scheduled; 7 | 8 | @Slf4j 9 | public class ScheduledStockQuoteProducer { 10 | 11 | private final StockQuoteProducer producer; 12 | private final RandomStockQuoteGenerator generator; 13 | 14 | public ScheduledStockQuoteProducer(StockQuoteProducer producer, RandomStockQuoteGenerator generator) { 15 | this.producer = producer; 16 | this.generator = generator; 17 | } 18 | 19 | @Scheduled(fixedRateString = "${kafka.producer.rate}") 20 | public void produce() { 21 | StockQuote stockQuote = generator.generate(); 22 | producer.produce(stockQuote); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/SpringKafkaProducerApplication.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringKafkaProducerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringKafkaProducerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/StockQuoteProducer.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 5 | import org.springframework.kafka.core.KafkaTemplate; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @Slf4j 10 | public class StockQuoteProducer { 11 | 12 | private final KafkaTemplate kafkaTemplate; 13 | 14 | public StockQuoteProducer(KafkaTemplate kafkaTemplate) { 15 | this.kafkaTemplate = kafkaTemplate; 16 | } 17 | 18 | public void produce(StockQuote stockQuote) { 19 | kafkaTemplate.send("stock-quotes", stockQuote.getSymbol(), stockQuote); 20 | log.info("Produced stock quote: {}", stockQuote); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/config/KafkaProducerConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.config; 2 | 3 | import nl.jtim.spring.kafka.producer.generator.RandomStockQuoteGenerator; 4 | import nl.jtim.spring.kafka.producer.ScheduledStockQuoteProducer; 5 | import nl.jtim.spring.kafka.producer.StockQuoteProducer; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | public class KafkaProducerConfiguration { 12 | 13 | @Bean 14 | @ConditionalOnProperty(name = "kafka.producer.enabled", havingValue = "true") 15 | public ScheduledStockQuoteProducer scheduledStockQuoteProducer(StockQuoteProducer producer, RandomStockQuoteGenerator generator) { 16 | return new ScheduledStockQuoteProducer(producer, generator); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/config/KafkaTopicsConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.config; 2 | 3 | import org.apache.kafka.clients.admin.NewTopic; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.kafka.config.TopicBuilder; 8 | 9 | @Configuration 10 | public class KafkaTopicsConfiguration { 11 | 12 | public final static String STOCK_QUOTES_TOPIC_NAME = "stock-quotes"; 13 | 14 | /** 15 | * Since version 2.6, you can omit .partitions() and/or replicas() 16 | * and the broker defaults will be applied to those properties. 17 | * The broker version must be at least 2.4.0 to support this feature. 18 | *

19 | * See: https://cwiki.apache.org/confluence/display/KAFKA/KIP-464%3A+Defaults+for+AdminClient%23createTopic 20 | */ 21 | @Bean 22 | @ConditionalOnProperty(name = "kafka.producer.enabled", havingValue = "true") 23 | public NewTopic stockQuotesTopic() { 24 | return TopicBuilder.name(STOCK_QUOTES_TOPIC_NAME) 25 | .build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/config/SchedulingConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.scheduling.annotation.EnableScheduling; 5 | 6 | @Configuration 7 | @EnableScheduling 8 | public class SchedulingConfiguration { 9 | } 10 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/generator/AbstractRandomStockQuoteGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.generator; 2 | 3 | import lombok.Value; 4 | import org.apache.commons.math3.random.RandomDataGenerator; 5 | 6 | import java.math.BigDecimal; 7 | import java.math.RoundingMode; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | import java.util.Random; 11 | 12 | public abstract class AbstractRandomStockQuoteGenerator { 13 | 14 | private final List instruments; 15 | private static final String STOCK_EXCHANGE_NASDAQ = "NASDAQ"; 16 | private static final String STOCK_EXCHANGE_NEW_YORK = "NYSE"; 17 | private static final String STOCK_EXCHANGE_AMSTERDAM = "AMS"; 18 | 19 | private static final String CURRENCY_EURO = "EUR"; 20 | private static final String CURRENCY_US_DOLLAR = "USD"; 21 | 22 | public AbstractRandomStockQuoteGenerator() { 23 | instruments = Arrays.asList(new RandomStockQuoteGenerator.Instrument("AAPL", STOCK_EXCHANGE_NASDAQ, CURRENCY_US_DOLLAR), 24 | new RandomStockQuoteGenerator.Instrument("AMZN", STOCK_EXCHANGE_NASDAQ, CURRENCY_US_DOLLAR), 25 | new RandomStockQuoteGenerator.Instrument("GOOGL", STOCK_EXCHANGE_NASDAQ, CURRENCY_US_DOLLAR), 26 | new RandomStockQuoteGenerator.Instrument("NFLX", STOCK_EXCHANGE_NASDAQ, CURRENCY_US_DOLLAR), 27 | new RandomStockQuoteGenerator.Instrument("INGA", STOCK_EXCHANGE_AMSTERDAM, CURRENCY_EURO), 28 | new RandomStockQuoteGenerator.Instrument("AD", STOCK_EXCHANGE_AMSTERDAM, CURRENCY_EURO), 29 | new RandomStockQuoteGenerator.Instrument("RDSA", STOCK_EXCHANGE_AMSTERDAM, CURRENCY_EURO), 30 | new RandomStockQuoteGenerator.Instrument("KO", STOCK_EXCHANGE_NEW_YORK, CURRENCY_US_DOLLAR)); 31 | } 32 | 33 | BigDecimal generateRandomPrice() { 34 | double leftLimit = 1.000D; 35 | double rightLimit = 3000.000D; 36 | 37 | BigDecimal randomPrice = BigDecimal.valueOf(new RandomDataGenerator().nextUniform(leftLimit, rightLimit)); 38 | randomPrice = randomPrice.setScale(3, RoundingMode.HALF_UP); 39 | return randomPrice; 40 | } 41 | 42 | RandomStockQuoteGenerator.Instrument pickRandomInstrument() { 43 | int randomIndex = new Random().nextInt(instruments.size()); 44 | return instruments.get(randomIndex); 45 | } 46 | 47 | 48 | @Value 49 | static class Instrument { 50 | private String symbol; 51 | private String exchange; 52 | private String currency; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/generator/RandomStockQuoteGenerator.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.generator; 2 | 3 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 4 | import nl.jtim.spring.kafka.producer.generator.AbstractRandomStockQuoteGenerator; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.math.BigDecimal; 8 | import java.time.Instant; 9 | 10 | @Component 11 | public class RandomStockQuoteGenerator extends AbstractRandomStockQuoteGenerator { 12 | 13 | public StockQuote generate() { 14 | Instrument randomInstrument = pickRandomInstrument(); 15 | BigDecimal randomPrice = generateRandomPrice(); 16 | return new StockQuote(randomInstrument.getSymbol(), randomInstrument.getExchange(), randomPrice.toPlainString(), 17 | randomInstrument.getCurrency(), randomInstrument.getSymbol() + " stock", Instant.now()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/rest/RestResource.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.rest; 2 | 3 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 4 | import nl.jtim.spring.kafka.producer.StockQuoteProducer; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.time.Instant; 11 | 12 | @RestController 13 | @RequestMapping("/api/quotes") 14 | public class RestResource { 15 | 16 | private final StockQuoteProducer stockQuoteProducer; 17 | 18 | public RestResource(StockQuoteProducer stockQuoteProducer) { 19 | this.stockQuoteProducer = stockQuoteProducer; 20 | } 21 | 22 | @PostMapping 23 | public void produce(@RequestBody StockQuoteRequest request) { 24 | StockQuote stockQuote = new StockQuote(request.getSymbol(), request.getExchange(), request.getTradeValue(), request.getCurrency(), request.getDescription(), Instant.now()); 25 | stockQuoteProducer.produce(stockQuote); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/java/nl/jtim/spring/kafka/producer/rest/StockQuoteRequest.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer.rest; 2 | 3 | import lombok.Getter; 4 | 5 | @Getter 6 | public class StockQuoteRequest { 7 | 8 | /** 9 | * The identifier of the stock. 10 | */ 11 | private String symbol; 12 | /** 13 | * The stock exchange the stock was traded. 14 | */ 15 | private String exchange; 16 | /** 17 | * The value the stock was traded for. 18 | */ 19 | private String tradeValue; 20 | /** 21 | * The currency the stock was traded in. 22 | */ 23 | private String currency; 24 | /** 25 | * Description about the stock. 26 | */ 27 | private String description; 28 | 29 | public StockQuoteRequest(String symbol, String exchange, String tradeValue, String currency, String description) { 30 | this.symbol = symbol; 31 | this.exchange = exchange; 32 | this.tradeValue = tradeValue; 33 | this.currency = currency; 34 | this.description = description; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: producer-application 4 | 5 | kafka: 6 | bootstrap-servers: localhost:9092 7 | 8 | producer: 9 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 10 | value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer 11 | client-id: ${spring.application.name} 12 | properties: 13 | enable.idempotence: true 14 | 15 | properties: 16 | schema.registry.url: http://localhost:8081 17 | 18 | # Open up all Spring Boot Actuator endpoints 19 | management: 20 | endpoints: 21 | web: 22 | exposure: 23 | include: "*" 24 | 25 | endpoint: 26 | health: 27 | show-details: always 28 | 29 | metrics: 30 | tags: 31 | application: ${spring.application.name} 32 | env: local 33 | 34 | kafka: 35 | producer: 36 | enabled: true 37 | rate: 1000 -------------------------------------------------------------------------------- /spring-kafka-producer/src/test/java/nl/jtim/spring/kafka/producer/SpringKafkaProducerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.spring.kafka.producer; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.kafka.test.context.EmbeddedKafka; 6 | 7 | @SpringBootTest 8 | @EmbeddedKafka 9 | class SpringKafkaProducerApplicationTests { 10 | 11 | @Test 12 | void contextLoads() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-kafka-producer/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | bootstrap-servers: ${spring.embedded.kafka.brokers} 4 | 5 | # We don't want to send spans to Zipkin in Spring Boot tests! 6 | zipkin: 7 | enabled: false 8 | -------------------------------------------------------------------------------- /spring-kafka-streams/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /spring-kafka-streams/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/j-tim/spring-io-barcelona-2022-spring-kafka-beyond-the-basics/b12b54545badac628cfaee8aee234f4b12ed9464/spring-kafka-streams/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-kafka-streams/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /spring-kafka-streams/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /spring-kafka-streams/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /spring-kafka-streams/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.7 9 | 10 | 11 | nl.jtim 12 | spring-kafka-streams 13 | 0.0.1-SNAPSHOT 14 | spring-kafka-streams 15 | Demo project for Spring Boot 16 | 17 | 18 | 11 19 | 7.1.0 20 | 2021.0.2 21 | 5.13.8 22 | 23 | 24 | 25 | 26 | nl.jtim 27 | avro-model 28 | ${project.version} 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-actuator 38 | 39 | 40 | 41 | org.springframework.kafka 42 | spring-kafka 43 | 44 | 45 | org.apache.kafka 46 | kafka-streams 47 | 48 | 49 | 50 | org.apache.kafka 51 | kafka-streams-test-utils 52 | test 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-webflux 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter-test 63 | test 64 | 65 | 66 | 67 | org.springframework.kafka 68 | spring-kafka-test 69 | test 70 | 71 | 72 | 75 | 76 | io.confluent 77 | kafka-avro-serializer 78 | ${confluent.kafka.version} 79 | 80 | 81 | 82 | io.confluent 83 | kafka-streams-avro-serde 84 | ${confluent.kafka.version} 85 | 86 | 87 | 88 | 89 | org.springframework.cloud 90 | spring-cloud-sleuth-zipkin 91 | 92 | 93 | org.springframework.cloud 94 | spring-cloud-starter-sleuth 95 | 96 | 97 | 98 | 99 | 100 | 101 | org.springframework.boot 102 | spring-boot-maven-plugin 103 | 104 | 105 | 106 | 107 | 108 | 109 | 112 | 113 | io.zipkin.brave 114 | brave-bom 115 | ${brave.version} 116 | pom 117 | import 118 | 119 | 120 | org.springframework.cloud 121 | spring-cloud-dependencies 122 | ${spring-cloud.version} 123 | pom 124 | import 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | confluent 133 | https://packages.confluent.io/maven/ 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /spring-kafka-streams/src/main/java/nl/jtim/kafka/streams/SpringKafkaStreamsApplication.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.kafka.streams; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringKafkaStreamsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringKafkaStreamsApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-kafka-streams/src/main/java/nl/jtim/kafka/streams/config/KafkaStreamsConfig.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.kafka.streams.config; 2 | 3 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 4 | import org.apache.kafka.streams.StreamsBuilder; 5 | import org.apache.kafka.streams.kstream.KStream; 6 | import org.apache.kafka.streams.kstream.Printed; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.kafka.annotation.EnableKafkaStreams; 10 | import org.springframework.kafka.support.KafkaStreamBrancher; 11 | 12 | import static nl.jtim.kafka.streams.config.KafkaTopicsConfiguration.STOCK_QUOTES_TOPIC_NAME; 13 | 14 | @Configuration 15 | @EnableKafkaStreams 16 | public class KafkaStreamsConfig { 17 | 18 | @Bean 19 | public KStream kStream(StreamsBuilder streamsBuilder) { 20 | 21 | KStream stream = streamsBuilder.stream(STOCK_QUOTES_TOPIC_NAME); 22 | stream.print(Printed.toSysOut()); 23 | 24 | KStream branchedStream = new KafkaStreamBrancher() 25 | .branch((key, value) -> value.getExchange().equalsIgnoreCase("NYSE"), kStream -> kStream.to("stock-quotes-exchange-nyse")) 26 | .branch((key, value) -> value.getExchange().equalsIgnoreCase("NASDAQ"), kStream -> kStream.to("stock-quotes-exchange-nasdaq")) 27 | .branch((key, value) -> value.getExchange().equalsIgnoreCase("AMS"), kStream -> kStream.to("stock-quotes-exchange-ams")) 28 | .defaultBranch(kStream -> kStream.to("stock-quotes-exchange-other")) 29 | .onTopOf(streamsBuilder.stream(STOCK_QUOTES_TOPIC_NAME)); 30 | 31 | branchedStream.print(Printed.toSysOut()); 32 | 33 | return branchedStream; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-kafka-streams/src/main/java/nl/jtim/kafka/streams/config/KafkaStreamsExceptionHandlingConfig.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.kafka.streams.config; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerRecord; 4 | import org.apache.kafka.common.TopicPartition; 5 | import org.springframework.boot.autoconfigure.kafka.KafkaProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.kafka.annotation.KafkaStreamsDefaultConfiguration; 9 | import org.springframework.kafka.config.KafkaStreamsConfiguration; 10 | import org.springframework.kafka.core.KafkaOperations; 11 | import org.springframework.kafka.core.KafkaTemplate; 12 | import org.springframework.kafka.listener.DeadLetterPublishingRecoverer; 13 | import org.springframework.kafka.streams.RecoveringDeserializationExceptionHandler; 14 | 15 | import java.util.LinkedHashMap; 16 | import java.util.Map; 17 | import java.util.function.BiFunction; 18 | 19 | @Configuration 20 | public class KafkaStreamsExceptionHandlingConfig { 21 | 22 | private static final BiFunction, Exception, TopicPartition> 23 | CUSTOM_DESTINATION_RESOLVER = (cr, e) -> new TopicPartition(cr.topic() + ".DEAD_LETTER_TOPIC", cr.partition()); 24 | 25 | @Bean(name = KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME) 26 | public KafkaStreamsConfiguration kStreamsConfigs(KafkaProperties kafkaProperties, DeadLetterPublishingRecoverer deadLetterPublishingRecoverer) { 27 | Map properties = kafkaProperties.getStreams().buildProperties(); 28 | 29 | properties.put(RecoveringDeserializationExceptionHandler.KSTREAM_DESERIALIZATION_RECOVERER, deadLetterPublishingRecoverer); 30 | 31 | return new KafkaStreamsConfiguration(properties); 32 | } 33 | 34 | @Bean 35 | public DeadLetterPublishingRecoverer recoverer(KafkaTemplate bytesTemplate) { 36 | Map, KafkaOperations> templates = new LinkedHashMap<>(); 37 | templates.put(byte[].class, bytesTemplate); 38 | 39 | // In case you want to customize the destination resolver 40 | return new DeadLetterPublishingRecoverer(templates, CUSTOM_DESTINATION_RESOLVER); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-kafka-streams/src/main/java/nl/jtim/kafka/streams/config/KafkaTopicsConfiguration.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.kafka.streams.config; 2 | 3 | import org.apache.kafka.clients.admin.NewTopic; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.kafka.config.TopicBuilder; 7 | 8 | @Configuration 9 | public class KafkaTopicsConfiguration { 10 | 11 | public final static String STOCK_QUOTES_TOPIC_NAME = "stock-quotes"; 12 | public final static String STOCK_QUOTES_EXCHANGE_NYSE_TOPIC_NAME = "stock-quotes-exchange-nyse"; 13 | public final static String STOCK_QUOTES_EXCHANGE_NASDAQ_TOPIC_NAME = "stock-quotes-exchange-nasdaq"; 14 | public final static String STOCK_QUOTES_EXCHANGE_AMS_TOPIC_NAME = "stock-quotes-exchange-ams"; 15 | public final static String STOCK_QUOTES_EXCHANGE_OTHER_TOPIC_NAME = "stock-quotes-exchange-other"; 16 | 17 | @Bean 18 | public NewTopic stockQuotes() { 19 | return TopicBuilder.name(STOCK_QUOTES_TOPIC_NAME) 20 | .build(); 21 | } 22 | 23 | @Bean 24 | public NewTopic stockQuotesNyse() { 25 | return TopicBuilder.name(STOCK_QUOTES_EXCHANGE_NYSE_TOPIC_NAME) 26 | .build(); 27 | } 28 | 29 | @Bean 30 | public NewTopic stockQuotesNasdaq() { 31 | return TopicBuilder.name(STOCK_QUOTES_EXCHANGE_NASDAQ_TOPIC_NAME) 32 | .build(); 33 | } 34 | 35 | @Bean 36 | public NewTopic stockQuotesAmsterdam() { 37 | return TopicBuilder.name(STOCK_QUOTES_EXCHANGE_OTHER_TOPIC_NAME) 38 | .build(); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-kafka-streams/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | 4 | spring: 5 | application: 6 | name: streams-application 7 | 8 | kafka: 9 | bootstrap-servers: localhost:9092 10 | 11 | producer: 12 | # Important! 13 | # In case you publish to a 'dead letter topic' your application becomes 14 | # a producer as well! So you need to specify the producer properties! 15 | key-serializer: org.apache.kafka.common.serialization.ByteArraySerializer 16 | value-serializer: org.apache.kafka.common.serialization.ByteArraySerializer 17 | 18 | streams: 19 | application-id: ${spring.application.name} 20 | bootstrap-servers: ${spring.kafka.bootstrap-servers} 21 | # This setting is here to don't wait until the buffer is full 22 | cache-max-size-buffering: 0 23 | properties: 24 | schema.registry.url: http://localhost:8081 25 | default.key.serde: org.apache.kafka.common.serialization.Serdes$StringSerde 26 | default.value.serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde 27 | # LogAndFailExceptionHandler is the default! 28 | default.deserialization.exception.handler: org.apache.kafka.streams.errors.LogAndFailExceptionHandler 29 | # default.deserialization.exception.handler: org.apache.kafka.streams.errors.LogAndContinueExceptionHandler 30 | # default.deserialization.exception.handler: org.springframework.kafka.streams.RecoveringDeserializationExceptionHandler 31 | 32 | # Open up all Spring Boot Actuator endpoints 33 | management: 34 | endpoints: 35 | web: 36 | exposure: 37 | include: "*" 38 | 39 | endpoint: 40 | health: 41 | show-details: always -------------------------------------------------------------------------------- /spring-kafka-streams/src/test/java/nl/jtim/kafka/streams/TopologyTestDriverAvroTest.java: -------------------------------------------------------------------------------- 1 | package nl.jtim.kafka.streams; 2 | 3 | import io.confluent.kafka.schemaregistry.testutil.MockSchemaRegistry; 4 | import io.confluent.kafka.serializers.AbstractKafkaSchemaSerDeConfig; 5 | import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde; 6 | import nl.jtim.kafka.streams.config.KafkaStreamsConfig; 7 | import nl.jtim.spring.kafka.avro.stock.quote.StockQuote; 8 | import org.apache.kafka.common.serialization.Serde; 9 | import org.apache.kafka.common.serialization.Serdes; 10 | import org.apache.kafka.streams.*; 11 | import org.junit.jupiter.api.AfterEach; 12 | import org.junit.jupiter.api.BeforeEach; 13 | import org.junit.jupiter.api.Test; 14 | 15 | import java.time.Instant; 16 | import java.util.Map; 17 | import java.util.Properties; 18 | 19 | import static nl.jtim.kafka.streams.config.KafkaTopicsConfiguration.*; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | /** 23 | * Unit test for Kafka streams application using the 24 | * Kafka streams {@link TopologyTestDriver} 25 | */ 26 | public class TopologyTestDriverAvroTest { 27 | 28 | private static final String SCHEMA_REGISTRY_SCOPE = TopologyTestDriverAvroTest.class.getName(); 29 | 30 | private static final String MOCK_SCHEMA_REGISTRY_URL = "mock://" + SCHEMA_REGISTRY_SCOPE; 31 | private TopologyTestDriver topologyTestDriver; 32 | 33 | private TestInputTopic stockQuoteInputTopic; 34 | private TestOutputTopic stockQuoteNyseOutputTopic; 35 | private TestOutputTopic stockQuoteNasdaqOutputTopic; 36 | private TestOutputTopic stockQuoteAmsOutputTopic; 37 | private TestOutputTopic stockQuoteOtherOutputTopic; 38 | 39 | @BeforeEach 40 | void setUp() { 41 | StreamsBuilder builder = new StreamsBuilder(); 42 | new KafkaStreamsConfig().kStream(builder); 43 | Topology topology = builder.build(); 44 | 45 | Properties properties = new Properties(); 46 | properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "unit-test"); 47 | properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:9092"); 48 | properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.StringSerde.class); 49 | properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, SpecificAvroSerde.class); 50 | properties.put(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, MOCK_SCHEMA_REGISTRY_URL); 51 | 52 | topologyTestDriver = new TopologyTestDriver(topology, properties); 53 | 54 | Serde stringSerde = Serdes.String(); 55 | Serde avroStockQuoteSerde = new SpecificAvroSerde<>(); 56 | 57 | Map schemaRegistryProperties = Map.of(AbstractKafkaSchemaSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, MOCK_SCHEMA_REGISTRY_URL); 58 | avroStockQuoteSerde.configure(schemaRegistryProperties, false); 59 | 60 | // Define input and output topics to use in tests 61 | stockQuoteInputTopic = topologyTestDriver.createInputTopic( 62 | STOCK_QUOTES_TOPIC_NAME, 63 | stringSerde.serializer(), 64 | avroStockQuoteSerde.serializer()); 65 | 66 | stockQuoteNyseOutputTopic = topologyTestDriver.createOutputTopic( 67 | STOCK_QUOTES_EXCHANGE_NYSE_TOPIC_NAME, 68 | stringSerde.deserializer(), 69 | avroStockQuoteSerde.deserializer()); 70 | 71 | stockQuoteNasdaqOutputTopic = topologyTestDriver.createOutputTopic( 72 | STOCK_QUOTES_EXCHANGE_NASDAQ_TOPIC_NAME, 73 | stringSerde.deserializer(), 74 | avroStockQuoteSerde.deserializer()); 75 | 76 | stockQuoteAmsOutputTopic = topologyTestDriver.createOutputTopic( 77 | STOCK_QUOTES_EXCHANGE_AMS_TOPIC_NAME, 78 | stringSerde.deserializer(), 79 | avroStockQuoteSerde.deserializer()); 80 | 81 | stockQuoteOtherOutputTopic = topologyTestDriver.createOutputTopic( 82 | STOCK_QUOTES_EXCHANGE_OTHER_TOPIC_NAME, 83 | stringSerde.deserializer(), 84 | avroStockQuoteSerde.deserializer()); 85 | } 86 | 87 | @AfterEach 88 | void tearDown() { 89 | topologyTestDriver.close(); 90 | MockSchemaRegistry.dropScope(SCHEMA_REGISTRY_SCOPE); 91 | } 92 | 93 | @Test 94 | void stockQuoteFromAmsterdamStockExchangeEndUpOnTopicQuotesAmsTopic() { 95 | StockQuote stockQuote = new StockQuote("INGA", "AMS", "10.99", "EUR", "Description", Instant.now()); 96 | 97 | stockQuoteInputTopic.pipeInput(stockQuote.getSymbol(), stockQuote); 98 | 99 | assertThat(stockQuoteAmsOutputTopic.isEmpty()).isFalse(); 100 | assertThat(stockQuoteAmsOutputTopic.getQueueSize()).isEqualTo(1L); 101 | assertThat(stockQuoteAmsOutputTopic.readValue()).isEqualTo(stockQuote); 102 | 103 | assertThat(stockQuoteNyseOutputTopic.isEmpty()).isTrue(); 104 | assertThat(stockQuoteNasdaqOutputTopic.isEmpty()).isTrue(); 105 | assertThat(stockQuoteOtherOutputTopic.isEmpty()).isTrue(); 106 | } 107 | } 108 | --------------------------------------------------------------------------------