Skip to content

s1ches/WeatherService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WeatherService - Test task

What does the service do?

Service can get actual data of weather in Kazan
Every minute it's fetching data from accuweather.com API, and store in Database,
then we can get last 10 actual weather infos

How it is works?

image

Service A every minute fetching weather from accuweather.com API and Produce data to Apache Kafka
Service B consume messages from Kafka and send gRPC request on ServiceC to add weather info in Database Service C has service to add weather info in Database which calls by Service B, Service C it's RESTful API which has one method to get last ten weather records

ServiceC - RESTful API which was built in Clean Architecture with CQRS and DDD(with Anemic Domain models) patterns

image

About layers:

  • Presentation
    image

Presentation layer has 1 project Web Application(Web API), which has 1 controller and 1 method, which returns ten latest weather records

  • Core
    image

Core layer(Business logic layer) has 2 projects:

  • Domain - for Domain models

  • Application - for BusinessLogic realization

  • Infrastructure
    image

Infrastructure layer for realization service and interfaces/abstraction which need Core layer:

  • ServiceC.Infrastructure.Grpc - for realization gRPC services
  • ServiceC.Infrastructure.Persistence - for DbContext, Migrations, Entities Configurations

Workers: ServiceB and ServiceC

image

  • ServiceA - worker which works with Hangfire and collect data from external api by Cron every minute and then produce it to Kafka
    image
  • ServiceB - worker which constantly works and consumes messages from Kafka, on every message ServiceB send gRPC request to a WeatherInteractionService to add data in Database
    image
  • Common - contains protobuf file for workers
    image

How to Run the application

  1. You need to up the docker-compose.yaml file with Kafka, Zookeeper and Shema-Registry image

docker-compose:

version: "3.7"
services:
  zookeeper:
    restart: always
    image: docker.io/bitnami/zookeeper:3.8
    ports:
      - "2181:2181"
    volumes:
      - "zookeeper-volume:/bitnami"
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
  kafka:
    restart: always
    image: docker.io/bitnami/kafka:3.3
    ports:
      - "9093:9093"
    volumes:
      - "kafka-volume:/bitnami"
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:9093
      - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka:9092,EXTERNAL://localhost:9093
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=CLIENT
    depends_on:
      - zookeeper
  schema-registry:
    image: confluentinc/cp-schema-registry:latest
    depends_on:
      - zookeeper
      - kafka
    ports:
      - "8035:8035"
    environment:
      SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: PLAINTEXT://kafka:9092
      SCHEMA_REGISTRY_HOST_NAME: schema-registry
      SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8035
volumes:
  kafka-volume:
  zookeeper-volume:
  1. In ServiceA in appsettings.json you need to replace WeatherApiConfig(WeatherApiKey) DefaultConnection(Username, Host and Password) with yours and create WorkerWeatherCollectorDb in postgres
  2. In ServiceC in appsettings.json you need to replace DefaultConnection(Username, Host and Password) and apply migrations

After that u can run services A, B and C in any order you want