Skip to content

Commit

Permalink
feat: qdrant resource example (#64)
Browse files Browse the repository at this point in the history
* feat: qdrant resource example

* update qdrant example
- `shuttle_qdrant::Qdrant` now returns a `QdrantClient`
- pass in `cloud_url` and `api_key`, read from `Secrets.toml`

* update versions

* fix: filenames

* fix: correct shuttle version

* docs: add qdrant to readme

---------

Co-authored-by: jonaro00 <54029719+jonaro00@users.noreply.github.com>
  • Loading branch information
paulotten and jonaro00 authored Jan 23, 2024
1 parent d595ecd commit 826fab3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Actix Web | [websocket-actorless](./actix-web/websocket-actorless/) | Websocket
Actix Web | [cookie-authentication](./actix-web/cookie-authentication/) | Use JWT to authenticate API endpoints | `cargo shuttle init --from shuttle-hq/shuttle-examples --subfolder actix-web/cookie-authentication`
Axum | [hello-world](./axum/hello-world/) | Hello World | `cargo shuttle init --template axum`
Axum | [metadata](./axum/metadata/) | Simple app that prints the service information such as Shuttle service name | `cargo shuttle init --from shuttle-hq/shuttle-examples --subfolder axum/metadata`
Axum | [qdrant](./axum/qdrant/) | Barebones example of the shuttle-qdrant plugin | `cargo shuttle init --from shuttle-hq/shuttle-examples --subfolder axum/qdrant`
Axum | [static-files](./axum/static-files/) | Hello World page that serves static HTML and JS files | `cargo shuttle init --from shuttle-hq/shuttle-examples --subfolder axum/static-files`
Axum | [static-next-server](./axum/static-next-server/) | SPA server for serving a apps from frameworks such as Next.js | `cargo shuttle init --from shuttle-hq/shuttle-examples --subfolder axum/static-next-server`
Axum | [websocket](./axum/websocket/) | Websocket app that checks the status of Shuttle's API | `cargo shuttle init --from shuttle-hq/shuttle-examples --subfolder axum/websocket`
Expand Down
12 changes: 12 additions & 0 deletions axum/qdrant/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "shuttle-axum-qdrant"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.7.3"
qdrant-client = "1.7.0"
shuttle-axum = "0.36.0"
shuttle-qdrant = "0.36.0"
shuttle-runtime = "0.36.0"
tokio = "1.26.0"
3 changes: 3 additions & 0 deletions axum/qdrant/Secrets.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Note that we use gRPC (port 6334) to talk to Qdrant.
CLOUD_URL = 'https://xyz-example.eu-central.aws.cloud.qdrant.io:6334'
API_KEY = 'your_api_key'
25 changes: 25 additions & 0 deletions axum/qdrant/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use axum::{extract::State, routing::get, Router};
use qdrant_client::prelude::*;
use std::sync::Arc;

struct AppState {
qdrant: QdrantClient,
}

async fn list_collections(State(state): State<Arc<AppState>>) -> String {
format!("{:?}\n", state.qdrant.list_collections().await)
}

#[shuttle_runtime::main]
async fn axum(
#[shuttle_qdrant::Qdrant(cloud_url = "{secrets.CLOUD_URL}", api_key = "{secrets.API_KEY}")]
qdrant: QdrantClient,
) -> shuttle_axum::ShuttleAxum {
let state = Arc::new(AppState { qdrant });

let router = Router::new()
.route("/", get(list_collections))
.with_state(state);

Ok(router.into())
}

0 comments on commit 826fab3

Please # to comment.