├── Data Analysis.ipynb ├── Machine Learing.ipynb ├── README.md ├── Sample.ipynb ├── Spring-boot-Kafka-Mocroservices ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alanbinu │ │ │ └── Spring │ │ │ └── boot │ │ │ └── Kafka │ │ │ └── Mocroservices │ │ │ ├── Config │ │ │ ├── KafkaConsumerConfig.java │ │ │ ├── KafkaProducerConfig.java │ │ │ └── KafkaTopicConfig.java │ │ │ ├── Controller │ │ │ ├── MessageController.java │ │ │ └── MessageRequest.java │ │ │ ├── Listener │ │ │ └── KafkaListener.java │ │ │ └── SpringBootKafkaMocroservicesApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── alanbinu │ └── Spring │ └── boot │ └── Kafka │ └── Mocroservices │ └── SpringBootKafkaMocroservicesApplicationTests.java ├── SpringBootKafka-producer and consumer ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── demo │ │ │ ├── KafkaProducerConsumerApplication.java │ │ │ ├── controller │ │ │ └── KafkaController.java │ │ │ └── service │ │ │ ├── Consumer.java │ │ │ └── Producer.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── example │ └── demo │ └── KafkaProducerConsumerApplicationTests.java ├── countries.csv ├── data visulization.ipynb ├── sample_data.csv ├── spring-boot-kafka-producer-example ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── alanbinu │ │ │ └── kafka │ │ │ └── springbootkafkaproducerexample │ │ │ ├── SpringBootKafkaProducerExampleApplication.java │ │ │ ├── config │ │ │ └── KakfaConfiguration.java │ │ │ ├── model │ │ │ └── User.java │ │ │ └── resource │ │ │ └── UserResource.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── alanbinu │ └── kafka │ └── springbootkafkaproducerexample │ └── SpringBootKafkaProducerExampleApplicationTests.java ├── springboot-kafka-advanced-project-setup ├── consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ ├── KafkaConsumerApplication.java │ │ │ ├── config │ │ │ └── KafkaConsumerConfig.java │ │ │ └── service │ │ │ └── KafkaReciever.java │ │ └── resources │ │ └── application.yml ├── model │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── springboot │ │ └── model │ │ ├── Address.java │ │ └── Student.java └── producer │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── springboot │ │ ├── KafkaProducerApplication.java │ │ ├── config │ │ └── KafkaProducerConfig.java │ │ ├── ctrl │ │ └── KafkaProducerController.java │ │ └── service │ │ └── KafkaSender.java │ └── resources │ └── application.yml ├── springboot-kafka-basic ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── kafka │ │ │ └── springbootkafka │ │ │ ├── Consumer.java │ │ │ ├── Producer.java │ │ │ ├── SpringbootKafkaApplication.java │ │ │ └── TestController.java │ └── resources │ │ ├── application.properties │ │ └── application.yml │ └── test │ └── java │ └── com │ └── example │ └── kafka │ └── springbootkafka │ └── SpringbootKafkaApplicationTests.java └── tic-tac-toe-AI.py /Data Analysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [] 9 | } 10 | ], 11 | "metadata": { 12 | "kernelspec": { 13 | "display_name": "Python 3", 14 | "language": "python", 15 | "name": "python3" 16 | }, 17 | "language_info": { 18 | "codemirror_mode": { 19 | "name": "ipython", 20 | "version": 3 21 | }, 22 | "file_extension": ".py", 23 | "mimetype": "text/x-python", 24 | "name": "python", 25 | "nbconvert_exporter": "python", 26 | "pygments_lexer": "ipython3", 27 | "version": "3.7.3" 28 | } 29 | }, 30 | "nbformat": 4, 31 | "nbformat_minor": 2 32 | } 33 | -------------------------------------------------------------------------------- /Machine Learing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import sklearn" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 3, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "from sklearn import tree" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 4, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "feature = [[140,1], [130,1], [150,0], [170,0]]" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 5, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "labels = [0,0,1,1]" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 6, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "clf = tree.DecisionTreeClassifier()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 7, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "clf = clf.fit(feature, labels)" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 8, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "[0]\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "print (clf.predict([[140 ,1]]))" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 36, 77 | "metadata": {}, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "Hai\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "print (\"Hai\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 37, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "ename": "SyntaxError", 98 | "evalue": "invalid syntax (, line 1)", 99 | "output_type": "error", 100 | "traceback": [ 101 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m print clf.predict([[150 ,0]])\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 102 | ] 103 | } 104 | ], 105 | "source": [] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 38, 110 | "metadata": {}, 111 | "outputs": [ 112 | { 113 | "ename": "SyntaxError", 114 | "evalue": "invalid syntax (, line 1)", 115 | "output_type": "error", 116 | "traceback": [ 117 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m print clf.predict([[130 ,1]])\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 118 | ] 119 | } 120 | ], 121 | "source": [ 122 | "print clf.predict([[130 ,1]])" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.7.3" 150 | } 151 | }, 152 | "nbformat": 4, 153 | "nbformat_minor": 2 154 | } 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # AI, KAFKA, Big-Data Data-Engineering and Distributions 3 | 4 | 5 | ## Features 6 | 7 | - Kafka 8 | - Kafka sending data using REST API 9 | - Kafka Consumer and Producer 10 | - Data Cleaning 11 | - Data Virtualization 12 | - Machine Learing 13 | - Simple AI project 14 | 15 | ## Steps to run in your machine for Kafka 16 | 17 | #### Kafka Quick Start : https://kafka.apache.org/quickstart 18 | 19 | ``` 20 | clone the repo 21 | ``` 22 | 23 | #### Run as following to Start the Kafka 24 | Go to your Kafka dir 25 | ``` 26 | \bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties 27 | 28 | \bin\windows\kafka-server-start.bat .\config\server.properties 29 | ``` 30 | #### Run the project 31 | Open the project in any Ide, then run as spring boot appication 32 | ``` 33 | Try Chnage your Tpoic name as you wish. Here we used "alanbinu" 34 | ``` 35 | 36 | Try the following in any API builder 37 | ``` 38 | http://localhost:8081/api/v1/message 39 | ``` 40 | Body 41 | ``` 42 | { 43 | "message":"It works. Thanks Alan" 44 | } 45 | ``` 46 | To see the Data from Kafka, follow the below steps 47 | 48 | Go to the Kafka Dir, then the run the following command 49 | ``` 50 | bin\windows\kafka-console-consumer.sh --topic --from-beginning --bootstrap-server localhost: 51 | ``` 52 |


