Skip to content

genadigeno/AMS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

img Accident Management System(AMS)

Project Description

Accident Management System(AMS) is the project implemented with Event-Driven Architectural approach
that provides messages distribution across several services based on their event type, ACCIDENT_TYPE.
It is simulation of what happens when some kind of accident happens,
it can be criminal, car, fire or some kind of accident that are saved in some
(in case of default settings: accident.events) source topic.
The list of services (repositories on github):

  • accident-event-stream - app that produces large amound of data as event stream and distributes them across services.
  • emergency-service - app that is responsible of handling corresponding data to response an accident in emergency way
  • fire-rescue-service - app that is responsible of handling corresponding data to response an accident in emergency way
  • law-enforcement-service - app that is responsible of handling corresponding data to response an accident in emergency way
  • statistics-service - app that collects and analyzes data

Table of Contents

Visual

alt text

Used Technologies

  • img Event-Driven Architecture
  • img Java 17+
  • img Spring Boot 3.1.x & Spring Boot JPA
  • img Apache Kafka & Kafka Streams library
  • img Docker
  • img Git
  • img Gitlab CI/CD

Project status

Ready for use


Installation

Prerequisites

  • Java 17+ (JAVA_HOME must be set)
  • Maven 3.8+ (MAVEN_HOME must be set)
  • Docker
  • Docker Compose

Application starting steps

  1. Create working folder and clone the repositories:

    mkdir ams
    cd ams
    git clone https://gitlab.com/projectAMS/accident-event-stream.git
    git clone https://gitlab.com/projectAMS/emergency-service.git
    git clone https://gitlab.com/projectAMS/fire-rescue-service.git
    git clone https://gitlab.com/projectAMS/police-service.git
    git clone https://gitlab.com/projectAMS/statistics-service.git
    git clone https://gitlab.com/projectAMS/gitlab-profile.git scripts
    mvn clean package -f .\accident-event-stream -am
    mvn clean package -f .\emergency-service -am
    mvn clean package -f .\fire-rescue-service -am
    mvn clean package -f .\statistics-service -am
    mvn clean package -f .\statistics-service -am
  2. Run kafka cluster + confluent schema registry with docker compose:

    docker-compose -f .\scripts\docker-compose.yml up -d
  3. Start AMS event stream service:

     ./scripts/start-ams-event-stream.sh

    or if windows:````

     ./scripts/start-ams-event-stream.bat

    Note: every time you run the script new instance are created.```` For simplicity, it is limited to 3 instances, subsequent instances will be idle. Same for other services.
    properties with default values:

    BOOTSTRAP_SERVERS=localhost:9092,localhost:9093
    STATE_STORE_CACHE_MAX_SIZE=0
    STATE_DIRECTORY=./state-dir
    AVRO_SUBJECT_VERSION=latest
    SCHEMA_REGISTRY_URL=http://localhost:8081
    SOURCE_TOPIC_NAME=accident.events
    DLT_SOURCE_TOPIC_NAME=accident.events-dlt
    EMERGENCY_SERVICE_TOPIC_NAME=emergency.events
    POLICE_SERVICE_TOPIC_NAME=police.events
    FIRE_RESCUE_SERVICE_TOPIC_NAME=fire-rescue.events
    STATISTICS_SERVICE_TOPIC_NAME=statistics.events

    example of properties with custom values:

    ./scripts/start-emergency-service.sh --SERVER_PORT=8081 --BOOTSTRAP_SERVERS=localhost:9092,localhost:9093 \
       --STATE_STORE_CACHE_MAX_SIZE=1000 --STATE_DIRECTORY=./custom-directory \
       --SOURCE_TOPIC_NAME=accident.events --DLT_SOURCE_TOPIC_NAME.name=accident.events-dlt

    3.1 start emergency service:

    ./scripts/start-emergency-service.sh

    or if windows:

    ./scripts/start-emergency-service.bat

    properties with default values:

    BOOTSTRAP_SERVERS=localhost:9092,localhost:9093
    SCHEMA_REGISTRY_URL=http://localhost:8081
    POSTGRES_URL=jdbc:postgresql://localhost:5432/accident_management_service
    POSTGRES_USER=postgres
    POSTGRES_PASSWORD=test
    MAIN_TOPIC_NAME=emergency.events
    DLT_TOPIC_NAME=emergency.events-dlt

    example of properties with custom values:

    ./scripts/start-emergency-service.sh --SERVER_PORT=8081 --BOOTSTRAP_SERVERS=localhost:9092,localhost:9093 \
       --POSTGRES_URL=jdbc:postgresql://localhost:5432/accident_management_service --POSTGRES_PASSWORD=testpass \
       --MAIN_TOPIC_NAME=emergency.events --DLT_TOPIC_NAME.name=emergency.events-dlt

    3.2 start fire rescue service:

    ./scripts/start-fire-resque-service.sh

    properties with default values:

     ...
     KAFKA_MAIN_TOPIC_NAME=fire-rescue.events
     KAFKA_DLT_TOPIC_NAME=fire-rescue.events-dlt

    3.3 start police service:

    ./scripts/start-police-service.sh

    properties with default values:

     ...
     KAFKA_MAIN_TOPIC_NAME=police.events
     KAFKA_DLT_TOPIC_NAME=police.events-dlt

    3.4 start statistics service:

    ./scripts/start-statistics-service.sh

    properties with default values:

     ...
     KAFKA_MAIN_TOPIC_NAME=statistics.events
     KAFKA_DLT_TOPIC_NAME=statistics.events-dlt

Usage

  1. Start the stream bombarder application: [NOT FINISHED]
     ./scripts/start-stream-bombarder.sh
    delay period between iterations in seconds is calculated by:
    int wait = (int) Math.floor(random.nextDouble(1.5) * 1000.0);
    and number of events sending per iteration:
    private static List<?> getEvents(double scale) {
         List<?> events = new ArrayList<>();
         int randomInt  = new Random().nextInt(100);
         int scaled = (int)((double) randomInt * scale);
         for(int i = 0; i < scaled; ++i) {
             events.add(getAccidentModel());
         }
         return events;
     }
    properties with default values:
     bootstrap.servers=localhost:9092,localhost:9093
     client.id=stream-bombarder
     enable.idempotence=true
     schema.registry.url=http://localhost:8081
     topic=accident.events
     scale=1
    example of properties with custom values:
     ./scripts/start-stream-bombarder.sh --bootstrap.servers=localhost:9092,localhost:9093 \
         --client.id=stream-bombarder --schema.registry.url=http://localhost:8081 --scale=10

About

Accident Management System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published