Skip to content

x2d7751347m/Tokio-Tungstenite-Rocket

Repository files navigation

Rust Web & Websocket Server

  • Coroutine & Non-blocking

Tutorial movie

tutorial1

▲ Click the link!

Swagger ui (Check out available API here!)

  1. If running on a local server

http://localhost:8000/swagger-ui

Websocket url

  1. IMPORTANT: PORT IS 8080, NOT 8000

    1. If running on a local server

      ws://localhost:8080/socket?{topic name}
      1. e.g) ws://localhost:8080/socket?food_topic

        ws://localhost:8080/socket?room1
  2. Note) Swagger does not support WebSockets

Kafka topic console

  1. If running on a local server

http://localhost:9080

How to tune

  1. Modify the file in the path below.

    api/Rocket.toml
    config\src\app_config.rs
    • You don’t have to create a matching Database.

  2. Turn on the appropriate database feature for your chosen db in service/Cargo.toml (the "sqlx-postgres", line)

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

  4. Run kafka server infrastructure using docker compose up

  5. Install Cargo(https://doc.rust-lang.org/cargo/getting-started/installation.html)

  6. Execute cargo run to start the server

  7. You can go to http://localhost:8000/swagger-ui/index.html to see the api documentation about this demo project.

    1. Note: WebSocket is binding at port 8080, so you can go to ws://localhost:8080/socket?{group/topic name} to connect to the WebSocket about this demo project.

docker compose up command
docker compose up -d

Producers and consumers writing and reading events from Kafka topics ( ws://…​/socket?{query} )

kafka producers consumers topics

User table columns

user table

Email table columns

email table

Post table columns

post 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. Note: websocket url e.g) ws://localhost:8080/socket?{group/topic name}

Notice

  1. You don’t need to create a user when connecting to ws://…​/socket?{group}.

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published