Go Server Rust SDK
A Rust implementation of the Go Server SDK for distributed task processing.
Features
- Scheduler Client: Execute tasks on remote workers with support for synchronous and asynchronous execution
- Worker: Create distributed task workers that can handle method calls
- Encryption: Built-in AES-GCM encryption support for secure task execution
- Retry Logic: Automatic retry mechanisms for improved reliability
- WebSocket Support: Real-time communication between workers and scheduler
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
= "1.0"
Quick Start
Client Usage
use call;
use json;
async
Worker Usage
use ;
use ;
async
Scheduler Client Usage
use Client;
use json;
async
API Reference
Scheduler Client
The Client struct provides methods for executing tasks on the scheduler:
execute(method, params)- Execute a task asynchronouslyexecute_sync(method, params)- Execute a task synchronously with pollingexecute_encrypted(method, params, key)- Execute an encrypted task asynchronouslyexecute_sync_encrypted(method, params, key)- Execute an encrypted task synchronouslyget_result(task_id)- Get the result of a taskget_result_encrypted(task_id, key)- Get the encrypted result of a task
Retry Client
The RetryClient wraps the base client with automatic retry functionality:
execute_with_retry(method, params)- Execute with retry logicexecute_sync_with_retry(method, params)- Synchronous execution with retryexecute_encrypted_with_retry(method, params, key)- Encrypted execution with retryexecute_sync_encrypted_with_retry(method, params, key)- Encrypted synchronous execution with retry
Worker
The Worker struct allows you to create distributed task workers:
new(config)- Create a new workerregister_method(name, handler, docs)- Register a method handlerstart()- Start the worker (blocks until stopped)stop()- Stop the worker
Helper Functions
call(scheduler_url, method, params)- Simple function to call a remote methodcall_encrypted(scheduler_url, method, params, key)- Simple function to call an encrypted remote method
Examples
See the examples/ directory for complete examples:
client.rs- Simple client exampleworker.rs- Worker with multiple methodsscheduler.rs- Advanced scheduler client usage
Error Handling
The SDK uses a comprehensive error system with the SdkError enum that covers:
- HTTP errors
- WebSocket errors
- JSON serialization/deserialization errors
- Cryptographic errors
- Task execution errors
- Connection errors
- Timeout errors
Encryption
The SDK supports AES-GCM encryption for secure task execution. When using encrypted methods, both the task parameters and results are encrypted using the provided key.
Compatibility
This Rust SDK is fully compatible with the original Go SDK and can interoperate with Go-based workers and clients.
License
MIT License - see LICENSE file for details.