Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
rust-version:
- "stable"
- "nightly"
- "1.78.0" # MSRV
- "1.88" # MSRV

steps:
- name: Install Rust
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
fail-fast: false
matrix:
examples:
[ "actors", "bindings", "client", "configuration", "conversation-alpha1", "conversation-alpha2", "crypto", "invoke/grpc", "invoke/grpc-proxying", "jobs", "jobs-failurepolicy", "pubsub", "query_state", "secrets-bulk" ]
[ "actors", "bindings", "client", "configuration", "conversation-alpha1", "conversation-alpha2", "crypto", "invoke/grpc", "invoke/grpc-proxying", "jobs", "jobs-failurepolicy", "pubsub", "query_state", "secrets-bulk", "workflow", "workflow-history-propagation", "workflow-parallel", "workflow-sustained", "workflow-taskexecutionid" ]
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
18 changes: 8 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ resolver = "2"

[workspace.dependencies]
async-trait = "0.1"
prost = "0.13.4"
prost-types = "0.13.4"
prost = "0.14"
prost-types = "0.14"

serde = "1.0"
serde_json = "1.0"
Expand All @@ -22,21 +22,19 @@ tokio = "1.39"
tokio-stream = "0.1"
tokio-util = "0.7"

tonic = "0.12.3"
tonic-build = "0.12.3"

[patch.crates-io]
# Pinning getrandom to 0.3.x to maintain compatibility with MSRV 1.78.0, as getrandom 0.4.x requires Rust 1.85.0 or later
getrandom = { git = "https://github.com/rust-random/getrandom.git", rev = "38e4ad38309a85b56eef4fc759535ccfc322ba9a" }
tonic = "0.14.6"
tonic-build = "0.14.6"
tonic-prost = "0.14.6"
tonic-prost-build = "0.14.6"

[workspace.package]
version = "0.18.0-rc.0"
authors = [
"Mike Nguyen <hey@mike.ee>",
"The Dapr Authors <dapr@dapr.io>"
]
edition = "2021"
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/dapr/rust-sdk"

rust-version = "1.78.0" # MSRV
rust-version = "1.88.0" # MSRV
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ resiliency.

## Prerequisites

