artshishkin / art-gelenler-event-driven

Tutorial - Event-Driven Microservices: Spring Boot, Kafka and Elastic - from Ali Gelenler (Udemy)
Apache License 2.0
2 stars 4 forks source link

CircleCI codecov Tested on JVM 11 (Ubuntu) Tested on JVM 17 (Ubuntu) Tested on JVM 17 (MacOS) GitHub issues Spring Boot version Twitter4J Kafka Elasticsearch OpenAPI Docker Testcontainers version Keycloak Container PostgreSQL Container Kafka Container Elasticsearch Container MockServer Container Project licence

art-gelenler-event-driven

Tutorial - Event-Driven Microservices: Spring Boot, Kafka and Elastic - from Ali Gelenler (Udemy)

Section 3: First service: twitter-to-kafka-service - How to use Twitter4j & Kafka producers

13. Running Apache Kafka cluster with docker: Kafka, Zookeeper and Schema Registry

  1. Start kafka cluster
    • docker-compose -f common.yml -f kafka_cluster.yml up
  2. Kafkacat command line
    • docker run --tty --network host confluentinc/cp-kafkacat kafkacat -b localhost:29092 -L
    • -L - list
    • -b - brokers
    • Kafkacat docker commands

19. Integrate Kafka modules with Microservice: Use Kafka as event store for service

  1. Kafkacat as consumer
    • docker run --rm --tty --network host confluentinc/cp-kafkacat kafkacat -b localhost:29092 -C -t twitter-topic
    • docker container ls -a --filter ancestor=confluentinc/cp-kafkacat - list useless containers
    • docker container rm $(docker container ls -a --filter ancestor=confluentinc/cp-kafkacat -q) - remove all containers by image name

Section 4: Externalizing configuration with Spring Cloud Config Server

25. Using remote GitHub repository

  1. Create private repository art-gelenler-event-driven-config-repo
  2. Create github access token
    • Settings -> Developer settings -> Personal Access Tokens -> Create new
    • Select scopes: repo
    • Generate token
    • Copy token
  3. Create environment variable
    • GITHUB_ACCESS_TOKEN = {Paste token here}
  4. Use separate-remote-git-repo spring profile to start application

28. Using JCE to encrypt sensitive data

  1. Install SDKMAN (I used WSL Ubuntu in Windows)
  2. Install Spring Boot
    • sdk install springboot
  3. Check installations
    • ls ~/.sdkman/candidates/
    • cd ~/.sdkman/candidates/springboot
  4. Install Spring Cloud CLI
    • spring install org.springframework.cloud:spring-cloud-cli:3.1.1
  5. Encrypt password
    • spring encrypt PLAIN_TEXT --key KEY
  6. Set ENCRYPT_KEY through Environment variable

Section 5: kafka-to-elastic-service: How to use Kafka consumers and Elastic Index API

36. Running elastic search with docker

  1. Start elastic cluster
    • docker-compose -f common.yml -f elastic_cluster.yml up
  2. In case of error in Windows
    • max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    • use commands for Windows
    • wsl -d docker-desktop
    • sysctl -w vm.max_map_count=262144
    • or permanently add vm.max_map_count = 262144 to /etc/sysctl.conf

Section 9: Securing the services: Spring security OAuth2, OpenID connect, Keycloak and JWT

68. Run and configure Keycloak authorization server with OIDC for authentication

Stack variations

ENCRYPT_KEY must be provided through System Environment Variables

  1. Infrastructure (without microservices)
    • docker-compose up -d
    • docker-compose --profile=debug up -d (with adminer, kibana)
  2. Full stack
    • docker-compose --profile=app up -d