Outbox Pattern Processor
Library to make easier to dispatch your outbox-pattern data from database to SQS, SNS and/or HTTP(S) gateways.
- Simple: Your application only need to write into
outbox
table. - Scalable: It's possible to run more than one instance to increase performance without lose order.
Pre-requisites
How to use
To use as docker image, see more here
[!TIP] All events, HTTP, SNS or SQS, always include the header or message-attribute called
x-idempotent-key
. It can be used to avoid consume duplicated events.
Persisting outbox event data
Rust
HTTP
let partition_key = now_v7; // or your own domain unique uuid
let url = "https://your-detination-url.com/some-path";
let headers = None;
let payload = json!
SNS
let partition_key = now_v7; // or your own domain unique uuid
let topic_arn = "arn:aws:sns:us-east-1:000000000000:topic";
let headers = None;
let payload = "any data"; // can also be a JSON stringified
let outbox = sns;
SQS
let partition_key = now_v7; // or your own domain unique uuid
let queue_url = "http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/queue";
let headers = None;
let payload = "any data"; // can also be a JSON stringified
let outbox = sqs;
Any outbox kind with delay
let outbox = http_post_json // or any other, like sqs and sns
.delay;
Persisting
let stored_outbox = insert.await?;
let idempotent_key = stored_outbox.idempotent_key;
Manually
[!NOTE]
More details and examples about columns data in database configuration
insert into outbox
(idempotent_key, partition_key, destinations, headers, payload)
values
($1, $2, $3, $4, $5)
returning *
Initialize
Simple
let custom_resources = new
// each optional with default value
.with_outbox_query_limit
.with_http_timeout_in_millis
.with_max_in_flight_interval_in_seconds
.with_outbox_execution_interval_in_seconds
.with_delete_after_process_successfully
.with_delay_for_failure_attempt_in_seconds
.with_outbox_failure_limit
.with_scheduled_clear_locked_partition
.with_outbox_cleaner_execution_interval_in_seconds;
let _ = new
.init
.await;
Tokio + Axum example
use Environment;
use ;
use Shutdown;
use Routes;
use AppState;
use env;
use SocketAddr;
use TcpListener;
use info;
use SubscriberExt;
use SubscriberInitExt;
use EnvFilter;
use WaitGroup;
async
async
async
License
This project is licensed under the MIT license.