-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: better readme md and more examples
- Loading branch information
Showing
18 changed files
with
239 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
# Upstash Rust QStash SDK | ||
|
||
# Upstash QStash Rust SDK | ||
|
||
**QStash** is a robust, HTTP-based messaging and scheduling solution optimized for serverless and edge runtimes. With a stateless, HTTP-driven design, it supports a broad range of environments and platforms, including: | ||
|
||
- Serverless functions (e.g., AWS Lambda) – [Example](https://github.com/mertakman/qstash-rs/tree/main/examples/aws-lambda/main.rs) | ||
- Cloudflare Workers – [Example](https://github.com/mertakman/qstash-rs/tree/main/examples/cloudflare-workers/main.rs) | ||
- Fastly Compute@Edge | ||
- Next.js, including [Edge runtime](https://nextjs.org/docs/api-reference/edge-runtime) | ||
- Deno | ||
- Client-side web and mobile applications | ||
- WebAssembly | ||
- Any other environment where HTTP-based communication is preferred over TCP | ||
|
||
## How QStash Works | ||
|
||
QStash serves as the intermediary message broker for serverless applications. By sending a simple HTTP request to QStash, you can include a destination, payload, and optional configurations. QStash then stores the message securely and reliably delivers it to the designated API endpoint. In cases where the destination is temporarily unavailable, QStash ensures at-least-once delivery by automatically retrying until the message is successfully received. | ||
|
||
## Quick Start | ||
|
||
### 1. Obtain Your Authorization Token | ||
|
||
To get started, head to the [Upstash Console](https://console.upstash.com/qstash) and copy your **QSTASH_TOKEN**. | ||
|
||
### 2. Explore Examples | ||
|
||
For API documentation and a quickstart guide, refer to the official [QStash API Documentation](https://upstash.com/docs/qstash/api/). Below, you'll find links to additional examples that demonstrate usage for each endpoint: | ||
|
||
- **Dead Letter Queue** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/dead_letter_queue/main.rs) | ||
- **Events** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/events/main.rs) | ||
- **LLM** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/llm/main.rs) | ||
- **Messages** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/messages/main.rs) | ||
- **Queues** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/queues/main.rs) | ||
- **Schedulers** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/schedulers/main.rs) | ||
- **Signing Keys** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/signing_keys/main.rs) | ||
- **URL Groups** – [Example](https://github.com/mertakman/qstash-rs/blob/main/examples/url_groups/main.rs) | ||
|
||
## Supported Environments | ||
|
||
QStash is ideal for use with serverless architectures and edge deployments, supporting scenarios where HTTP-based communication provides flexibility and compatibility with modern applications. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
use std::env; | ||
|
||
use qstash_rs::client::QstashClient; | ||
use qstash_rs::{client::QstashClient, dead_letter_queue::DlqQueryParams}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let api_key = env::var("QSTASH_API_KEY").expect("QSTASH_API_KEY not set"); | ||
|
||
let client = QstashClient::builder().api_key(&api_key).build().unwrap(); | ||
let client = QstashClient::builder().api_key(&api_key).build()?; | ||
|
||
let dlq_messages_list = client.dlq_list_messages(DlqQueryParams::default()).await?; | ||
println!("{:#?}", dlq_messages_list); | ||
|
||
let message_list = vec![]; | ||
let deleted_messages_list = client.dlq_delete_messages(message_list).await?; | ||
println!("{:#?}", deleted_messages_list); | ||
|
||
let dlq_message_id = ""; | ||
client.dlq_delete_message(dlq_message_id).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
use std::env; | ||
|
||
use qstash_rs::client::QstashClient; | ||
use qstash_rs::{ | ||
client::QstashClient, | ||
llm_types::{ChatCompletionRequest, Message}, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let api_key = env::var("QSTASH_API_KEY").expect("QSTASH_API_KEY not set"); | ||
let client = QstashClient::builder().api_key(&api_key).build()?; | ||
|
||
let client = QstashClient::builder().api_key(&api_key).build().unwrap(); | ||
|
||
let mut chat_completion_request = ChatCompletionRequest::default(); | ||
chat_completion_request.model = "meta-llama/Meta-Llama-3-8B-Instruct".to_string(); | ||
chat_completion_request.messages = vec![Message { | ||
role: "user".to_string(), | ||
content: "What is the capital of Türkiye?".to_string(), | ||
name: None, | ||
}]; | ||
|
||
println!("Starting the process to create a chat completion."); | ||
let resp = client | ||
.create_chat_completion(chat_completion_request) | ||
.await?; | ||
println!("Retrieved response succesfully"); | ||
println!("{:#?}", resp); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,62 @@ | ||
use qstash_rs::client::QstashClient; | ||
use http::{ | ||
header::{AUTHORIZATION, CONTENT_TYPE}, | ||
HeaderValue, | ||
}; | ||
use qstash_rs::{client::QstashClient, message_types::MessageResponseResult}; | ||
use reqwest::header::HeaderMap; | ||
use std::env; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let api_key = env::var("QSTASH_API_KEY").expect("QSTASH_API_KEY not set"); | ||
|
||
let client = QstashClient::builder().api_key(&api_key).build().unwrap(); | ||
let destination = "https://www.example.com".to_string(); | ||
let body = "{\"message\": \"Hello, world!\"}".to_string(); | ||
|
||
let message_ids = [ | ||
"msg_id_0".to_string(), | ||
"msg_id_1".to_string(), | ||
"msg_id_2".to_string(), | ||
"msg_id_3".to_string(), | ||
]; | ||
let mut headers = HeaderMap::new(); | ||
|
||
let client = QstashClient::builder().api_key(" ").build().unwrap(); | ||
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); | ||
headers.insert("Upstash-Method", HeaderValue::from_static("POST")); | ||
headers.insert("Upstash-Delay", HeaderValue::from_static("0s")); | ||
headers.insert("Upstash-Retries", HeaderValue::from_static("3")); | ||
headers.insert( | ||
"Upstash-Forward-Custom-Header", | ||
HeaderValue::from_static("custom-value"), | ||
); | ||
|
||
let client: QstashClient = QstashClient::builder().api_key(&api_key).build()?; | ||
println!( | ||
"Starting to publish message to the destination: {}", | ||
destination | ||
); | ||
|
||
let publish_message_resp = client | ||
.publish_message(&destination, headers, body.clone().into()) | ||
.await?; | ||
println!("Message published successfully to {}!", destination); | ||
println!( | ||
"Response from publishing message: {:#?}", | ||
publish_message_resp | ||
); | ||
|
||
let message_id = match publish_message_resp { | ||
MessageResponseResult::URLResponse(url_response) => url_response.message_id, | ||
MessageResponseResult::URLGroupResponse(_) => { | ||
panic!("Response is not of type URLResponse"); | ||
} | ||
}; | ||
|
||
println!("Retrieving message with id: {}", message_id); | ||
let get_message_resp = client.get_message(&message_id).await?; | ||
println!("Successfully retrieved message with id: {}.", message_id); | ||
println!("Retrieved message details: {:#?}", get_message_resp); | ||
|
||
println!("Initiating cancellation of message with id: {}", message_id); | ||
client.cancel_message(&message_id).await?; | ||
println!( | ||
"Message with id: {} has been cancelled successfully.", | ||
message_id | ||
); | ||
|
||
// client.publish_message(destination, headers, body).await?; | ||
// client.enqueue_message(destination, queue_name, headers, body) | ||
// client.batch_messages(destination, queue_name, headers, body) | ||
// client.get_message(destination, queue_name, headers, body) | ||
// client.cancel_message(&"msg_id_0".to_string()).await?; | ||
// client.bulk_cancel_messages(message_ids[1..].to_vec()).await?; | ||
// | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.