53 | ## Steps to run in your machine for Data Virtulization, Machine Learing or Data Cleaning 54 | ``` 55 | clone the repo 56 | ``` 57 | 58 | #### Follow the steps 59 | Install Jupyter Notebook : https://jupyter.org/install 60 | Open Jupyter Notebook and the open the file you need to run and then Click on the "Run from Start" 61 | 62 | 63 | #### Hope you liked this project, dont forget to ⭐ the repo. 64 | -------------------------------------------------------------------------------- /Sample.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [] 9 | } 10 | ], 11 | "metadata": { 12 | "kernelspec": { 13 | "display_name": "Python 3", 14 | "language": "python", 15 | "name": "python3" 16 | }, 17 | "language_info": { 18 | "codemirror_mode": { 19 | "name": "ipython", 20 | "version": 3 21 | }, 22 | "file_extension": ".py", 23 | "mimetype": "text/x-python", 24 | "name": "python", 25 | "nbconvert_exporter": "python", 26 | "pygments_lexer": "ipython3", 27 | "version": "3.7.3" 28 | } 29 | }, 30 | "nbformat": 4, 31 | "nbformat_minor": 2 32 | } 33 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.4 9 | 10 | 11 | com.alanbinu 12 | Spring-boot-Kafka-Mocroservices 13 | 0.0.1-SNAPSHOT 14 | Spring-boot-Kafka-Mocroservices 15 | Demo project for Spring Boot 16 | 17 | 11 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.springframework.kafka 26 | spring-kafka 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-test 32 | test 33 | 34 | 35 | org.springframework.kafka 36 | spring-kafka-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-compiler-plugin 50 | 51 | 16 52 | 16 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/Config/KafkaConsumerConfig.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices.Config; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerConfig; 4 | import org.apache.kafka.common.serialization.StringSerializer; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 9 | import org.springframework.kafka.config.KafkaListenerContainerFactory; 10 | import org.springframework.kafka.core.ConsumerFactory; 11 | import org.springframework.kafka.core.DefaultKafkaConsumerFactory; 12 | import org.springframework.kafka.listener.ConcurrentMessageListenerContainer; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Configuration 18 | public class KafkaConsumerConfig { 19 | 20 | @Value("${spring.kafka.bootstrap-servers}") 21 | private String bootstrpServer; 22 | 23 | public Map consumerConfig(){ 24 | HashMap props = new HashMap<>(); 25 | props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrpServer); 26 | props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringSerializer.class); 27 | props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringSerializer.class); 28 | return props; 29 | } 30 | 31 | @Bean 32 | public ConsumerFactory consumerFactory(){ 33 | return new DefaultKafkaConsumerFactory<>(consumerConfig()); 34 | } 35 | 36 | public KafkaListenerContainerFactory> factory( 37 | ConsumerFactory consumerFactory 38 | ){ 39 | ConcurrentKafkaListenerContainerFactory factory = 40 | new ConcurrentKafkaListenerContainerFactory<>(); 41 | factory.setConsumerFactory(consumerFactory); 42 | return factory; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/Config/KafkaProducerConfig.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices.Config; 2 | 3 | import org.apache.kafka.clients.producer.ProducerConfig; 4 | import org.apache.kafka.common.serialization.StringSerializer; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 9 | import org.springframework.kafka.core.KafkaTemplate; 10 | import org.springframework.kafka.core.ProducerFactory; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | @Configuration 16 | public class KafkaProducerConfig { 17 | 18 | @Value("${spring.kafka.bootstrap-servers}") 19 | private String bootstrpServer; 20 | 21 | public Map producerConfig(){ 22 | HashMap props = new HashMap<>(); 23 | props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrpServer); 24 | props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 25 | props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 26 | return props; 27 | } 28 | 29 | @Bean 30 | public ProducerFactory produccerFactory(){ 31 | return new DefaultKafkaProducerFactory<>(producerConfig()); 32 | } 33 | 34 | @Bean 35 | public KafkaTemplate kafkaTemplate(ProducerFactory produccerFactory){ 36 | return new KafkaTemplate<>(produccerFactory); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/Config/KafkaTopicConfig.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices.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 KafkaTopicConfig { 10 | 11 | @Bean 12 | public NewTopic alanTopic(){ 13 | return TopicBuilder.name("alanbinu").build(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/Controller/MessageController.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices.Controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.kafka.core.KafkaTemplate; 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 | @RestController 11 | @RequestMapping("api/v1/message") 12 | public class MessageController { 13 | 14 | @Autowired 15 | private KafkaTemplate kafkaTemplate; 16 | 17 | public MessageController(KafkaTemplate kafkaTemplate){ 18 | this.kafkaTemplate = kafkaTemplate; 19 | } 20 | 21 | @PostMapping 22 | public void publish(@RequestBody MessageRequest request){ 23 | kafkaTemplate.send("alanbinu",request.message()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/Controller/MessageRequest.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices.Controller; 2 | 3 | public record MessageRequest(String message) { 4 | } 5 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/Listener/KafkaListener.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices.Listener; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class KafkaListener { 7 | 8 | @org.springframework.kafka.annotation.KafkaListener(topics = "alanbinu",groupId = "groupID") 9 | void Listener(String data){ 10 | System.out.println("Received the data : "+data+" "); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/SpringBootKafkaMocroservicesApplication.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.kafka.core.KafkaTemplate; 8 | 9 | @SpringBootApplication 10 | public class SpringBootKafkaMocroservicesApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootKafkaMocroservicesApplication.class, args); 14 | } 15 | 16 | @Bean 17 | CommandLineRunner commandLineRunner(KafkaTemplate kafkaTemplate){ 18 | return args -> { 19 | for (int i = 0; i < 100; i++) { 20 | kafkaTemplate.send("alanbinu", "hello Alan "+i); 21 | } 22 | }; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.kafka.bootstrap-servers=localhost:9092 2 | server.port=8081 -------------------------------------------------------------------------------- /Spring-boot-Kafka-Mocroservices/src/test/java/com/alanbinu/Spring/boot/Kafka/Mocroservices/SpringBootKafkaMocroservicesApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.Spring.boot.Kafka.Mocroservices; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringBootKafkaMocroservicesApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.3 9 | 10 | 11 | com.example 12 | KafkaProducerConsumer 13 | 0.0.1-SNAPSHOT 14 | KafkaProducerConsumer 15 | Demo project for Spring Boot 16 | 17 | 11 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.springframework.kafka 26 | spring-kafka 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-test 32 | test 33 | 34 | 35 | org.springframework.kafka 36 | spring-kafka-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/src/main/java/com/example/demo/KafkaProducerConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KafkaProducerConsumerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KafkaProducerConsumerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/src/main/java/com/example/demo/controller/KafkaController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.example.demo.service.Producer; 10 | 11 | @RestController 12 | @RequestMapping("/kafkaapp") 13 | public class KafkaController { 14 | 15 | @Autowired 16 | Producer producer; 17 | 18 | @PostMapping(value="/post") 19 | public void sendMessage(@RequestParam("msg") String msg) { 20 | producer.publishToTopic(msg); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/src/main/java/com/example/demo/service/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import org.springframework.kafka.annotation.KafkaListener; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class Consumer { 8 | 9 | @KafkaListener(topics="mytopic", groupId="mygroup") 10 | public void consumeFromTopic(String message) { 11 | System.out.println("Consummed message "+message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/src/main/java/com/example/demo/service/Producer.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.kafka.core.KafkaTemplate; 5 | import org.springframework.stereotype.Service; 6 | 7 | @Service 8 | public class Producer { 9 | public static final String topic = "mytopic"; 10 | 11 | @Autowired 12 | private KafkaTemplate kafkaTemp; 13 | 14 | public void publishToTopic(String message) { 15 | System.out.println("Publishing to topic "+topic); 16 | this.kafkaTemp.send(topic, message); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port= 8888 2 | 3 | spring.kafka.consumer.bootstrap-servers=localhost:9092 4 | spring.kafka.consumer.group-id=mygroup 5 | spring.kafka.consumer.auto-offset-reset=earliest 6 | spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer 7 | spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer 8 | 9 | spring.kafka.producer.bootstrap-servers=localhost:9092 10 | spring.kafka.producer.key-deserializer = org.apache.kafka.common.serialization.StringDeserializer 11 | spring.kafka.producer.value-deserializer = org.apache.kafka.common.serialization.StringDeserializer -------------------------------------------------------------------------------- /SpringBootKafka-producer and consumer/src/test/java/com/example/demo/KafkaProducerConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class KafkaProducerConsumerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /countries.csv: -------------------------------------------------------------------------------- 1 | country,year,population 2 | Afghanistan,1952,8425333 3 | Afghanistan,1957,9240934 4 | Afghanistan,1962,10267083 5 | Afghanistan,1967,11537966 6 | Afghanistan,1972,13079460 7 | Afghanistan,1977,14880372 8 | Afghanistan,1982,12881816 9 | Afghanistan,1987,13867957 10 | Afghanistan,1992,16317921 11 | Afghanistan,1997,22227415 12 | Afghanistan,2002,25268405 13 | Afghanistan,2007,31889923 14 | Albania,1952,1282697 15 | Albania,1957,1476505 16 | Albania,1962,1728137 17 | Albania,1967,1984060 18 | Albania,1972,2263554 19 | Albania,1977,2509048 20 | Albania,1982,2780097 21 | Albania,1987,3075321 22 | Albania,1992,3326498 23 | Albania,1997,3428038 24 | Albania,2002,3508512 25 | Albania,2007,3600523 26 | Algeria,1952,9279525 27 | Algeria,1957,10270856 28 | Algeria,1962,11000948 29 | Algeria,1967,12760499 30 | Algeria,1972,14760787 31 | Algeria,1977,17152804 32 | Algeria,1982,20033753 33 | Algeria,1987,23254956 34 | Algeria,1992,26298373 35 | Algeria,1997,29072015 36 | Algeria,2002,31287142 37 | Algeria,2007,33333216 38 | Angola,1952,4232095 39 | Angola,1957,4561361 40 | Angola,1962,4826015 41 | Angola,1967,5247469 42 | Angola,1972,5894858 43 | Angola,1977,6162675 44 | Angola,1982,7016384 45 | Angola,1987,7874230 46 | Angola,1992,8735988 47 | Angola,1997,9875024 48 | Angola,2002,10866106 49 | Angola,2007,12420476 50 | Argentina,1952,17876956 51 | Argentina,1957,19610538 52 | Argentina,1962,21283783 53 | Argentina,1967,22934225 54 | Argentina,1972,24779799 55 | Argentina,1977,26983828 56 | Argentina,1982,29341374 57 | Argentina,1987,31620918 58 | Argentina,1992,33958947 59 | Argentina,1997,36203463 60 | Argentina,2002,38331121 61 | Argentina,2007,40301927 62 | Australia,1952,8691212 63 | Australia,1957,9712569 64 | Australia,1962,10794968 65 | Australia,1967,11872264 66 | Australia,1972,13177000 67 | Australia,1977,14074100 68 | Australia,1982,15184200 69 | Australia,1987,16257249 70 | Australia,1992,17481977 71 | Australia,1997,18565243 72 | Australia,2002,19546792 73 | Australia,2007,20434176 74 | Austria,1952,6927772 75 | Austria,1957,6965860 76 | Austria,1962,7129864 77 | Austria,1967,7376998 78 | Austria,1972,7544201 79 | Austria,1977,7568430 80 | Austria,1982,7574613 81 | Austria,1987,7578903 82 | Austria,1992,7914969 83 | Austria,1997,8069876 84 | Austria,2002,8148312 85 | Austria,2007,8199783 86 | Bahrain,1952,120447 87 | Bahrain,1957,138655 88 | Bahrain,1962,171863 89 | Bahrain,1967,202182 90 | Bahrain,1972,230800 91 | Bahrain,1977,297410 92 | Bahrain,1982,377967 93 | Bahrain,1987,454612 94 | Bahrain,1992,529491 95 | Bahrain,1997,598561 96 | Bahrain,2002,656397 97 | Bahrain,2007,708573 98 | Bangladesh,1952,46886859 99 | Bangladesh,1957,51365468 100 | Bangladesh,1962,56839289 101 | Bangladesh,1967,62821884 102 | Bangladesh,1972,70759295 103 | Bangladesh,1977,80428306 104 | Bangladesh,1982,93074406 105 | Bangladesh,1987,103764241 106 | Bangladesh,1992,113704579 107 | Bangladesh,1997,123315288 108 | Bangladesh,2002,135656790 109 | Bangladesh,2007,150448339 110 | Belgium,1952,8730405 111 | Belgium,1957,8989111 112 | Belgium,1962,9218400 113 | Belgium,1967,9556500 114 | Belgium,1972,9709100 115 | Belgium,1977,9821800 116 | Belgium,1982,9856303 117 | Belgium,1987,9870200 118 | Belgium,1992,10045622 119 | Belgium,1997,10199787 120 | Belgium,2002,10311970 121 | Belgium,2007,10392226 122 | Benin,1952,1738315 123 | Benin,1957,1925173 124 | Benin,1962,2151895 125 | Benin,1967,2427334 126 | Benin,1972,2761407 127 | Benin,1977,3168267 128 | Benin,1982,3641603 129 | Benin,1987,4243788 130 | Benin,1992,4981671 131 | Benin,1997,6066080 132 | Benin,2002,7026113 133 | Benin,2007,8078314 134 | Bolivia,1952,2883315 135 | Bolivia,1957,3211738 136 | Bolivia,1962,3593918 137 | Bolivia,1967,4040665 138 | Bolivia,1972,4565872 139 | Bolivia,1977,5079716 140 | Bolivia,1982,5642224 141 | Bolivia,1987,6156369 142 | Bolivia,1992,6893451 143 | Bolivia,1997,7693188 144 | Bolivia,2002,8445134 145 | Bolivia,2007,9119152 146 | Bosnia and Herzegovina,1952,2791000 147 | Bosnia and Herzegovina,1957,3076000 148 | Bosnia and Herzegovina,1962,3349000 149 | Bosnia and Herzegovina,1967,3585000 150 | Bosnia and Herzegovina,1972,3819000 151 | Bosnia and Herzegovina,1977,4086000 152 | Bosnia and Herzegovina,1982,4172693 153 | Bosnia and Herzegovina,1987,4338977 154 | Bosnia and Herzegovina,1992,4256013 155 | Bosnia and Herzegovina,1997,3607000 156 | Bosnia and Herzegovina,2002,4165416 157 | Bosnia and Herzegovina,2007,4552198 158 | Botswana,1952,442308 159 | Botswana,1957,474639 160 | Botswana,1962,512764 161 | Botswana,1967,553541 162 | Botswana,1972,619351 163 | Botswana,1977,781472 164 | Botswana,1982,970347 165 | Botswana,1987,1151184 166 | Botswana,1992,1342614 167 | Botswana,1997,1536536 168 | Botswana,2002,1630347 169 | Botswana,2007,1639131 170 | Brazil,1952,56602560 171 | Brazil,1957,65551171 172 | Brazil,1962,76039390 173 | Brazil,1967,88049823 174 | Brazil,1972,100840058 175 | Brazil,1977,114313951 176 | Brazil,1982,128962939 177 | Brazil,1987,142938076 178 | Brazil,1992,155975974 179 | Brazil,1997,168546719 180 | Brazil,2002,179914212 181 | Brazil,2007,190010647 182 | Bulgaria,1952,7274900 183 | Bulgaria,1957,7651254 184 | Bulgaria,1962,8012946 185 | Bulgaria,1967,8310226 186 | Bulgaria,1972,8576200 187 | Bulgaria,1977,8797022 188 | Bulgaria,1982,8892098 189 | Bulgaria,1987,8971958 190 | Bulgaria,1992,8658506 191 | Bulgaria,1997,8066057 192 | Bulgaria,2002,7661799 193 | Bulgaria,2007,7322858 194 | Burkina Faso,1952,4469979 195 | Burkina Faso,1957,4713416 196 | Burkina Faso,1962,4919632 197 | Burkina Faso,1967,5127935 198 | Burkina Faso,1972,5433886 199 | Burkina Faso,1977,5889574 200 | Burkina Faso,1982,6634596 201 | Burkina Faso,1987,7586551 202 | Burkina Faso,1992,8878303 203 | Burkina Faso,1997,10352843 204 | Burkina Faso,2002,12251209 205 | Burkina Faso,2007,14326203 206 | Burundi,1952,2445618 207 | Burundi,1957,2667518 208 | Burundi,1962,2961915 209 | Burundi,1967,3330989 210 | Burundi,1972,3529983 211 | Burundi,1977,3834415 212 | Burundi,1982,4580410 213 | Burundi,1987,5126023 214 | Burundi,1992,5809236 215 | Burundi,1997,6121610 216 | Burundi,2002,7021078 217 | Burundi,2007,8390505 218 | Cambodia,1952,4693836 219 | Cambodia,1957,5322536 220 | Cambodia,1962,6083619 221 | Cambodia,1967,6960067 222 | Cambodia,1972,7450606 223 | Cambodia,1977,6978607 224 | Cambodia,1982,7272485 225 | Cambodia,1987,8371791 226 | Cambodia,1992,10150094 227 | Cambodia,1997,11782962 228 | Cambodia,2002,12926707 229 | Cambodia,2007,14131858 230 | Cameroon,1952,5009067 231 | Cameroon,1957,5359923 232 | Cameroon,1962,5793633 233 | Cameroon,1967,6335506 234 | Cameroon,1972,7021028 235 | Cameroon,1977,7959865 236 | Cameroon,1982,9250831 237 | Cameroon,1987,10780667 238 | Cameroon,1992,12467171 239 | Cameroon,1997,14195809 240 | Cameroon,2002,15929988 241 | Cameroon,2007,17696293 242 | Canada,1952,14785584 243 | Canada,1957,17010154 244 | Canada,1962,18985849 245 | Canada,1967,20819767 246 | Canada,1972,22284500 247 | Canada,1977,23796400 248 | Canada,1982,25201900 249 | Canada,1987,26549700 250 | Canada,1992,28523502 251 | Canada,1997,30305843 252 | Canada,2002,31902268 253 | Canada,2007,33390141 254 | Central African Republic,1952,1291695 255 | Central African Republic,1957,1392284 256 | Central African Republic,1962,1523478 257 | Central African Republic,1967,1733638 258 | Central African Republic,1972,1927260 259 | Central African Republic,1977,2167533 260 | Central African Republic,1982,2476971 261 | Central African Republic,1987,2840009 262 | Central African Republic,1992,3265124 263 | Central African Republic,1997,3696513 264 | Central African Republic,2002,4048013 265 | Central African Republic,2007,4369038 266 | Chad,1952,2682462 267 | Chad,1957,2894855 268 | Chad,1962,3150417 269 | Chad,1967,3495967 270 | Chad,1972,3899068 271 | Chad,1977,4388260 272 | Chad,1982,4875118 273 | Chad,1987,5498955 274 | Chad,1992,6429417 275 | Chad,1997,7562011 276 | Chad,2002,8835739 277 | Chad,2007,10238807 278 | Chile,1952,6377619 279 | Chile,1957,7048426 280 | Chile,1962,7961258 281 | Chile,1967,8858908 282 | Chile,1972,9717524 283 | Chile,1977,10599793 284 | Chile,1982,11487112 285 | Chile,1987,12463354 286 | Chile,1992,13572994 287 | Chile,1997,14599929 288 | Chile,2002,15497046 289 | Chile,2007,16284741 290 | China,1952,556263527 291 | China,1957,637408000 292 | China,1962,665770000 293 | China,1967,754550000 294 | China,1972,862030000 295 | China,1977,943455000 296 | China,1982,1000281000 297 | China,1987,1084035000 298 | China,1992,1164970000 299 | China,1997,1230075000 300 | China,2002,1280400000 301 | China,2007,1318683096 302 | Colombia,1952,12350771 303 | Colombia,1957,14485993 304 | Colombia,1962,17009885 305 | Colombia,1967,19764027 306 | Colombia,1972,22542890 307 | Colombia,1977,25094412 308 | Colombia,1982,27764644 309 | Colombia,1987,30964245 310 | Colombia,1992,34202721 311 | Colombia,1997,37657830 312 | Colombia,2002,41008227 313 | Colombia,2007,44227550 314 | Comoros,1952,153936 315 | Comoros,1957,170928 316 | Comoros,1962,191689 317 | Comoros,1967,217378 318 | Comoros,1972,250027 319 | Comoros,1977,304739 320 | Comoros,1982,348643 321 | Comoros,1987,395114 322 | Comoros,1992,454429 323 | Comoros,1997,527982 324 | Comoros,2002,614382 325 | Comoros,2007,710960 326 | "Congo, Dem. Rep.",1952,14100005 327 | "Congo, Dem. Rep.",1957,15577932 328 | "Congo, Dem. Rep.",1962,17486434 329 | "Congo, Dem. Rep.",1967,19941073 330 | "Congo, Dem. Rep.",1972,23007669 331 | "Congo, Dem. Rep.",1977,26480870 332 | "Congo, Dem. Rep.",1982,30646495 333 | "Congo, Dem. Rep.",1987,35481645 334 | "Congo, Dem. Rep.",1992,41672143 335 | "Congo, Dem. Rep.",1997,47798986 336 | "Congo, Dem. Rep.",2002,55379852 337 | "Congo, Dem. Rep.",2007,64606759 338 | "Congo, Rep.",1952,854885 339 | "Congo, Rep.",1957,940458 340 | "Congo, Rep.",1962,1047924 341 | "Congo, Rep.",1967,1179760 342 | "Congo, Rep.",1972,1340458 343 | "Congo, Rep.",1977,1536769 344 | "Congo, Rep.",1982,1774735 345 | "Congo, Rep.",1987,2064095 346 | "Congo, Rep.",1992,2409073 347 | "Congo, Rep.",1997,2800947 348 | "Congo, Rep.",2002,3328795 349 | "Congo, Rep.",2007,3800610 350 | Costa Rica,1952,926317 351 | Costa Rica,1957,1112300 352 | Costa Rica,1962,1345187 353 | Costa Rica,1967,1588717 354 | Costa Rica,1972,1834796 355 | Costa Rica,1977,2108457 356 | Costa Rica,1982,2424367 357 | Costa Rica,1987,2799811 358 | Costa Rica,1992,3173216 359 | Costa Rica,1997,3518107 360 | Costa Rica,2002,3834934 361 | Costa Rica,2007,4133884 362 | Cote d'Ivoire,1952,2977019 363 | Cote d'Ivoire,1957,3300000 364 | Cote d'Ivoire,1962,3832408 365 | Cote d'Ivoire,1967,4744870 366 | Cote d'Ivoire,1972,6071696 367 | Cote d'Ivoire,1977,7459574 368 | Cote d'Ivoire,1982,9025951 369 | Cote d'Ivoire,1987,10761098 370 | Cote d'Ivoire,1992,12772596 371 | Cote d'Ivoire,1997,14625967 372 | Cote d'Ivoire,2002,16252726 373 | Cote d'Ivoire,2007,18013409 374 | Croatia,1952,3882229 375 | Croatia,1957,3991242 376 | Croatia,1962,4076557 377 | Croatia,1967,4174366 378 | Croatia,1972,4225310 379 | Croatia,1977,4318673 380 | Croatia,1982,4413368 381 | Croatia,1987,4484310 382 | Croatia,1992,4494013 383 | Croatia,1997,4444595 384 | Croatia,2002,4481020 385 | Croatia,2007,4493312 386 | Cuba,1952,6007797 387 | Cuba,1957,6640752 388 | Cuba,1962,7254373 389 | Cuba,1967,8139332 390 | Cuba,1972,8831348 391 | Cuba,1977,9537988 392 | Cuba,1982,9789224 393 | Cuba,1987,10239839 394 | Cuba,1992,10723260 395 | Cuba,1997,10983007 396 | Cuba,2002,11226999 397 | Cuba,2007,11416987 398 | Czech Republic,1952,9125183 399 | Czech Republic,1957,9513758 400 | Czech Republic,1962,9620282 401 | Czech Republic,1967,9835109 402 | Czech Republic,1972,9862158 403 | Czech Republic,1977,10161915 404 | Czech Republic,1982,10303704 405 | Czech Republic,1987,10311597 406 | Czech Republic,1992,10315702 407 | Czech Republic,1997,10300707 408 | Czech Republic,2002,10256295 409 | Czech Republic,2007,10228744 410 | Denmark,1952,4334000 411 | Denmark,1957,4487831 412 | Denmark,1962,4646899 413 | Denmark,1967,4838800 414 | Denmark,1972,4991596 415 | Denmark,1977,5088419 416 | Denmark,1982,5117810 417 | Denmark,1987,5127024 418 | Denmark,1992,5171393 419 | Denmark,1997,5283663 420 | Denmark,2002,5374693 421 | Denmark,2007,5468120 422 | Djibouti,1952,63149 423 | Djibouti,1957,71851 424 | Djibouti,1962,89898 425 | Djibouti,1967,127617 426 | Djibouti,1972,178848 427 | Djibouti,1977,228694 428 | Djibouti,1982,305991 429 | Djibouti,1987,311025 430 | Djibouti,1992,384156 431 | Djibouti,1997,417908 432 | Djibouti,2002,447416 433 | Djibouti,2007,496374 434 | Dominican Republic,1952,2491346 435 | Dominican Republic,1957,2923186 436 | Dominican Republic,1962,3453434 437 | Dominican Republic,1967,4049146 438 | Dominican Republic,1972,4671329 439 | Dominican Republic,1977,5302800 440 | Dominican Republic,1982,5968349 441 | Dominican Republic,1987,6655297 442 | Dominican Republic,1992,7351181 443 | Dominican Republic,1997,7992357 444 | Dominican Republic,2002,8650322 445 | Dominican Republic,2007,9319622 446 | Ecuador,1952,3548753 447 | Ecuador,1957,4058385 448 | Ecuador,1962,4681707 449 | Ecuador,1967,5432424 450 | Ecuador,1972,6298651 451 | Ecuador,1977,7278866 452 | Ecuador,1982,8365850 453 | Ecuador,1987,9545158 454 | Ecuador,1992,10748394 455 | Ecuador,1997,11911819 456 | Ecuador,2002,12921234 457 | Ecuador,2007,13755680 458 | Egypt,1952,22223309 459 | Egypt,1957,25009741 460 | Egypt,1962,28173309 461 | Egypt,1967,31681188 462 | Egypt,1972,34807417 463 | Egypt,1977,38783863 464 | Egypt,1982,45681811 465 | Egypt,1987,52799062 466 | Egypt,1992,59402198 467 | Egypt,1997,66134291 468 | Egypt,2002,73312559 469 | Egypt,2007,80264543 470 | El Salvador,1952,2042865 471 | El Salvador,1957,2355805 472 | El Salvador,1962,2747687 473 | El Salvador,1967,3232927 474 | El Salvador,1972,3790903 475 | El Salvador,1977,4282586 476 | El Salvador,1982,4474873 477 | El Salvador,1987,4842194 478 | El Salvador,1992,5274649 479 | El Salvador,1997,5783439 480 | El Salvador,2002,6353681 481 | El Salvador,2007,6939688 482 | Equatorial Guinea,1952,216964 483 | Equatorial Guinea,1957,232922 484 | Equatorial Guinea,1962,249220 485 | Equatorial Guinea,1967,259864 486 | Equatorial Guinea,1972,277603 487 | Equatorial Guinea,1977,192675 488 | Equatorial Guinea,1982,285483 489 | Equatorial Guinea,1987,341244 490 | Equatorial Guinea,1992,387838 491 | Equatorial Guinea,1997,439971 492 | Equatorial Guinea,2002,495627 493 | Equatorial Guinea,2007,551201 494 | Eritrea,1952,1438760 495 | Eritrea,1957,1542611 496 | Eritrea,1962,1666618 497 | Eritrea,1967,1820319 498 | Eritrea,1972,2260187 499 | Eritrea,1977,2512642 500 | Eritrea,1982,2637297 501 | Eritrea,1987,2915959 502 | Eritrea,1992,3668440 503 | Eritrea,1997,4058319 504 | Eritrea,2002,4414865 505 | Eritrea,2007,4906585 506 | Ethiopia,1952,20860941 507 | Ethiopia,1957,22815614 508 | Ethiopia,1962,25145372 509 | Ethiopia,1967,27860297 510 | Ethiopia,1972,30770372 511 | Ethiopia,1977,34617799 512 | Ethiopia,1982,38111756 513 | Ethiopia,1987,42999530 514 | Ethiopia,1992,52088559 515 | Ethiopia,1997,59861301 516 | Ethiopia,2002,67946797 517 | Ethiopia,2007,76511887 518 | Finland,1952,4090500 519 | Finland,1957,4324000 520 | Finland,1962,4491443 521 | Finland,1967,4605744 522 | Finland,1972,4639657 523 | Finland,1977,4738902 524 | Finland,1982,4826933 525 | Finland,1987,4931729 526 | Finland,1992,5041039 527 | Finland,1997,5134406 528 | Finland,2002,5193039 529 | Finland,2007,5238460 530 | France,1952,42459667 531 | France,1957,44310863 532 | France,1962,47124000 533 | France,1967,49569000 534 | France,1972,51732000 535 | France,1977,53165019 536 | France,1982,54433565 537 | France,1987,55630100 538 | France,1992,57374179 539 | France,1997,58623428 540 | France,2002,59925035 541 | France,2007,61083916 542 | Gabon,1952,420702 543 | Gabon,1957,434904 544 | Gabon,1962,455661 545 | Gabon,1967,489004 546 | Gabon,1972,537977 547 | Gabon,1977,706367 548 | Gabon,1982,753874 549 | Gabon,1987,880397 550 | Gabon,1992,985739 551 | Gabon,1997,1126189 552 | Gabon,2002,1299304 553 | Gabon,2007,1454867 554 | Gambia,1952,284320 555 | Gambia,1957,323150 556 | Gambia,1962,374020 557 | Gambia,1967,439593 558 | Gambia,1972,517101 559 | Gambia,1977,608274 560 | Gambia,1982,715523 561 | Gambia,1987,848406 562 | Gambia,1992,1025384 563 | Gambia,1997,1235767 564 | Gambia,2002,1457766 565 | Gambia,2007,1688359 566 | Germany,1952,69145952 567 | Germany,1957,71019069 568 | Germany,1962,73739117 569 | Germany,1967,76368453 570 | Germany,1972,78717088 571 | Germany,1977,78160773 572 | Germany,1982,78335266 573 | Germany,1987,77718298 574 | Germany,1992,80597764 575 | Germany,1997,82011073 576 | Germany,2002,82350671 577 | Germany,2007,82400996 578 | Ghana,1952,5581001 579 | Ghana,1957,6391288 580 | Ghana,1962,7355248 581 | Ghana,1967,8490213 582 | Ghana,1972,9354120 583 | Ghana,1977,10538093 584 | Ghana,1982,11400338 585 | Ghana,1987,14168101 586 | Ghana,1992,16278738 587 | Ghana,1997,18418288 588 | Ghana,2002,20550751 589 | Ghana,2007,22873338 590 | Greece,1952,7733250 591 | Greece,1957,8096218 592 | Greece,1962,8448233 593 | Greece,1967,8716441 594 | Greece,1972,8888628 595 | Greece,1977,9308479 596 | Greece,1982,9786480 597 | Greece,1987,9974490 598 | Greece,1992,10325429 599 | Greece,1997,10502372 600 | Greece,2002,10603863 601 | Greece,2007,10706290 602 | Guatemala,1952,3146381 603 | Guatemala,1957,3640876 604 | Guatemala,1962,4208858 605 | Guatemala,1967,4690773 606 | Guatemala,1972,5149581 607 | Guatemala,1977,5703430 608 | Guatemala,1982,6395630 609 | Guatemala,1987,7326406 610 | Guatemala,1992,8486949 611 | Guatemala,1997,9803875 612 | Guatemala,2002,11178650 613 | Guatemala,2007,12572928 614 | Guinea,1952,2664249 615 | Guinea,1957,2876726 616 | Guinea,1962,3140003 617 | Guinea,1967,3451418 618 | Guinea,1972,3811387 619 | Guinea,1977,4227026 620 | Guinea,1982,4710497 621 | Guinea,1987,5650262 622 | Guinea,1992,6990574 623 | Guinea,1997,8048834 624 | Guinea,2002,8807818 625 | Guinea,2007,9947814 626 | Guinea-Bissau,1952,580653 627 | Guinea-Bissau,1957,601095 628 | Guinea-Bissau,1962,627820 629 | Guinea-Bissau,1967,601287 630 | Guinea-Bissau,1972,625361 631 | Guinea-Bissau,1977,745228 632 | Guinea-Bissau,1982,825987 633 | Guinea-Bissau,1987,927524 634 | Guinea-Bissau,1992,1050938 635 | Guinea-Bissau,1997,1193708 636 | Guinea-Bissau,2002,1332459 637 | Guinea-Bissau,2007,1472041 638 | Haiti,1952,3201488 639 | Haiti,1957,3507701 640 | Haiti,1962,3880130 641 | Haiti,1967,4318137 642 | Haiti,1972,4698301 643 | Haiti,1977,4908554 644 | Haiti,1982,5198399 645 | Haiti,1987,5756203 646 | Haiti,1992,6326682 647 | Haiti,1997,6913545 648 | Haiti,2002,7607651 649 | Haiti,2007,8502814 650 | Honduras,1952,1517453 651 | Honduras,1957,1770390 652 | Honduras,1962,2090162 653 | Honduras,1967,2500689 654 | Honduras,1972,2965146 655 | Honduras,1977,3055235 656 | Honduras,1982,3669448 657 | Honduras,1987,4372203 658 | Honduras,1992,5077347 659 | Honduras,1997,5867957 660 | Honduras,2002,6677328 661 | Honduras,2007,7483763 662 | "Hong Kong, China",1952,2125900 663 | "Hong Kong, China",1957,2736300 664 | "Hong Kong, China",1962,3305200 665 | "Hong Kong, China",1967,3722800 666 | "Hong Kong, China",1972,4115700 667 | "Hong Kong, China",1977,4583700 668 | "Hong Kong, China",1982,5264500 669 | "Hong Kong, China",1987,5584510 670 | "Hong Kong, China",1992,5829696 671 | "Hong Kong, China",1997,6495918 672 | "Hong Kong, China",2002,6762476 673 | "Hong Kong, China",2007,6980412 674 | Hungary,1952,9504000 675 | Hungary,1957,9839000 676 | Hungary,1962,10063000 677 | Hungary,1967,10223422 678 | Hungary,1972,10394091 679 | Hungary,1977,10637171 680 | Hungary,1982,10705535 681 | Hungary,1987,10612740 682 | Hungary,1992,10348684 683 | Hungary,1997,10244684 684 | Hungary,2002,10083313 685 | Hungary,2007,9956108 686 | Iceland,1952,147962 687 | Iceland,1957,165110 688 | Iceland,1962,182053 689 | Iceland,1967,198676 690 | Iceland,1972,209275 691 | Iceland,1977,221823 692 | Iceland,1982,233997 693 | Iceland,1987,244676 694 | Iceland,1992,259012 695 | Iceland,1997,271192 696 | Iceland,2002,288030 697 | Iceland,2007,301931 698 | India,1952,372000000 699 | India,1957,409000000 700 | India,1962,454000000 701 | India,1967,506000000 702 | India,1972,567000000 703 | India,1977,634000000 704 | India,1982,708000000 705 | India,1987,788000000 706 | India,1992,872000000 707 | India,1997,959000000 708 | India,2002,1034172547 709 | India,2007,1110396331 710 | Indonesia,1952,82052000 711 | Indonesia,1957,90124000 712 | Indonesia,1962,99028000 713 | Indonesia,1967,109343000 714 | Indonesia,1972,121282000 715 | Indonesia,1977,136725000 716 | Indonesia,1982,153343000 717 | Indonesia,1987,169276000 718 | Indonesia,1992,184816000 719 | Indonesia,1997,199278000 720 | Indonesia,2002,211060000 721 | Indonesia,2007,223547000 722 | Iran,1952,17272000 723 | Iran,1957,19792000 724 | Iran,1962,22874000 725 | Iran,1967,26538000 726 | Iran,1972,30614000 727 | Iran,1977,35480679 728 | Iran,1982,43072751 729 | Iran,1987,51889696 730 | Iran,1992,60397973 731 | Iran,1997,63327987 732 | Iran,2002,66907826 733 | Iran,2007,69453570 734 | Iraq,1952,5441766 735 | Iraq,1957,6248643 736 | Iraq,1962,7240260 737 | Iraq,1967,8519282 738 | Iraq,1972,10061506 739 | Iraq,1977,11882916 740 | Iraq,1982,14173318 741 | Iraq,1987,16543189 742 | Iraq,1992,17861905 743 | Iraq,1997,20775703 744 | Iraq,2002,24001816 745 | Iraq,2007,27499638 746 | Ireland,1952,2952156 747 | Ireland,1957,2878220 748 | Ireland,1962,2830000 749 | Ireland,1967,2900100 750 | Ireland,1972,3024400 751 | Ireland,1977,3271900 752 | Ireland,1982,3480000 753 | Ireland,1987,3539900 754 | Ireland,1992,3557761 755 | Ireland,1997,3667233 756 | Ireland,2002,3879155 757 | Ireland,2007,4109086 758 | Israel,1952,1620914 759 | Israel,1957,1944401 760 | Israel,1962,2310904 761 | Israel,1967,2693585 762 | Israel,1972,3095893 763 | Israel,1977,3495918 764 | Israel,1982,3858421 765 | Israel,1987,4203148 766 | Israel,1992,4936550 767 | Israel,1997,5531387 768 | Israel,2002,6029529 769 | Israel,2007,6426679 770 | Italy,1952,47666000 771 | Italy,1957,49182000 772 | Italy,1962,50843200 773 | Italy,1967,52667100 774 | Italy,1972,54365564 775 | Italy,1977,56059245 776 | Italy,1982,56535636 777 | Italy,1987,56729703 778 | Italy,1992,56840847 779 | Italy,1997,57479469 780 | Italy,2002,57926999 781 | Italy,2007,58147733 782 | Jamaica,1952,1426095 783 | Jamaica,1957,1535090 784 | Jamaica,1962,1665128 785 | Jamaica,1967,1861096 786 | Jamaica,1972,1997616 787 | Jamaica,1977,2156814 788 | Jamaica,1982,2298309 789 | Jamaica,1987,2326606 790 | Jamaica,1992,2378618 791 | Jamaica,1997,2531311 792 | Jamaica,2002,2664659 793 | Jamaica,2007,2780132 794 | Japan,1952,86459025 795 | Japan,1957,91563009 796 | Japan,1962,95831757 797 | Japan,1967,100825279 798 | Japan,1972,107188273 799 | Japan,1977,113872473 800 | Japan,1982,118454974 801 | Japan,1987,122091325 802 | Japan,1992,124329269 803 | Japan,1997,125956499 804 | Japan,2002,127065841 805 | Japan,2007,127467972 806 | Jordan,1952,607914 807 | Jordan,1957,746559 808 | Jordan,1962,933559 809 | Jordan,1967,1255058 810 | Jordan,1972,1613551 811 | Jordan,1977,1937652 812 | Jordan,1982,2347031 813 | Jordan,1987,2820042 814 | Jordan,1992,3867409 815 | Jordan,1997,4526235 816 | Jordan,2002,5307470 817 | Jordan,2007,6053193 818 | Kenya,1952,6464046 819 | Kenya,1957,7454779 820 | Kenya,1962,8678557 821 | Kenya,1967,10191512 822 | Kenya,1972,12044785 823 | Kenya,1977,14500404 824 | Kenya,1982,17661452 825 | Kenya,1987,21198082 826 | Kenya,1992,25020539 827 | Kenya,1997,28263827 828 | Kenya,2002,31386842 829 | Kenya,2007,35610177 830 | "Korea, Dem. Rep.",1952,8865488 831 | "Korea, Dem. Rep.",1957,9411381 832 | "Korea, Dem. Rep.",1962,10917494 833 | "Korea, Dem. Rep.",1967,12617009 834 | "Korea, Dem. Rep.",1972,14781241 835 | "Korea, Dem. Rep.",1977,16325320 836 | "Korea, Dem. Rep.",1982,17647518 837 | "Korea, Dem. Rep.",1987,19067554 838 | "Korea, Dem. Rep.",1992,20711375 839 | "Korea, Dem. Rep.",1997,21585105 840 | "Korea, Dem. Rep.",2002,22215365 841 | "Korea, Dem. Rep.",2007,23301725 842 | "Korea, Rep.",1952,20947571 843 | "Korea, Rep.",1957,22611552 844 | "Korea, Rep.",1962,26420307 845 | "Korea, Rep.",1967,30131000 846 | "Korea, Rep.",1972,33505000 847 | "Korea, Rep.",1977,36436000 848 | "Korea, Rep.",1982,39326000 849 | "Korea, Rep.",1987,41622000 850 | "Korea, Rep.",1992,43805450 851 | "Korea, Rep.",1997,46173816 852 | "Korea, Rep.",2002,47969150 853 | "Korea, Rep.",2007,49044790 854 | Kuwait,1952,160000 855 | Kuwait,1957,212846 856 | Kuwait,1962,358266 857 | Kuwait,1967,575003 858 | Kuwait,1972,841934 859 | Kuwait,1977,1140357 860 | Kuwait,1982,1497494 861 | Kuwait,1987,1891487 862 | Kuwait,1992,1418095 863 | Kuwait,1997,1765345 864 | Kuwait,2002,2111561 865 | Kuwait,2007,2505559 866 | Lebanon,1952,1439529 867 | Lebanon,1957,1647412 868 | Lebanon,1962,1886848 869 | Lebanon,1967,2186894 870 | Lebanon,1972,2680018 871 | Lebanon,1977,3115787 872 | Lebanon,1982,3086876 873 | Lebanon,1987,3089353 874 | Lebanon,1992,3219994 875 | Lebanon,1997,3430388 876 | Lebanon,2002,3677780 877 | Lebanon,2007,3921278 878 | Lesotho,1952,748747 879 | Lesotho,1957,813338 880 | Lesotho,1962,893143 881 | Lesotho,1967,996380 882 | Lesotho,1972,1116779 883 | Lesotho,1977,1251524 884 | Lesotho,1982,1411807 885 | Lesotho,1987,1599200 886 | Lesotho,1992,1803195 887 | Lesotho,1997,1982823 888 | Lesotho,2002,2046772 889 | Lesotho,2007,2012649 890 | Liberia,1952,863308 891 | Liberia,1957,975950 892 | Liberia,1962,1112796 893 | Liberia,1967,1279406 894 | Liberia,1972,1482628 895 | Liberia,1977,1703617 896 | Liberia,1982,1956875 897 | Liberia,1987,2269414 898 | Liberia,1992,1912974 899 | Liberia,1997,2200725 900 | Liberia,2002,2814651 901 | Liberia,2007,3193942 902 | Libya,1952,1019729 903 | Libya,1957,1201578 904 | Libya,1962,1441863 905 | Libya,1967,1759224 906 | Libya,1972,2183877 907 | Libya,1977,2721783 908 | Libya,1982,3344074 909 | Libya,1987,3799845 910 | Libya,1992,4364501 911 | Libya,1997,4759670 912 | Libya,2002,5368585 913 | Libya,2007,6036914 914 | Madagascar,1952,4762912 915 | Madagascar,1957,5181679 916 | Madagascar,1962,5703324 917 | Madagascar,1967,6334556 918 | Madagascar,1972,7082430 919 | Madagascar,1977,8007166 920 | Madagascar,1982,9171477 921 | Madagascar,1987,10568642 922 | Madagascar,1992,12210395 923 | Madagascar,1997,14165114 924 | Madagascar,2002,16473477 925 | Madagascar,2007,19167654 926 | Malawi,1952,2917802 927 | Malawi,1957,3221238 928 | Malawi,1962,3628608 929 | Malawi,1967,4147252 930 | Malawi,1972,4730997 931 | Malawi,1977,5637246 932 | Malawi,1982,6502825 933 | Malawi,1987,7824747 934 | Malawi,1992,10014249 935 | Malawi,1997,10419991 936 | Malawi,2002,11824495 937 | Malawi,2007,13327079 938 | Malaysia,1952,6748378 939 | Malaysia,1957,7739235 940 | Malaysia,1962,8906385 941 | Malaysia,1967,10154878 942 | Malaysia,1972,11441462 943 | Malaysia,1977,12845381 944 | Malaysia,1982,14441916 945 | Malaysia,1987,16331785 946 | Malaysia,1992,18319502 947 | Malaysia,1997,20476091 948 | Malaysia,2002,22662365 949 | Malaysia,2007,24821286 950 | Mali,1952,3838168 951 | Mali,1957,4241884 952 | Mali,1962,4690372 953 | Mali,1967,5212416 954 | Mali,1972,5828158 955 | Mali,1977,6491649 956 | Mali,1982,6998256 957 | Mali,1987,7634008 958 | Mali,1992,8416215 959 | Mali,1997,9384984 960 | Mali,2002,10580176 961 | Mali,2007,12031795 962 | Mauritania,1952,1022556 963 | Mauritania,1957,1076852 964 | Mauritania,1962,1146757 965 | Mauritania,1967,1230542 966 | Mauritania,1972,1332786 967 | Mauritania,1977,1456688 968 | Mauritania,1982,1622136 969 | Mauritania,1987,1841240 970 | Mauritania,1992,2119465 971 | Mauritania,1997,2444741 972 | Mauritania,2002,2828858 973 | Mauritania,2007,3270065 974 | Mauritius,1952,516556 975 | Mauritius,1957,609816 976 | Mauritius,1962,701016 977 | Mauritius,1967,789309 978 | Mauritius,1972,851334 979 | Mauritius,1977,913025 980 | Mauritius,1982,992040 981 | Mauritius,1987,1042663 982 | Mauritius,1992,1096202 983 | Mauritius,1997,1149818 984 | Mauritius,2002,1200206 985 | Mauritius,2007,1250882 986 | Mexico,1952,30144317 987 | Mexico,1957,35015548 988 | Mexico,1962,41121485 989 | Mexico,1967,47995559 990 | Mexico,1972,55984294 991 | Mexico,1977,63759976 992 | Mexico,1982,71640904 993 | Mexico,1987,80122492 994 | Mexico,1992,88111030 995 | Mexico,1997,95895146 996 | Mexico,2002,102479927 997 | Mexico,2007,108700891 998 | Mongolia,1952,800663 999 | Mongolia,1957,882134 1000 | Mongolia,1962,1010280 1001 | Mongolia,1967,1149500 1002 | Mongolia,1972,1320500 1003 | Mongolia,1977,1528000 1004 | Mongolia,1982,1756032 1005 | Mongolia,1987,2015133 1006 | Mongolia,1992,2312802 1007 | Mongolia,1997,2494803 1008 | Mongolia,2002,2674234 1009 | Mongolia,2007,2874127 1010 | Montenegro,1952,413834 1011 | Montenegro,1957,442829 1012 | Montenegro,1962,474528 1013 | Montenegro,1967,501035 1014 | Montenegro,1972,527678 1015 | Montenegro,1977,560073 1016 | Montenegro,1982,562548 1017 | Montenegro,1987,569473 1018 | Montenegro,1992,621621 1019 | Montenegro,1997,692651 1020 | Montenegro,2002,720230 1021 | Montenegro,2007,684736 1022 | Morocco,1952,9939217 1023 | Morocco,1957,11406350 1024 | Morocco,1962,13056604 1025 | Morocco,1967,14770296 1026 | Morocco,1972,16660670 1027 | Morocco,1977,18396941 1028 | Morocco,1982,20198730 1029 | Morocco,1987,22987397 1030 | Morocco,1992,25798239 1031 | Morocco,1997,28529501 1032 | Morocco,2002,31167783 1033 | Morocco,2007,33757175 1034 | Mozambique,1952,6446316 1035 | Mozambique,1957,7038035 1036 | Mozambique,1962,7788944 1037 | Mozambique,1967,8680909 1038 | Mozambique,1972,9809596 1039 | Mozambique,1977,11127868 1040 | Mozambique,1982,12587223 1041 | Mozambique,1987,12891952 1042 | Mozambique,1992,13160731 1043 | Mozambique,1997,16603334 1044 | Mozambique,2002,18473780 1045 | Mozambique,2007,19951656 1046 | Myanmar,1952,20092996 1047 | Myanmar,1957,21731844 1048 | Myanmar,1962,23634436 1049 | Myanmar,1967,25870271 1050 | Myanmar,1972,28466390 1051 | Myanmar,1977,31528087 1052 | Myanmar,1982,34680442 1053 | Myanmar,1987,38028578 1054 | Myanmar,1992,40546538 1055 | Myanmar,1997,43247867 1056 | Myanmar,2002,45598081 1057 | Myanmar,2007,47761980 1058 | Namibia,1952,485831 1059 | Namibia,1957,548080 1060 | Namibia,1962,621392 1061 | Namibia,1967,706640 1062 | Namibia,1972,821782 1063 | Namibia,1977,977026 1064 | Namibia,1982,1099010 1065 | Namibia,1987,1278184 1066 | Namibia,1992,1554253 1067 | Namibia,1997,1774766 1068 | Namibia,2002,1972153 1069 | Namibia,2007,2055080 1070 | Nepal,1952,9182536 1071 | Nepal,1957,9682338 1072 | Nepal,1962,10332057 1073 | Nepal,1967,11261690 1074 | Nepal,1972,12412593 1075 | Nepal,1977,13933198 1076 | Nepal,1982,15796314 1077 | Nepal,1987,17917180 1078 | Nepal,1992,20326209 1079 | Nepal,1997,23001113 1080 | Nepal,2002,25873917 1081 | Nepal,2007,28901790 1082 | Netherlands,1952,10381988 1083 | Netherlands,1957,11026383 1084 | Netherlands,1962,11805689 1085 | Netherlands,1967,12596822 1086 | Netherlands,1972,13329874 1087 | Netherlands,1977,13852989 1088 | Netherlands,1982,14310401 1089 | Netherlands,1987,14665278 1090 | Netherlands,1992,15174244 1091 | Netherlands,1997,15604464 1092 | Netherlands,2002,16122830 1093 | Netherlands,2007,16570613 1094 | New Zealand,1952,1994794 1095 | New Zealand,1957,2229407 1096 | New Zealand,1962,2488550 1097 | New Zealand,1967,2728150 1098 | New Zealand,1972,2929100 1099 | New Zealand,1977,3164900 1100 | New Zealand,1982,3210650 1101 | New Zealand,1987,3317166 1102 | New Zealand,1992,3437674 1103 | New Zealand,1997,3676187 1104 | New Zealand,2002,3908037 1105 | New Zealand,2007,4115771 1106 | Nicaragua,1952,1165790 1107 | Nicaragua,1957,1358828 1108 | Nicaragua,1962,1590597 1109 | Nicaragua,1967,1865490 1110 | Nicaragua,1972,2182908 1111 | Nicaragua,1977,2554598 1112 | Nicaragua,1982,2979423 1113 | Nicaragua,1987,3344353 1114 | Nicaragua,1992,4017939 1115 | Nicaragua,1997,4609572 1116 | Nicaragua,2002,5146848 1117 | Nicaragua,2007,5675356 1118 | Niger,1952,3379468 1119 | Niger,1957,3692184 1120 | Niger,1962,4076008 1121 | Niger,1967,4534062 1122 | Niger,1972,5060262 1123 | Niger,1977,5682086 1124 | Niger,1982,6437188 1125 | Niger,1987,7332638 1126 | Niger,1992,8392818 1127 | Niger,1997,9666252 1128 | Niger,2002,11140655 1129 | Niger,2007,12894865 1130 | Nigeria,1952,33119096 1131 | Nigeria,1957,37173340 1132 | Nigeria,1962,41871351 1133 | Nigeria,1967,47287752 1134 | Nigeria,1972,53740085 1135 | Nigeria,1977,62209173 1136 | Nigeria,1982,73039376 1137 | Nigeria,1987,81551520 1138 | Nigeria,1992,93364244 1139 | Nigeria,1997,106207839 1140 | Nigeria,2002,119901274 1141 | Nigeria,2007,135031164 1142 | Norway,1952,3327728 1143 | Norway,1957,3491938 1144 | Norway,1962,3638919 1145 | Norway,1967,3786019 1146 | Norway,1972,3933004 1147 | Norway,1977,4043205 1148 | Norway,1982,4114787 1149 | Norway,1987,4186147 1150 | Norway,1992,4286357 1151 | Norway,1997,4405672 1152 | Norway,2002,4535591 1153 | Norway,2007,4627926 1154 | Oman,1952,507833 1155 | Oman,1957,561977 1156 | Oman,1962,628164 1157 | Oman,1967,714775 1158 | Oman,1972,829050 1159 | Oman,1977,1004533 1160 | Oman,1982,1301048 1161 | Oman,1987,1593882 1162 | Oman,1992,1915208 1163 | Oman,1997,2283635 1164 | Oman,2002,2713462 1165 | Oman,2007,3204897 1166 | Pakistan,1952,41346560 1167 | Pakistan,1957,46679944 1168 | Pakistan,1962,53100671 1169 | Pakistan,1967,60641899 1170 | Pakistan,1972,69325921 1171 | Pakistan,1977,78152686 1172 | Pakistan,1982,91462088 1173 | Pakistan,1987,105186881 1174 | Pakistan,1992,120065004 1175 | Pakistan,1997,135564834 1176 | Pakistan,2002,153403524 1177 | Pakistan,2007,169270617 1178 | Panama,1952,940080 1179 | Panama,1957,1063506 1180 | Panama,1962,1215725 1181 | Panama,1967,1405486 1182 | Panama,1972,1616384 1183 | Panama,1977,1839782 1184 | Panama,1982,2036305 1185 | Panama,1987,2253639 1186 | Panama,1992,2484997 1187 | Panama,1997,2734531 1188 | Panama,2002,2990875 1189 | Panama,2007,3242173 1190 | Paraguay,1952,1555876 1191 | Paraguay,1957,1770902 1192 | Paraguay,1962,2009813 1193 | Paraguay,1967,2287985 1194 | Paraguay,1972,2614104 1195 | Paraguay,1977,2984494 1196 | Paraguay,1982,3366439 1197 | Paraguay,1987,3886512 1198 | Paraguay,1992,4483945 1199 | Paraguay,1997,5154123 1200 | Paraguay,2002,5884491 1201 | Paraguay,2007,6667147 1202 | Peru,1952,8025700 1203 | Peru,1957,9146100 1204 | Peru,1962,10516500 1205 | Peru,1967,12132200 1206 | Peru,1972,13954700 1207 | Peru,1977,15990099 1208 | Peru,1982,18125129 1209 | Peru,1987,20195924 1210 | Peru,1992,22430449 1211 | Peru,1997,24748122 1212 | Peru,2002,26769436 1213 | Peru,2007,28674757 1214 | Philippines,1952,22438691 1215 | Philippines,1957,26072194 1216 | Philippines,1962,30325264 1217 | Philippines,1967,35356600 1218 | Philippines,1972,40850141 1219 | Philippines,1977,46850962 1220 | Philippines,1982,53456774 1221 | Philippines,1987,60017788 1222 | Philippines,1992,67185766 1223 | Philippines,1997,75012988 1224 | Philippines,2002,82995088 1225 | Philippines,2007,91077287 1226 | Poland,1952,25730551 1227 | Poland,1957,28235346 1228 | Poland,1962,30329617 1229 | Poland,1967,31785378 1230 | Poland,1972,33039545 1231 | Poland,1977,34621254 1232 | Poland,1982,36227381 1233 | Poland,1987,37740710 1234 | Poland,1992,38370697 1235 | Poland,1997,38654957 1236 | Poland,2002,38625976 1237 | Poland,2007,38518241 1238 | Portugal,1952,8526050 1239 | Portugal,1957,8817650 1240 | Portugal,1962,9019800 1241 | Portugal,1967,9103000 1242 | Portugal,1972,8970450 1243 | Portugal,1977,9662600 1244 | Portugal,1982,9859650 1245 | Portugal,1987,9915289 1246 | Portugal,1992,9927680 1247 | Portugal,1997,10156415 1248 | Portugal,2002,10433867 1249 | Portugal,2007,10642836 1250 | Puerto Rico,1952,2227000 1251 | Puerto Rico,1957,2260000 1252 | Puerto Rico,1962,2448046 1253 | Puerto Rico,1967,2648961 1254 | Puerto Rico,1972,2847132 1255 | Puerto Rico,1977,3080828 1256 | Puerto Rico,1982,3279001 1257 | Puerto Rico,1987,3444468 1258 | Puerto Rico,1992,3585176 1259 | Puerto Rico,1997,3759430 1260 | Puerto Rico,2002,3859606 1261 | Puerto Rico,2007,3942491 1262 | Reunion,1952,257700 1263 | Reunion,1957,308700 1264 | Reunion,1962,358900 1265 | Reunion,1967,414024 1266 | Reunion,1972,461633 1267 | Reunion,1977,492095 1268 | Reunion,1982,517810 1269 | Reunion,1987,562035 1270 | Reunion,1992,622191 1271 | Reunion,1997,684810 1272 | Reunion,2002,743981 1273 | Reunion,2007,798094 1274 | Romania,1952,16630000 1275 | Romania,1957,17829327 1276 | Romania,1962,18680721 1277 | Romania,1967,19284814 1278 | Romania,1972,20662648 1279 | Romania,1977,21658597 1280 | Romania,1982,22356726 1281 | Romania,1987,22686371 1282 | Romania,1992,22797027 1283 | Romania,1997,22562458 1284 | Romania,2002,22404337 1285 | Romania,2007,22276056 1286 | Rwanda,1952,2534927 1287 | Rwanda,1957,2822082 1288 | Rwanda,1962,3051242 1289 | Rwanda,1967,3451079 1290 | Rwanda,1972,3992121 1291 | Rwanda,1977,4657072 1292 | Rwanda,1982,5507565 1293 | Rwanda,1987,6349365 1294 | Rwanda,1992,7290203 1295 | Rwanda,1997,7212583 1296 | Rwanda,2002,7852401 1297 | Rwanda,2007,8860588 1298 | Sao Tome and Principe,1952,60011 1299 | Sao Tome and Principe,1957,61325 1300 | Sao Tome and Principe,1962,65345 1301 | Sao Tome and Principe,1967,70787 1302 | Sao Tome and Principe,1972,76595 1303 | Sao Tome and Principe,1977,86796 1304 | Sao Tome and Principe,1982,98593 1305 | Sao Tome and Principe,1987,110812 1306 | Sao Tome and Principe,1992,125911 1307 | Sao Tome and Principe,1997,145608 1308 | Sao Tome and Principe,2002,170372 1309 | Sao Tome and Principe,2007,199579 1310 | Saudi Arabia,1952,4005677 1311 | Saudi Arabia,1957,4419650 1312 | Saudi Arabia,1962,4943029 1313 | Saudi Arabia,1967,5618198 1314 | Saudi Arabia,1972,6472756 1315 | Saudi Arabia,1977,8128505 1316 | Saudi Arabia,1982,11254672 1317 | Saudi Arabia,1987,14619745 1318 | Saudi Arabia,1992,16945857 1319 | Saudi Arabia,1997,21229759 1320 | Saudi Arabia,2002,24501530 1321 | Saudi Arabia,2007,27601038 1322 | Senegal,1952,2755589 1323 | Senegal,1957,3054547 1324 | Senegal,1962,3430243 1325 | Senegal,1967,3965841 1326 | Senegal,1972,4588696 1327 | Senegal,1977,5260855 1328 | Senegal,1982,6147783 1329 | Senegal,1987,7171347 1330 | Senegal,1992,8307920 1331 | Senegal,1997,9535314 1332 | Senegal,2002,10870037 1333 | Senegal,2007,12267493 1334 | Serbia,1952,6860147 1335 | Serbia,1957,7271135 1336 | Serbia,1962,7616060 1337 | Serbia,1967,7971222 1338 | Serbia,1972,8313288 1339 | Serbia,1977,8686367 1340 | Serbia,1982,9032824 1341 | Serbia,1987,9230783 1342 | Serbia,1992,9826397 1343 | Serbia,1997,10336594 1344 | Serbia,2002,10111559 1345 | Serbia,2007,10150265 1346 | Sierra Leone,1952,2143249 1347 | Sierra Leone,1957,2295678 1348 | Sierra Leone,1962,2467895 1349 | Sierra Leone,1967,2662190 1350 | Sierra Leone,1972,2879013 1351 | Sierra Leone,1977,3140897 1352 | Sierra Leone,1982,3464522 1353 | Sierra Leone,1987,3868905 1354 | Sierra Leone,1992,4260884 1355 | Sierra Leone,1997,4578212 1356 | Sierra Leone,2002,5359092 1357 | Sierra Leone,2007,6144562 1358 | Singapore,1952,1127000 1359 | Singapore,1957,1445929 1360 | Singapore,1962,1750200 1361 | Singapore,1967,1977600 1362 | Singapore,1972,2152400 1363 | Singapore,1977,2325300 1364 | Singapore,1982,2651869 1365 | Singapore,1987,2794552 1366 | Singapore,1992,3235865 1367 | Singapore,1997,3802309 1368 | Singapore,2002,4197776 1369 | Singapore,2007,4553009 1370 | Slovak Republic,1952,3558137 1371 | Slovak Republic,1957,3844277 1372 | Slovak Republic,1962,4237384 1373 | Slovak Republic,1967,4442238 1374 | Slovak Republic,1972,4593433 1375 | Slovak Republic,1977,4827803 1376 | Slovak Republic,1982,5048043 1377 | Slovak Republic,1987,5199318 1378 | Slovak Republic,1992,5302888 1379 | Slovak Republic,1997,5383010 1380 | Slovak Republic,2002,5410052 1381 | Slovak Republic,2007,5447502 1382 | Slovenia,1952,1489518 1383 | Slovenia,1957,1533070 1384 | Slovenia,1962,1582962 1385 | Slovenia,1967,1646912 1386 | Slovenia,1972,1694510 1387 | Slovenia,1977,1746919 1388 | Slovenia,1982,1861252 1389 | Slovenia,1987,1945870 1390 | Slovenia,1992,1999210 1391 | Slovenia,1997,2011612 1392 | Slovenia,2002,2011497 1393 | Slovenia,2007,2009245 1394 | Somalia,1952,2526994 1395 | Somalia,1957,2780415 1396 | Somalia,1962,3080153 1397 | Somalia,1967,3428839 1398 | Somalia,1972,3840161 1399 | Somalia,1977,4353666 1400 | Somalia,1982,5828892 1401 | Somalia,1987,6921858 1402 | Somalia,1992,6099799 1403 | Somalia,1997,6633514 1404 | Somalia,2002,7753310 1405 | Somalia,2007,9118773 1406 | South Africa,1952,14264935 1407 | South Africa,1957,16151549 1408 | South Africa,1962,18356657 1409 | South Africa,1967,20997321 1410 | South Africa,1972,23935810 1411 | South Africa,1977,27129932 1412 | South Africa,1982,31140029 1413 | South Africa,1987,35933379 1414 | South Africa,1992,39964159 1415 | South Africa,1997,42835005 1416 | South Africa,2002,44433622 1417 | South Africa,2007,43997828 1418 | Spain,1952,28549870 1419 | Spain,1957,29841614 1420 | Spain,1962,31158061 1421 | Spain,1967,32850275 1422 | Spain,1972,34513161 1423 | Spain,1977,36439000 1424 | Spain,1982,37983310 1425 | Spain,1987,38880702 1426 | Spain,1992,39549438 1427 | Spain,1997,39855442 1428 | Spain,2002,40152517 1429 | Spain,2007,40448191 1430 | Sri Lanka,1952,7982342 1431 | Sri Lanka,1957,9128546 1432 | Sri Lanka,1962,10421936 1433 | Sri Lanka,1967,11737396 1434 | Sri Lanka,1972,13016733 1435 | Sri Lanka,1977,14116836 1436 | Sri Lanka,1982,15410151 1437 | Sri Lanka,1987,16495304 1438 | Sri Lanka,1992,17587060 1439 | Sri Lanka,1997,18698655 1440 | Sri Lanka,2002,19576783 1441 | Sri Lanka,2007,20378239 1442 | Sudan,1952,8504667 1443 | Sudan,1957,9753392 1444 | Sudan,1962,11183227 1445 | Sudan,1967,12716129 1446 | Sudan,1972,14597019 1447 | Sudan,1977,17104986 1448 | Sudan,1982,20367053 1449 | Sudan,1987,24725960 1450 | Sudan,1992,28227588 1451 | Sudan,1997,32160729 1452 | Sudan,2002,37090298 1453 | Sudan,2007,42292929 1454 | Swaziland,1952,290243 1455 | Swaziland,1957,326741 1456 | Swaziland,1962,370006 1457 | Swaziland,1967,420690 1458 | Swaziland,1972,480105 1459 | Swaziland,1977,551425 1460 | Swaziland,1982,649901 1461 | Swaziland,1987,779348 1462 | Swaziland,1992,962344 1463 | Swaziland,1997,1054486 1464 | Swaziland,2002,1130269 1465 | Swaziland,2007,1133066 1466 | Sweden,1952,7124673 1467 | Sweden,1957,7363802 1468 | Sweden,1962,7561588 1469 | Sweden,1967,7867931 1470 | Sweden,1972,8122293 1471 | Sweden,1977,8251648 1472 | Sweden,1982,8325260 1473 | Sweden,1987,8421403 1474 | Sweden,1992,8718867 1475 | Sweden,1997,8897619 1476 | Sweden,2002,8954175 1477 | Sweden,2007,9031088 1478 | Switzerland,1952,4815000 1479 | Switzerland,1957,5126000 1480 | Switzerland,1962,5666000 1481 | Switzerland,1967,6063000 1482 | Switzerland,1972,6401400 1483 | Switzerland,1977,6316424 1484 | Switzerland,1982,6468126 1485 | Switzerland,1987,6649942 1486 | Switzerland,1992,6995447 1487 | Switzerland,1997,7193761 1488 | Switzerland,2002,7361757 1489 | Switzerland,2007,7554661 1490 | Syria,1952,3661549 1491 | Syria,1957,4149908 1492 | Syria,1962,4834621 1493 | Syria,1967,5680812 1494 | Syria,1972,6701172 1495 | Syria,1977,7932503 1496 | Syria,1982,9410494 1497 | Syria,1987,11242847 1498 | Syria,1992,13219062 1499 | Syria,1997,15081016 1500 | Syria,2002,17155814 1501 | Syria,2007,19314747 1502 | Taiwan,1952,8550362 1503 | Taiwan,1957,10164215 1504 | Taiwan,1962,11918938 1505 | Taiwan,1967,13648692 1506 | Taiwan,1972,15226039 1507 | Taiwan,1977,16785196 1508 | Taiwan,1982,18501390 1509 | Taiwan,1987,19757799 1510 | Taiwan,1992,20686918 1511 | Taiwan,1997,21628605 1512 | Taiwan,2002,22454239 1513 | Taiwan,2007,23174294 1514 | Tanzania,1952,8322925 1515 | Tanzania,1957,9452826 1516 | Tanzania,1962,10863958 1517 | Tanzania,1967,12607312 1518 | Tanzania,1972,14706593 1519 | Tanzania,1977,17129565 1520 | Tanzania,1982,19844382 1521 | Tanzania,1987,23040630 1522 | Tanzania,1992,26605473 1523 | Tanzania,1997,30686889 1524 | Tanzania,2002,34593779 1525 | Tanzania,2007,38139640 1526 | Thailand,1952,21289402 1527 | Thailand,1957,25041917 1528 | Thailand,1962,29263397 1529 | Thailand,1967,34024249 1530 | Thailand,1972,39276153 1531 | Thailand,1977,44148285 1532 | Thailand,1982,48827160 1533 | Thailand,1987,52910342 1534 | Thailand,1992,56667095 1535 | Thailand,1997,60216677 1536 | Thailand,2002,62806748 1537 | Thailand,2007,65068149 1538 | Togo,1952,1219113 1539 | Togo,1957,1357445 1540 | Togo,1962,1528098 1541 | Togo,1967,1735550 1542 | Togo,1972,2056351 1543 | Togo,1977,2308582 1544 | Togo,1982,2644765 1545 | Togo,1987,3154264 1546 | Togo,1992,3747553 1547 | Togo,1997,4320890 1548 | Togo,2002,4977378 1549 | Togo,2007,5701579 1550 | Trinidad and Tobago,1952,662850 1551 | Trinidad and Tobago,1957,764900 1552 | Trinidad and Tobago,1962,887498 1553 | Trinidad and Tobago,1967,960155 1554 | Trinidad and Tobago,1972,975199 1555 | Trinidad and Tobago,1977,1039009 1556 | Trinidad and Tobago,1982,1116479 1557 | Trinidad and Tobago,1987,1191336 1558 | Trinidad and Tobago,1992,1183669 1559 | Trinidad and Tobago,1997,1138101 1560 | Trinidad and Tobago,2002,1101832 1561 | Trinidad and Tobago,2007,1056608 1562 | Tunisia,1952,3647735 1563 | Tunisia,1957,3950849 1564 | Tunisia,1962,4286552 1565 | Tunisia,1967,4786986 1566 | Tunisia,1972,5303507 1567 | Tunisia,1977,6005061 1568 | Tunisia,1982,6734098 1569 | Tunisia,1987,7724976 1570 | Tunisia,1992,8523077 1571 | Tunisia,1997,9231669 1572 | Tunisia,2002,9770575 1573 | Tunisia,2007,10276158 1574 | Turkey,1952,22235677 1575 | Turkey,1957,25670939 1576 | Turkey,1962,29788695 1577 | Turkey,1967,33411317 1578 | Turkey,1972,37492953 1579 | Turkey,1977,42404033 1580 | Turkey,1982,47328791 1581 | Turkey,1987,52881328 1582 | Turkey,1992,58179144 1583 | Turkey,1997,63047647 1584 | Turkey,2002,67308928 1585 | Turkey,2007,71158647 1586 | Uganda,1952,5824797 1587 | Uganda,1957,6675501 1588 | Uganda,1962,7688797 1589 | Uganda,1967,8900294 1590 | Uganda,1972,10190285 1591 | Uganda,1977,11457758 1592 | Uganda,1982,12939400 1593 | Uganda,1987,15283050 1594 | Uganda,1992,18252190 1595 | Uganda,1997,21210254 1596 | Uganda,2002,24739869 1597 | Uganda,2007,29170398 1598 | United Kingdom,1952,50430000 1599 | United Kingdom,1957,51430000 1600 | United Kingdom,1962,53292000 1601 | United Kingdom,1967,54959000 1602 | United Kingdom,1972,56079000 1603 | United Kingdom,1977,56179000 1604 | United Kingdom,1982,56339704 1605 | United Kingdom,1987,56981620 1606 | United Kingdom,1992,57866349 1607 | United Kingdom,1997,58808266 1608 | United Kingdom,2002,59912431 1609 | United Kingdom,2007,60776238 1610 | United States,1952,157553000 1611 | United States,1957,171984000 1612 | United States,1962,186538000 1613 | United States,1967,198712000 1614 | United States,1972,209896000 1615 | United States,1977,220239000 1616 | United States,1982,232187835 1617 | United States,1987,242803533 1618 | United States,1992,256894189 1619 | United States,1997,272911760 1620 | United States,2002,287675526 1621 | United States,2007,301139947 1622 | Uruguay,1952,2252965 1623 | Uruguay,1957,2424959 1624 | Uruguay,1962,2598466 1625 | Uruguay,1967,2748579 1626 | Uruguay,1972,2829526 1627 | Uruguay,1977,2873520 1628 | Uruguay,1982,2953997 1629 | Uruguay,1987,3045153 1630 | Uruguay,1992,3149262 1631 | Uruguay,1997,3262838 1632 | Uruguay,2002,3363085 1633 | Uruguay,2007,3447496 1634 | Venezuela,1952,5439568 1635 | Venezuela,1957,6702668 1636 | Venezuela,1962,8143375 1637 | Venezuela,1967,9709552 1638 | Venezuela,1972,11515649 1639 | Venezuela,1977,13503563 1640 | Venezuela,1982,15620766 1641 | Venezuela,1987,17910182 1642 | Venezuela,1992,20265563 1643 | Venezuela,1997,22374398 1644 | Venezuela,2002,24287670 1645 | Venezuela,2007,26084662 1646 | Vietnam,1952,26246839 1647 | Vietnam,1957,28998543 1648 | Vietnam,1962,33796140 1649 | Vietnam,1967,39463910 1650 | Vietnam,1972,44655014 1651 | Vietnam,1977,50533506 1652 | Vietnam,1982,56142181 1653 | Vietnam,1987,62826491 1654 | Vietnam,1992,69940728 1655 | Vietnam,1997,76048996 1656 | Vietnam,2002,80908147 1657 | Vietnam,2007,85262356 1658 | West Bank and Gaza,1952,1030585 1659 | West Bank and Gaza,1957,1070439 1660 | West Bank and Gaza,1962,1133134 1661 | West Bank and Gaza,1967,1142636 1662 | West Bank and Gaza,1972,1089572 1663 | West Bank and Gaza,1977,1261091 1664 | West Bank and Gaza,1982,1425876 1665 | West Bank and Gaza,1987,1691210 1666 | West Bank and Gaza,1992,2104779 1667 | West Bank and Gaza,1997,2826046 1668 | West Bank and Gaza,2002,3389578 1669 | West Bank and Gaza,2007,4018332 1670 | "Yemen, Rep.",1952,4963829 1671 | "Yemen, Rep.",1957,5498090 1672 | "Yemen, Rep.",1962,6120081 1673 | "Yemen, Rep.",1967,6740785 1674 | "Yemen, Rep.",1972,7407075 1675 | "Yemen, Rep.",1977,8403990 1676 | "Yemen, Rep.",1982,9657618 1677 | "Yemen, Rep.",1987,11219340 1678 | "Yemen, Rep.",1992,13367997 1679 | "Yemen, Rep.",1997,15826497 1680 | "Yemen, Rep.",2002,18701257 1681 | "Yemen, Rep.",2007,22211743 1682 | Zambia,1952,2672000 1683 | Zambia,1957,3016000 1684 | Zambia,1962,3421000 1685 | Zambia,1967,3900000 1686 | Zambia,1972,4506497 1687 | Zambia,1977,5216550 1688 | Zambia,1982,6100407 1689 | Zambia,1987,7272406 1690 | Zambia,1992,8381163 1691 | Zambia,1997,9417789 1692 | Zambia,2002,10595811 1693 | Zambia,2007,11746035 1694 | Zimbabwe,1952,3080907 1695 | Zimbabwe,1957,3646340 1696 | Zimbabwe,1962,4277736 1697 | Zimbabwe,1967,4995432 1698 | Zimbabwe,1972,5861135 1699 | Zimbabwe,1977,6642107 1700 | Zimbabwe,1982,7636524 1701 | Zimbabwe,1987,9216418 1702 | Zimbabwe,1992,10704340 1703 | Zimbabwe,1997,11404948 1704 | Zimbabwe,2002,11926563 1705 | Zimbabwe,2007,12311143 -------------------------------------------------------------------------------- /sample_data.csv: -------------------------------------------------------------------------------- 1 | column_a,column_b,column_c 2 | 1,1,10 3 | 2,4,8 4 | 3,9,6 5 | 4,16,4 6 | 5,25,2 -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.alanbinu.kafka 7 | spring-boot-kafka-producer-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-kafka-producer-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.13.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.kafka 34 | spring-kafka 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/src/main/java/com/alanbinu/kafka/springbootkafkaproducerexample/SpringBootKafkaProducerExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.kafka.springbootkafkaproducerexample; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootKafkaProducerExampleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootKafkaProducerExampleApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/src/main/java/com/alanbinu/kafka/springbootkafkaproducerexample/config/KakfaConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.kafka.springbootkafkaproducerexample.config; 2 | 3 | import com.alanbinu.kafka.springbootkafkaproducerexample.model.User; 4 | import org.apache.kafka.clients.producer.ProducerConfig; 5 | import org.apache.kafka.common.serialization.StringSerializer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 9 | import org.springframework.kafka.core.KafkaTemplate; 10 | import org.springframework.kafka.core.ProducerFactory; 11 | import org.springframework.kafka.support.serializer.JsonSerializer; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | @Configuration 17 | public class KakfaConfiguration { 18 | 19 | @Bean 20 | public ProducerFactory producerFactory() { 21 | Map config = new HashMap<>(); 22 | 23 | config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092"); 24 | config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 25 | config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); 26 | 27 | return new DefaultKafkaProducerFactory<>(config); 28 | } 29 | 30 | 31 | @Bean 32 | public KafkaTemplate kafkaTemplate() { 33 | return new KafkaTemplate<>(producerFactory()); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/src/main/java/com/alanbinu/kafka/springbootkafkaproducerexample/model/User.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.kafka.springbootkafkaproducerexample.model; 2 | 3 | public class User { 4 | 5 | private String name; 6 | private String dept; 7 | private Long salary; 8 | 9 | public User(String name, String dept, Long salary) { 10 | this.name = name; 11 | this.dept = dept; 12 | this.salary = salary; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | public String getDept() { 24 | return dept; 25 | } 26 | 27 | public void setDept(String dept) { 28 | this.dept = dept; 29 | } 30 | 31 | public Long getSalary() { 32 | return salary; 33 | } 34 | 35 | public void setSalary(Long salary) { 36 | this.salary = salary; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/src/main/java/com/alanbinu/kafka/springbootkafkaproducerexample/resource/UserResource.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.kafka.springbootkafkaproducerexample.resource; 2 | 3 | import com.alanbinu.kafka.springbootkafkaproducerexample.model.User; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.kafka.core.KafkaTemplate; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | @RequestMapping("kafka") 13 | public class UserResource { 14 | 15 | @Autowired 16 | private KafkaTemplate kafkaTemplate; 17 | 18 | private static final String TOPIC = "Kafka_Example"; 19 | 20 | @GetMapping("/publish/{name}") 21 | public String post(@PathVariable("name") final String name) { 22 | 23 | kafkaTemplate.send(TOPIC, new User(name, "Technology", 12000L)); 24 | 25 | return "Published successfully"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /spring-boot-kafka-producer-example/src/test/java/com/alanbinu/kafka/springbootkafkaproducerexample/SpringBootKafkaProducerExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.alanbinu.kafka.springbootkafkaproducerexample; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringBootKafkaProducerExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.springboot 6 | springboot-kafka 7 | 0.0.1-SNAPSHOT 8 | 9 | springboot-kafka.consumer 10 | 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-web 15 | 16 | 17 | org.springframework.kafka 18 | spring-kafka 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-test 23 | test 24 | 25 | 26 | com.springboot 27 | springboot-kafka.model 28 | 0.0.1-SNAPSHOT 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/consumer/src/main/java/com/springboot/KafkaConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KafkaConsumerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KafkaConsumerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/consumer/src/main/java/com/springboot/config/KafkaConsumerConfig.java: -------------------------------------------------------------------------------- 1 | package com.springboot.config; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.kafka.clients.consumer.ConsumerConfig; 7 | import org.apache.kafka.common.serialization.StringDeserializer; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.kafka.annotation.EnableKafka; 12 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; 13 | import org.springframework.kafka.config.KafkaListenerContainerFactory; 14 | import org.springframework.kafka.core.ConsumerFactory; 15 | import org.springframework.kafka.core.DefaultKafkaConsumerFactory; 16 | import org.springframework.kafka.listener.ConcurrentMessageListenerContainer; 17 | import org.springframework.kafka.support.serializer.JsonDeserializer; 18 | 19 | import com.springboot.model.Student; 20 | 21 | @Configuration 22 | @EnableKafka 23 | public class KafkaConsumerConfig { 24 | 25 | @Value("${kafka.boot.server}") 26 | private String kafkaServer; 27 | 28 | @Value("${kafka.consumer.group.id}") 29 | private String kafkaGroupId; 30 | 31 | @Bean 32 | public ConsumerFactory consumerConfig() { 33 | // TODO Auto-generated method stub 34 | Map config = new HashMap<>(); 35 | config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaServer); 36 | config.put(ConsumerConfig.GROUP_ID_CONFIG, kafkaGroupId); 37 | config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); 38 | config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class); 39 | return new DefaultKafkaConsumerFactory<>(config, null, new JsonDeserializer(Student.class)); 40 | } 41 | 42 | @Bean 43 | public KafkaListenerContainerFactory> kafkaListenerContainerFactory() { 44 | ConcurrentKafkaListenerContainerFactory listener = new ConcurrentKafkaListenerContainerFactory<>(); 45 | listener.setConsumerFactory(consumerConfig()); 46 | return listener; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/consumer/src/main/java/com/springboot/service/KafkaReciever.java: -------------------------------------------------------------------------------- 1 | package com.springboot.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.kafka.annotation.KafkaListener; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.springboot.model.Student; 9 | 10 | @Service 11 | public class KafkaReciever { 12 | 13 | private static final Logger LOGGER = LoggerFactory.getLogger(KafkaReciever.class); 14 | 15 | @KafkaListener(topics = "${kafka.topic.name}", group = "${kafka.consumer.group.id}") 16 | public void recieveData(Student student) { 17 | LOGGER.info("Data - " + student.toString() + " recieved"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | kafka: 2 | boot: 3 | server: localhost:9092 4 | topic: 5 | name: myTopic-kafkasender 6 | consumer: 7 | group: 8 | id: myTopic-group-id 9 | server: 10 | port: 8082 -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/model/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.springboot 7 | springboot-kafka 8 | 0.0.1-SNAPSHOT 9 | 10 | springboot-kafka.model 11 | jar 12 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/model/src/main/java/com/springboot/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.springboot.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Address implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String apartment; 10 | private String street; 11 | private String state; 12 | private String city; 13 | private String postCode; 14 | 15 | public String getApartment() { 16 | return apartment; 17 | } 18 | 19 | public void setApartment(String apartment) { 20 | this.apartment = apartment; 21 | } 22 | 23 | public String getStreet() { 24 | return street; 25 | } 26 | 27 | public void setStreet(String street) { 28 | this.street = street; 29 | } 30 | 31 | public String getState() { 32 | return state; 33 | } 34 | 35 | public void setState(String state) { 36 | this.state = state; 37 | } 38 | 39 | public String getCity() { 40 | return city; 41 | } 42 | 43 | public void setCity(String city) { 44 | this.city = city; 45 | } 46 | 47 | public String getPostCode() { 48 | return postCode; 49 | } 50 | 51 | public void setPostCode(String postCode) { 52 | this.postCode = postCode; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/model/src/main/java/com/springboot/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.springboot.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Student implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String studentId; 10 | private String firstName; 11 | private String lastName; 12 | private String age; 13 | private Address address; 14 | 15 | public String getStudentId() { 16 | return studentId; 17 | } 18 | 19 | public void setStudentId(String studentId) { 20 | this.studentId = studentId; 21 | } 22 | 23 | public String getFirstName() { 24 | return firstName; 25 | } 26 | 27 | public void setFirstName(String firstName) { 28 | this.firstName = firstName; 29 | } 30 | 31 | public String getLastName() { 32 | return lastName; 33 | } 34 | 35 | public void setLastName(String lastName) { 36 | this.lastName = lastName; 37 | } 38 | 39 | public String getAge() { 40 | return age; 41 | } 42 | 43 | public void setAge(String age) { 44 | this.age = age; 45 | } 46 | 47 | public Address getAddress() { 48 | return address; 49 | } 50 | 51 | public void setAddress(Address address) { 52 | this.address = address; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/producer/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.springboot 6 | springboot-kafka 7 | 0.0.1-SNAPSHOT 8 | 9 | springboot-kafka.producer 10 | 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-web 15 | 16 | 17 | org.springframework.kafka 18 | spring-kafka 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-test 23 | test 24 | 25 | 26 | com.springboot 27 | springboot-kafka.model 28 | 0.0.1-SNAPSHOT 29 | 30 | 31 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/producer/src/main/java/com/springboot/KafkaProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KafkaProducerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KafkaProducerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/producer/src/main/java/com/springboot/config/KafkaProducerConfig.java: -------------------------------------------------------------------------------- 1 | package com.springboot.config; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import org.apache.kafka.clients.producer.ProducerConfig; 6 | import org.apache.kafka.common.serialization.StringSerializer; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; 11 | import org.springframework.kafka.core.KafkaTemplate; 12 | import org.springframework.kafka.core.ProducerFactory; 13 | import org.springframework.kafka.support.serializer.JsonSerializer; 14 | 15 | @Configuration 16 | public class KafkaProducerConfig { 17 | 18 | @Value("${kafka.boot.server}") 19 | private String kafkaServer; 20 | 21 | @Bean 22 | public KafkaTemplate kafkaTemplate() { 23 | return new KafkaTemplate<>(producerConfig()); 24 | } 25 | 26 | @Bean 27 | public ProducerFactory producerConfig() { 28 | // TODO Auto-generated method stub 29 | Map config = new HashMap<>(); 30 | config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaServer); 31 | config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 32 | config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); 33 | //Uncomment the below if you want to send String instead of an Object through Kafka 34 | //config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); 35 | return new DefaultKafkaProducerFactory<>(config); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/producer/src/main/java/com/springboot/ctrl/KafkaProducerController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.ctrl; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.springboot.model.Student; 12 | import com.springboot.service.KafkaSender; 13 | 14 | @RestController 15 | @RequestMapping("/kafkaProducer") 16 | public class KafkaProducerController { 17 | 18 | @Autowired 19 | private KafkaSender sender; 20 | 21 | @PostMapping 22 | public ResponseEntity sendData(@RequestBody Student student){ 23 | sender.sendData(student); 24 | return new ResponseEntity<>("Data sent to Kafka", HttpStatus.OK); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/producer/src/main/java/com/springboot/service/KafkaSender.java: -------------------------------------------------------------------------------- 1 | package com.springboot.service; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.kafka.core.KafkaTemplate; 11 | import org.springframework.kafka.support.KafkaHeaders; 12 | import org.springframework.messaging.support.GenericMessage; 13 | import org.springframework.stereotype.Service; 14 | 15 | import com.springboot.model.Student; 16 | 17 | @Service 18 | public class KafkaSender { 19 | 20 | private static final Logger LOGGER = LoggerFactory.getLogger(KafkaSender.class); 21 | 22 | @Autowired 23 | private KafkaTemplate kafkaTemplate; 24 | 25 | @Value("${kafka.topic.name}") 26 | private String topicName; 27 | 28 | public void sendData(Student student) { 29 | // TODO Auto-generated method stub 30 | Map headers = new HashMap<>(); 31 | headers.put(KafkaHeaders.TOPIC, topicName); 32 | kafkaTemplate.send(new GenericMessage(student, headers)); 33 | // use the below to send String values through kafka 34 | // kafkaTemplate.send(topicName, "some string value") 35 | LOGGER.info("Data - " + student.toString() + " sent to Kafka Topic - " + topicName); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-kafka-advanced-project-setup/producer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | kafka: 2 | boot: 3 | server: localhost:9092 4 | topic: 5 | name: myTopic-kafkasender 6 | server: 7 | port: 8081 -------------------------------------------------------------------------------- /springboot-kafka-basic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.1.RELEASE 9 | 10 | 11 | com.example.kafka 12 | springboot-kafka 13 | 0.0.1-SNAPSHOT 14 | springboot-kafka 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.kafka 28 | spring-kafka 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | org.junit.vintage 38 | junit-vintage-engine 39 | 40 | 41 | 42 | 43 | org.springframework.kafka 44 | spring-kafka-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/main/java/com/example/kafka/springbootkafka/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.example.kafka.springbootkafka; 2 | 3 | import org.springframework.kafka.annotation.KafkaListener; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class Consumer { 8 | @KafkaListener(topics = "test_topic",groupId = "group_id") 9 | public void consumeMessage(String message){ 10 | 11 | System.out.println(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/main/java/com/example/kafka/springbootkafka/Producer.java: -------------------------------------------------------------------------------- 1 | package com.example.kafka.springbootkafka; 2 | 3 | import org.apache.kafka.clients.admin.NewTopic; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.kafka.core.KafkaTemplate; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class Producer { 11 | private static final String TOPIC = "test_topic"; 12 | @Autowired 13 | private KafkaTemplate kafkaTemplate; 14 | 15 | public void sendMessage(String message){ 16 | 17 | this.kafkaTemplate.send(TOPIC,message); 18 | } 19 | 20 | @Bean 21 | public NewTopic createTopic(){ 22 | 23 | return new NewTopic(TOPIC,3,(short) 1); 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/main/java/com/example/kafka/springbootkafka/SpringbootKafkaApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.kafka.springbootkafka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootKafkaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootKafkaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/main/java/com/example/kafka/springbootkafka/TestController.java: -------------------------------------------------------------------------------- 1 | package com.example.kafka.springbootkafka; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class TestController { 10 | 11 | private final Producer producer; 12 | 13 | @Autowired 14 | public TestController(Producer producer) { 15 | this.producer = producer; 16 | } 17 | @PostMapping("/publish") 18 | public void messageToTopic(@RequestParam("message") String message){ 19 | 20 | this.producer.sendMessage(message); 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | consumer: 4 | bootstrap-servers: localhost:9092 5 | group-id: group_id 6 | auto-offset-reset: earliest 7 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 8 | value-deserializer: org.apache.kafka.common.serialization.StringDeserializer 9 | producer: 10 | bootstrap-servers: localhost:9092 11 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 12 | value-serializer: org.apache.kafka.common.serialization.StringSerializer 13 | -------------------------------------------------------------------------------- /springboot-kafka-basic/src/test/java/com/example/kafka/springbootkafka/SpringbootKafkaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.kafka.springbootkafka; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringbootKafkaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tic-tac-toe-AI.py: -------------------------------------------------------------------------------- 1 | #### TIC TAC TOE #### 2 | 3 | #START; 4 | 5 | 6 | #FUNCTIONS; 7 | 8 | def default(): 9 | #To be printed as Default; 10 | print("\nWelcome! Let's play TIC TAC TOE!\n") 11 | 12 | 13 | def rules(): 14 | print("The board will look like this!") 15 | print("The positions of this 3 x 3 board is same as the right side of your key board.\n") 16 | print(" 7 | 8 | 9 ") 17 | print("-----------") 18 | print(" 4 | 5 | 6 ") 19 | print("-----------") 20 | print(" 1 | 2 | 3 ") 21 | print("\nYou just have to input the position(1-9).") 22 | 23 | 24 | def play(): 25 | #Asking if the player is ready; 26 | return input("\nAre you ready to play the game? Enter [Y]es or [N]o.\t").upper().startswith('Y') 27 | 28 | 29 | def names(): 30 | #Player names input; 31 | 32 | p1_name=input("\nEnter NAME of PLAYER 1:\t").capitalize() 33 | p2_name=input("Enter NAME of PLAYER 2:\t").capitalize() 34 | return (p1_name, p2_name) 35 | 36 | 37 | def choice(): 38 | #Player choice input; 39 | p1_choice = ' ' 40 | p2_choice = ' ' 41 | while p1_choice != 'X' or p1_choice != 'O': #while loop; if the entered value isn't X or O; 42 | 43 | #WHILE LOOP STARTS 44 | 45 | p1_choice = input(f"\n{p1_name}, Do you want to be X or O?\t")[0].upper() 46 | #The input above has [0].upper() in the end; 47 | #So the user can enter x, X, xxxx or XXX; the input will always be taken as X; 48 | #Thereby, increasing the user input window; 49 | 50 | if p1_choice == 'X' or p1_choice == 'O': 51 | #if entered value is X or O; get out of the loop; 52 | break 53 | print("INVALID INPUT! Please Try Again!") 54 | #if the entered value isn't X or O, re-run the while loop; 55 | 56 | #WHILE LOOP ENDS 57 | #Assigning the value to p2 and then diplaying the values; 58 | if p1_choice == 'X': 59 | p2_choice = 'O' 60 | elif p1_choice == 'O': 61 | p2_choice = 'X' 62 | 63 | return (p1_choice, p2_choice) 64 | 65 | 66 | 67 | def first_player(): 68 | #This function will randomly decide who will go first; 69 | import random 70 | return random.choice((0, 1)) 71 | 72 | 73 | def display_board(board, avail): 74 | print(" " + " {} | {} | {} ".format(board[7],board[8],board[9]) + " " + " {} | {} | {} ".format(avail[7],avail[8],avail[9])) 75 | print(" " + "-----------" + " " + "-----------") 76 | print(" " + " {} | {} | {} ".format(board[4],board[5],board[6]) + " " + " {} | {} | {} ".format(avail[4],avail[5],avail[6])) 77 | print(" " + "-----------" + " " + "-----------") 78 | print(" " + " {} | {} | {} ".format(board[1],board[2],board[3]) + " " + " {} | {} | {} ".format(avail[1],avail[2],avail[3])) 79 | 80 | 81 | def player_choice(board, name, choice): 82 | position = 0 83 | #Initialising position as 0^; so it passes through the while loop; 84 | while position not in [1,2,3,4,5,6,7,8,9] or not space_check(board, position): 85 | position = int(input(f'\n{name} ({choice}), Choose your next position: (1-9) \t')) 86 | 87 | if position not in [1,2,3,4,5,6,7,8,9] or not space_check(board, position) or position == "": 88 | #To check whether the given position is in the set [1-9] or whether it is empty or occupied; 89 | print(f"INVALID INPUT. Please Try Again!\n") 90 | print("\n") 91 | return position 92 | 93 | 94 | # THIS IS THEFUNCTION WHERE AI IS ADDED: 95 | def CompAI(board, name, choice): 96 | position = 0 97 | possibilities = [x for x, letter in enumerate(board) if letter == ' ' and x != 0] 98 | 99 | # including both X and O, since if computer will win, he will place a choice there, but if the component will win --> we have to block that move 100 | for let in ['O', 'X']: 101 | for i in possibilities: 102 | # Creating a copy of the board everytime, placing the move and checking if it wins; 103 | # Creating a copy like this and not this boardCopy = board, since changes to boardCopy changes the original board; 104 | boardCopy = board[:] 105 | boardCopy[i] = let 106 | if(win_check(boardCopy, let)): 107 | position = i 108 | return position 109 | 110 | openCorners = [x for x in possibilities if x in [1, 3, 7, 9]] 111 | 112 | if len(openCorners) > 0: 113 | position = selectRandom(openCorners) 114 | return position 115 | 116 | if 5 in possibilities: 117 | position = 5 118 | return position 119 | 120 | openEdges = [x for x in possibilities if x in [2, 4, 6, 8]] 121 | 122 | if len(openEdges) > 0: 123 | position = selectRandom(openEdges) 124 | return position 125 | 126 | 127 | 128 | def selectRandom(board): 129 | import random 130 | ln = len(board) 131 | r = random.randrange(0,ln) 132 | return board[r] 133 | 134 | 135 | def place_marker(board, avail, choice, position): 136 | #To mark/replace the position on the board list; 137 | board[position] = choice 138 | avail[position] = ' ' 139 | 140 | 141 | def space_check(board, position): 142 | #To check whether the given position is empty or occupied; 143 | return board[position] == ' ' 144 | 145 | 146 | def full_board_check(board): 147 | #To check if the board is full, then the game is a draw; 148 | for i in range(1,10): 149 | if space_check(board, i): 150 | return False 151 | return True 152 | 153 | 154 | def win_check(board, choice): 155 | #To check if one of the following patterns are true; then the respective player has won!; 156 | 157 | #HORIZONTAL CHECK; 158 | return ( 159 | ( board[1] == choice and board[2] == choice and board[3] == choice ) 160 | or ( board[4] == choice and board[5] == choice and board[6] == choice ) 161 | or ( board[7] == choice and board[8] == choice and board[9] == choice ) 162 | #VERTICAL CHECK; 163 | or ( board[1] == choice and board[4] == choice and board[7] == choice ) 164 | or ( board[2] == choice and board[5] == choice and board[8] == choice ) 165 | or ( board[3] == choice and board[6] == choice and board[9] == choice ) 166 | #DIAGONAL CHECK; 167 | or ( board[1] == choice and board[5] == choice and board[9] == choice ) 168 | or ( board[3] == choice and board[5] == choice and board[7] == choice ) ) 169 | 170 | def delay(mode): 171 | if mode == 2: 172 | import time 173 | time.sleep(2) 174 | 175 | def replay(): 176 | #If the users want to play the game again? 177 | return input('\nDo you want to play again? Enter [Y]es or [N]o: ').lower().startswith('y') 178 | 179 | 180 | 181 | 182 | 183 | #MAIN PROGRAM STARTS; 184 | 185 | print("\n\t\t NAMASTE! \n") 186 | input("Press ENTER to start!") 187 | 188 | default() 189 | rules() 190 | 191 | 192 | while True: 193 | #################################################################################### 194 | 195 | #Creating the board as a list; to be kept replacing it with user input; 196 | theBoard = [' ']*10 197 | 198 | #Creating the available options on the board: 199 | available = [str(num) for num in range(0,10)] # a List Comprehension 200 | #available = '0123456789' 201 | 202 | 203 | 204 | print("\n[0]. Player vs. Computer") 205 | print("[1]. Player vs. Player") 206 | print("[2]. Computer vs. Computer") 207 | mode = int(input("\nSelect an option [0]-[2]: ")) 208 | if mode == 1: 209 | #Asking Names; 210 | p1_name, p2_name = names() 211 | # Asking Choices; Printing choices; X or O; 212 | p1_choice, p2_choice = choice() 213 | print(f"\n{p1_name}:", p1_choice) 214 | print(f"{p2_name}:", p2_choice) 215 | 216 | elif mode == 0: 217 | p1_name = input("\nEnter NAME of PLAYER who will go against the Computer:\t").capitalize() 218 | p2_name = "Computer" 219 | # Asking Choices; Printing choices; X or O; 220 | p1_choice, p2_choice = choice() 221 | print(f"\n{p1_name}:", p1_choice) 222 | print(f"{p2_name}:", p2_choice) 223 | 224 | else: 225 | p1_name = "Computer1" 226 | p2_name = "Computer2" 227 | p1_choice, p2_choice = "X", "O" 228 | print(f"\n{p1_name}:", p1_choice) 229 | print(f"\n{p2_name}:", p2_choice) 230 | 231 | 232 | 233 | #Printing randomly who will go first; 234 | if first_player(): 235 | turn = p2_name 236 | else: 237 | turn = p1_name 238 | 239 | print(f"\n{turn} will go first!") 240 | 241 | #Asking the user, if ready to play the game; Output will be True or False; 242 | if(mode == 2): 243 | ent = input("\nThis is going to be fast! Press Enter for the battle to begin!\n") 244 | play_game = 1 245 | else: 246 | play_game = play() 247 | 248 | while play_game: 249 | 250 | ############################ 251 | #PLAYER1 252 | if turn == p1_name: 253 | 254 | #Displaying the board; 255 | display_board(theBoard, available) 256 | 257 | #Position of the input; 258 | if mode != 2: 259 | position = player_choice(theBoard, p1_name, p1_choice) 260 | else: 261 | position = CompAI(theBoard, p1_name, p1_choice) 262 | print(f'\n{p1_name} ({p1_choice}) has placed on {position}\n') 263 | 264 | #Replacing the ' ' at *position* to *p1_choice* in *theBoard* list; 265 | place_marker(theBoard, available, p1_choice, position) 266 | 267 | #To check if Player 1 has won after the current input; 268 | if win_check(theBoard, p1_choice): 269 | display_board(theBoard, available) 270 | print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") 271 | if(mode): 272 | print(f'\n\nCONGRATULATIONS {p1_name}! YOU HAVE WON THE GAME!\n\n') 273 | else: 274 | print('\n\nTHE Computer HAS WON THE GAME!\n\n') 275 | print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") 276 | play_game = False 277 | 278 | else: 279 | #To check if the board is full; if yes, the game is a draw; 280 | if full_board_check(theBoard): 281 | display_board(theBoard, available) 282 | print("~~~~~~~~~~~~~~~~~~") 283 | print('\nThe game is a DRAW!\n') 284 | print("~~~~~~~~~~~~~~~~~~") 285 | break 286 | #If none of the above is possible, next turn of Player 2; 287 | else: 288 | turn = p2_name 289 | 290 | 291 | ############################ 292 | #PLAYER2 293 | elif turn == p2_name: 294 | 295 | #Displaying the board; 296 | display_board(theBoard, available) 297 | 298 | #Position of the input; 299 | if(mode == 1): 300 | position = player_choice(theBoard, p2_name, p2_choice) 301 | else: 302 | position = CompAI(theBoard, p2_name, p2_choice) 303 | print(f'\n{p2_name} ({p2_choice}) has placed on {position}\n') 304 | 305 | #Replacing the ' ' at *position* to *p2_choice* in *theBoard* list; 306 | place_marker(theBoard, available, p2_choice, position) 307 | 308 | #To check if Player 2 has won after the current input; 309 | if win_check(theBoard, p2_choice): 310 | display_board(theBoard, available) 311 | print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") 312 | if(mode): 313 | print(f'\n\nCONGRATULATIONS {p2_name}! YOU HAVE WON THE GAME!\n\n') 314 | else: 315 | print('\n\nTHE Computer HAS WON THE GAME!\n\n') 316 | print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") 317 | play_game = False 318 | 319 | else: 320 | #To check if the board is full; if yes, the game is a draw; 321 | if full_board_check(theBoard): 322 | display_board(theBoard, available) 323 | print("~~~~~~~~~~~~~~~~~~") 324 | print('\nThe game is a DRAW!\n') 325 | print("~~~~~~~~~~~~~~~~~~") 326 | break 327 | #If none of the above is possible, next turn of Player 2; 328 | else: 329 | turn = p1_name 330 | 331 | 332 | #If the users want to play the game again? 333 | if replay(): 334 | #if Yes; 335 | continue 336 | else: 337 | #if No; 338 | break 339 | 340 | #################################################################################### 341 | 342 | print("\n\n\t\t\tTHE END!") 343 | 344 | 345 | 346 | #END --------------------------------------------------------------------------------