Ensure you have Rust version 1.78 or higher installed. If not, install Rust [here](https://www.rust-lang.org/tools/install).
Ensure you have Rust version 1.85 or higher installed. If not, install Rust [here](https://www.rust-lang.org/tools/install).

These crates no longer require protoc unless to recompile the protobuf files.

Expand All @@ -65,13 +65,17 @@ use dapr;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get the Dapr port and create a connection
let port: u16 = std::env::var("DAPR_GRPC_PORT")?.parse()?;
let addr = format!("https://127.0.0.1:{}", port);
let addr = format!("http://127.0.0.1:{}", port);

// Create the client
let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr).await?;
}
```

## Workflows

Workflows are available through the default-on `workflow` cargo feature and the `dapr::workflow` module. See the [workflow](https://github.com/dapr/rust-sdk/tree/main/examples/src/workflow), [workflow-parallel](https://github.com/dapr/rust-sdk/tree/main/examples/src/workflow-parallel), [workflow-taskexecutionid](https://github.com/dapr/rust-sdk/tree/main/examples/src/workflow-taskexecutionid), [workflow-sustained](https://github.com/dapr/rust-sdk/tree/main/examples/src/workflow-sustained), and [workflow-history-propagation](https://github.com/dapr/rust-sdk/tree/main/examples/src/workflow-history-propagation) examples.

## Explore more examples

Browse through more examples to understand the SDK better: [View examples](https://github.com/dapr/rust-sdk/tree/main/examples)
Expand Down
2 changes: 1 addition & 1 deletion dapr-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::iter;
use proc_macro2::TokenTree;
use quote::{format_ident, quote};
use syn::parse::{Parse, ParseStream};
use syn::{parse_macro_input, Ident, LitStr};
use syn::{Ident, LitStr, parse_macro_input};

use proc_macro::TokenStream;

Expand Down
12 changes: 9 additions & 3 deletions dapr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ readme = "README.md"
keywords = ["microservices", "dapr"]
rust-version.workspace = true

[features]
default = ["workflow"]
workflow = ["dep:dapr-durabletask", "dep:tokio-util"]

[dependencies]
async-trait = { workspace = true }
axum = "0.7"
chrono = "0.4"
dapr-durabletask = { version = "0.0.1", optional = true }
futures = "0.3"
log = "0.4"
prost = { workspace = true }
prost-types = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tonic = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
tokio-util = { workspace = true, features = ["io"] }
tonic-prost = { workspace = true }
tokio = { workspace = true, features = ["rt", "sync"] }
tokio-util = { workspace = true, features = ["io"], optional = true }


[dev-dependencies]
Expand All @@ -32,7 +38,7 @@ once_cell = "1.19"
dapr = { path = "./" }
dapr-macros = { path = "../dapr-macros" }
tokio = { workspace = true, features = ["full"] }
uuid = { version = "=1.20.0", features = ["v4"] }
uuid = { version = "=1.23.0", features = ["v4"] }
tokio-stream = { workspace = true }
hyper = "1.8.1"
tower = "0.5.3"
44 changes: 26 additions & 18 deletions dapr/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::dapr::proto::common::v1::job_failure_policy::Policy;
use crate::dapr::proto::common::v1::JobFailurePolicyConstant;
use crate::dapr::proto::common::v1::job_failure_policy::Policy;
use crate::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1};
use crate::error::Error;
#[cfg(feature = "workflow")]
use crate::workflow;
use async_trait::async_trait;
use futures::StreamExt;
use prost_types::Any;
Expand All @@ -11,11 +13,11 @@ use std::collections::HashMap;
use std::time::Duration;
use tokio::io::AsyncRead;
use tonic::codegen::tokio_stream;
use tonic::{transport::Channel as TonicChannel, Request};
use tonic::{Request, transport::Channel as TonicChannel};
use tonic::{Status, Streaming};

#[derive(Clone)]
pub struct Client<T>(T);
pub struct Client<T>(T, String);

impl<T: DaprInterface> Client<T> {
/// Connect to a Dapr enabled app.
Expand All @@ -28,7 +30,7 @@ impl<T: DaprInterface> Client<T> {
let port: u16 = std::env::var("DAPR_GRPC_PORT")?.parse()?;
let address = format!("{addr}:{port}");

Ok(Client(T::connect(address).await?))
Ok(Client(T::connect(address.clone()).await?, address))
}

/// Connect to the Dapr sidecar with a specific port.
Expand All @@ -48,7 +50,13 @@ impl<T: DaprInterface> Client<T> {

let address = format!("{addr}:{port}");

Ok(Client(T::connect(address).await?))
Ok(Client(T::connect(address.clone()).await?, address))
}

/// Create a workflow client connected to the same Dapr sidecar.
#[cfg(feature = "workflow")]
pub async fn new_workflow_client(&self) -> workflow::Result<workflow::WorkflowClient> {
workflow::WorkflowClient::new_with_address(self.1.clone()).await
}

/// Invoke a method in a Dapr enabled app.
Expand Down Expand Up @@ -667,7 +675,7 @@ pub trait DaprInterface: Sized {
) -> Result<UnsubscribeConfigurationResponse, Error>;

async fn encrypt(&mut self, payload: Vec<EncryptRequest>)
-> Result<Vec<StreamPayload>, Status>;
-> Result<Vec<StreamPayload>, Status>;

async fn decrypt(&mut self, payload: Vec<DecryptRequest>) -> Result<Vec<u8>, Status>;

Expand Down Expand Up @@ -832,10 +840,10 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient<TonicChannel> {
let mut stream = stream.into_inner();
let mut return_data = vec![];
while let Some(resp) = stream.next().await {
if let Ok(resp) = resp {
if let Some(data) = resp.payload {
return_data.push(data)
}
if let Ok(resp) = resp
&& let Some(data) = resp.payload
{
return_data.push(data)
}
}
Ok(return_data)
Expand All @@ -853,10 +861,10 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient<TonicChannel> {
let mut stream = stream.into_inner();
let mut data = vec![];
while let Some(resp) = stream.next().await {
if let Ok(resp) = resp {
if let Some(mut payload) = resp.payload {
data.append(payload.data.as_mut())
}
if let Ok(resp) = resp
&& let Some(mut payload) = resp.payload
{
data.append(payload.data.as_mut())
}
}
Ok(data)
Expand Down Expand Up @@ -1348,10 +1356,10 @@ impl ConversationRequestAlpha2Builder {
}

pub use crate::dapr::proto::runtime::v1::{
conversation_message, conversation_tool_calls, ConversationMessage, ConversationMessageContent,
ConversationMessageOfAssistant, ConversationMessageOfDeveloper, ConversationMessageOfSystem,
ConversationMessageOfTool, ConversationMessageOfUser, ConversationToolCalls,
ConversationToolCallsOfFunction, ConversationTools,
ConversationMessage, ConversationMessageContent, ConversationMessageOfAssistant,
ConversationMessageOfDeveloper, ConversationMessageOfSystem, ConversationMessageOfTool,
ConversationMessageOfUser, ConversationToolCalls, ConversationToolCallsOfFunction,
ConversationTools, conversation_message, conversation_tool_calls,
};

impl From<ConversationMessageOfUser> for ConversationMessage {
Expand Down
20 changes: 10 additions & 10 deletions dapr/src/dapr/dapr.proto.common.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// `POST <http://localhost:3500/v1.0/invoke/<app_id>/method/<method>?query1=value1&query2=value2`>
///
/// Dapr runtime will parse POST as a verb and extract querystring to quersytring map.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct HttpExtension {
/// Required. HTTP verb.
#[prost(enumeration = "http_extension::Verb", tag = "1")]
Expand Down Expand Up @@ -84,7 +84,7 @@ pub mod http_extension {
/// InvokeRequest is the message to invoke a method with the data.
/// This message is used in InvokeService of Dapr gRPC Service and OnInvoke
/// of AppCallback gRPC service.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InvokeRequest {
/// Required. method is a method name which will be invoked by caller.
#[prost(string, tag = "1")]
Expand All @@ -110,7 +110,7 @@ pub struct InvokeRequest {
/// from app callback.
/// This message is used in InvokeService of Dapr gRPC Service and OnInvoke
/// of AppCallback gRPC service.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InvokeResponse {
/// Required in unary RPCs. The content body of InvokeService response.
#[prost(message, optional, tag = "1")]
Expand All @@ -121,7 +121,7 @@ pub struct InvokeResponse {
}
/// Chunk of data sent in a streaming request or response.
/// This is used in requests including InternalInvokeRequestStream.
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StreamPayload {
/// Data sent in the chunk.
/// The amount of data included in each chunk is up to the discretion of the sender, and can be empty.
Expand Down Expand Up @@ -157,14 +157,14 @@ pub struct StateItem {
pub options: ::core::option::Option<StateOptions>,
}
/// Etag represents a state item version
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Etag {
/// value sets the etag value
#[prost(string, tag = "1")]
pub value: ::prost::alloc::string::String,
}
/// StateOptions configures concurrency and consistency for state operations
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct StateOptions {
#[prost(enumeration = "state_options::StateConcurrency", tag = "1")]
pub concurrency: i32,
Expand Down Expand Up @@ -271,7 +271,7 @@ pub struct ConfigurationItem {
>,
}
/// JobFailurePolicy defines the policy to apply when a job fails to trigger.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct JobFailurePolicy {
/// policy is the policy to apply when a job fails to trigger.
#[prost(oneof = "job_failure_policy::Policy", tags = "1, 2")]
Expand All @@ -280,7 +280,7 @@ pub struct JobFailurePolicy {
/// Nested message and enum types in `JobFailurePolicy`.
pub mod job_failure_policy {
/// policy is the policy to apply when a job fails to trigger.
#[derive(Clone, Copy, PartialEq, ::prost::Oneof)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Oneof)]
pub enum Policy {
#[prost(message, tag = "1")]
Drop(super::JobFailurePolicyDrop),
Expand All @@ -289,10 +289,10 @@ pub mod job_failure_policy {
}
}
/// JobFailurePolicyDrop is a policy which drops the job tick when the job fails to trigger.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct JobFailurePolicyDrop {}
/// JobFailurePolicyConstant is a policy which retries the job at a consistent interval when the job fails to trigger.
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct JobFailurePolicyConstant {
/// interval is the constant delay to wait before retrying the job.
#[prost(message, optional, tag = "1")]
Expand Down
Loading
Loading