Rust Integration Services
A modern, fast, and lightweight integration library written in Rust, designed for memory safety and stability. It simplifies the development of scalable integrations for receiving and sending data, with built-in support for common protocols.
Installation
Add rust-integration-services to your project Cargo.toml with all or select features.
All features
[]
= { = "0.2.1" }
Select features
[]
= { = "0.2.1", = false, = ["file", "schedule", "sftp", "http"] }
Features
File
FileReceiver
Poll the directory ./io/in/
and receive a callback with the path of a matching file using regular expression.
let result = new
.filter
.receive
.await;
FileSender
Move a file from one directory to another.
let result = new
.send_move
.await;
Copy the contents from a file to another.
let result = new
.send_copy
.await;
Write a string to a file, appending the text.
let result = new
.send_string
.await;
Schedule
ScheduleReceiver
Run a task once every hour and receive an event when it triggers.
let result = new
.interval
.on_event
.receive
.await;
Run a task once every day at 03:00 UTC and receive an event when it triggers.
let result = new
.start_time
.interval
.on_event
.receive
.await;
HTTP
The http module is built on top of the fast and reliable hyper
HTTP library.
It supports both HTTP/1.1 and HTTP/2 protocols, enabling modern, high-performance HTTP communication with automatic protocol negotiation via ALPN (Application-Layer Protocol Negotiation).
HttpReceiver
Run a HTTP receiver listening on 127.0.0.1:8080
that handles GET
and POST
requests on the root path.
.route
.route
.receive
.await;
new
Run a HTTP receiver with TLS listening on 127.0.0.1:8080
that handles GET
and POST
requests on the root path and log events.
.tls
.route
.route
.on_event
.receive
.await;
new
HttpSender
HttpSender will automatically use a secure TLS connection if the scheme is https
and ALPN is used to determine whether to use HTTP/2 or HTTP/1.1 for the request.
Send a GET request to http://127.0.0.1:8080
.
let response = new
.send
.await
.unwrap;
Send a GET request using TLS to https://127.0.0.1:8080
.
let response = new
.send
.await
.unwrap;
Send a GET request using TLS and custom Root CA to https://127.0.0.1:8080
.
let root_ca_path = home_dir.unwrap.join;
let response = new
.root_ca
.send
.await
.unwrap;
SFTP
Using SFTP requires openssl
to be installed on the system.
Make sure you also have the development packages of openssl installed.
For example, libssl-dev
on Ubuntu or openssl-devel
on Fedora.
SftpReceiver
Download all files from 127.0.0.1:22
user remote directory upload
and delete files after successful download.
Using on_event
callback to print on download start and success.
That way files can be processed asyncronously without blocking other downloads.
let result = new
.auth_password
.remote_dir
.delete_after
.on_event
.receive_files_to_path
.await;
By setting a custom regex to the receiver, the sftp receiver will only download files matching this regex.
For examplem this will only download files starting with "ABC_".
.regex
SftpSender
Send a file to 127.0.0.1:22
user remote path upload
keeping the same file name.
A private key with a passphrase is used as authentication in this example.
let result = new
.private_key
.remote_path
.send_file
.await;
Send a string as a file to 127.0.0.1:22
user remote path upload
with a new file name.
A basic password is used as authentication in this example.
let result = new
.password
.remote_path
.file_name
.send_string
.await;