Skip to content

Latest commit

 

History

History
153 lines (88 loc) · 3.53 KB

README.adoc

File metadata and controls

153 lines (88 loc) · 3.53 KB

Ktor Web & Websocket Server

  • Coroutine & Non-blocking

  • R2dbc

Tutorial movie

tutorial1

▲ Click the link!

Testing video

test1

▲ Click the link!

Swagger ui (Check out available APIs here!)

  1. If running on a local server

http://localhost:8080

Websocket

  1. Websocket url without Kafka

    1. If running on a local server

      ws://localhost:8080/v1/api/chat
      1. Note) /chat consists of connections only within one server without kafka.

  2. Websocket url Including Kafka

    1. If running on a local server

    2. ws://localhost:8080/v1/api/messages/{group}

      1. e.g)

        ws://localhost:8080/v1/api/messages/food_topic
        ws://localhost:8080/v1/api/messages/food_topic
  3. Note) Swagger does not support WebSockets

Server operating environment

1 vCPU, 2 GB per instance on AWS

task definition

Kafka topic console

  1. If running on a local server

http://localhost:9080

How to tune

  1. Change parameters in src/main/resources and plugin/src/test/resources/kafka-config-map.conf

    • You don’t have to create a matching Database. Just connect to your db and fill src/main/resources/application.conf > ktor.deployment.db

  2. Install Docker

  3. Run kafka server infrastructure using docker compose up

    1. For local

      • Enter the command into bash or powershell depending on your operating environment.

        // Running it directly
        ./gradlew runDocker
        // Builds and publishes a project's Docker image to a local registry.
        ./gradlw publishImageToLocalRegistry
    2. For cloud deployment

      1. Set aws environmental variables and github actions secrets in .github/workflows/aws.yml

      2. git push or run github actions manually

docker compose up command
docker compose up -d

Architecture

Cloud Architecture of AWS ECS with ALB

Cloud Architecture of AWS ECS with ALB

Producers and consumers writing and reading events from Kafka topics ( /messages/{group} )

kafka producers consumers topics

Ci/cd pipeline

aws architecture

User table

User Table

Email table

Email Table

Image File table

Image File Table

How to use

  1. Post a user

  2. Login via /login path to acquire Authorization key

  3. Set Authorization key to Authorization header

    1. Don’t forget the prefix `Bearer `

    2. e.g) Bearer eyJhbGciOiJIU…​.

  4. Now you can access every apis and websocket!

    1. websocket url e.g) ws://localhost:8080/chat

websocket commands
connections // Shows the number of connections (/chat path)
bye // command for disconnect
did you still alive? // It is not a server-side command, but written in mock client test code in `src/test/kotlin/com/aftertime/ApplicationTest.kt`.

Notice

  1. You don’t need to create a user when connecting to /messages/{group}.

  2. If you connected with Authorization header, the server shows your nickname.

…​/admins/…​ paths can only be accessed by admins(set your role to ADMIN.)

Flow Chart

https://holy-tungsten-cc5.notion.site/56c389c4552947af99edb88239ad7e56?v=321dc448197244fcb3d515c811714d77&pvs=4