| Crates.io | camunda_connector_rs |
| lib.rs | camunda_connector_rs |
| version | 0.3.0 |
| created_at | 2025-08-07 09:33:15.50372+00 |
| updated_at | 2025-08-08 13:11:04.447512+00 |
| description | A procedural macro for generating Camunda connectors with Axum routers |
| homepage | https://github.com/mathias-vandaele/camunda_connector_rs |
| repository | https://github.com/mathias-vandaele/camunda_connector_rs |
| max_upload_size | |
| id | 1784968 |
| size | 16,643 |
A Rust procedural macro library for building Camunda connectors with automatic request dispatching and type-safe handlers.
Add the following dependencies to your Cargo.toml:
[dependencies]
camunda_connector_rs = "0.0.3"
axum = "0.8.4"
inventory = "0.3.20"
serde = { version = "1.0.219", features = ["derive"] }
tokio = { version = "1.47.1" , features = ["full"]}
serde_json = "1.0.142"
use camunda_connector_rs::{camunda_connector, connector_main};
use serde::{Deserialize, Serialize};
// Start the server on port 8080
connector_main!(port = 8080);
// Define your input/output types
#[derive(Deserialize, Debug)]
pub struct MathInput {
pub a: u64,
pub b: u64,
}
#[derive(Serialize, Debug)]
pub struct MathOutput {
pub result: u64,
}
// Define connector handlers
#[camunda_connector(name = "math", operation = "add")]
pub async fn add(id: u64, params: MathInput) -> Result<MathOutput, String> {
println!("[add] id: {}, params: {:?}", id, params);
Ok(MathOutput {
result: params.a + params.b,
})
}
#[camunda_connector(name = "math", operation = "subtract")]
pub async fn subtract(id: u64, params: MathInput) -> Result<MathOutput, String> {
println!("[subtract] id: {}, params: {:?}", id, params);
Ok(MathOutput {
result: params.a - params.b,
})
}
Use the #[camunda_connector] attribute to define connector handlers:
#[camunda_connector(name = "connector_name", operation = "operation_name")]
pub async fn handler_function(id: u64, params: InputType) -> Result<OutputType, String> {
// Your connector logic here
}
Requirements:
asyncid: u64 and params: T where T implements DeserializeResult<T, String> where T implements SerializeUse the connector_main! macro to generate the main function and start the HTTP server:
connector_main!(port = 8080);
This generates:
main() function with Tokio runtimeConnectors expect HTTP POST requests to /csp/{connector_name} with JSON payload:
{
"id": 12345,
"params": {
"operation": "operation_name",
"input": {
// Your connector-specific input data
}
}
}
Successful responses return JSON with your connector's output data. Error responses return appropriate HTTP status codes with error messages.
The #[camunda_connector] attribute generates:
Request/Response Structs: Automatically creates typed structs for deserialization
// Generated for each connector
pub struct ParamsMathAdd { /* ... */ }
pub struct RequestMathAdd { /* ... */ }
Dispatcher Function: Creates a type-safe dispatcher that handles JSON parsing and calls your handler
fn exec_raw_math_add(bytes: axum::body::Bytes) -> DispatcherFuture { /* ... */ }
Registration: Uses the inventory crate to register connectors at compile time
/csp/{connector_name}operation field to determine routingThe framework provides comprehensive error handling:
You can define multiple operations for the same connector:
#[camunda_connector(name = "calculator", operation = "add")]
pub async fn add(id: u64, params: MathInput) -> Result<MathOutput, String> { /* ... */ }
#[camunda_connector(name = "calculator", operation = "multiply")]
pub async fn multiply(id: u64, params: MathInput) -> Result<MathOutput, String> { /* ... */ }
Each connector operation can have its own input and output types:
#[derive(Deserialize)]
pub struct StringInput {
pub text: String,
}
#[derive(Serialize)]
pub struct StringOutput {
pub length: usize,
pub uppercase: String,
}
#[camunda_connector(name = "string_utils", operation = "process")]
pub async fn process_string(id: u64, params: StringInput) -> Result<StringOutput, String> {
Ok(StringOutput {
length: params.text.len(),
uppercase: params.text.to_uppercase(),
})
}
This library uses the following key dependencies:
[Add your license information here]
[Add contribution guidelines here]