Skip to content

Commit f202145

Browse files
author
Daniel Lyne
committed
Improve documentation for crate
1 parent 73e819a commit f202145

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ While the exact configuration will depend on the backend used, usage is roughly
2424
If you only need some backends, then simply disable the default features, and enable any backends
2525
that you require.
2626

27-
2. Construct anud use your queue.
27+
2. Construct and use your queue.
2828

2929
The exact configuration type used will depend on your backend, but it's as simple as:
3030

@@ -89,7 +89,7 @@ let (p, mut c) = RabbitMqBackend::builder(cfg)
8989
})
9090
.with_decoder(|v: &Vec<u8>| -> Result<ExampleType, QueueError> {
9191
Ok(ExampleType {
92-
field: *v.first().unwrap_or(i&0),
92+
field: *v.first().unwrap_or(&0),
9393
})
9494
})
9595
.build_pair()

omniqueue/src/lib.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,104 @@
1+
//! # Omniqueue
2+
//!
3+
//! Omniqueue is an abstraction layer over various queue backends. As of present it supports:
4+
//!
5+
//! * In-memory queues
6+
//!
7+
//! * RabbitMQ
8+
//!
9+
//! * Redis streams
10+
//!
11+
//! * SQS
12+
//!
13+
//! Omniqueue provides a high-level interface for sending and receiving
14+
//!
15+
//! * Raw byte arrays in the way most compatible with the queue backend
16+
//!
17+
//! * JSON encoded byte arrays for types that implement [`serde::Deserialize`] and
18+
//! [`serde::Serialize`]
19+
//!
20+
//! * Arbitrary types for which an encoder and/or decoder has been defined
21+
//!
22+
//! ## How to Use Omniqueue
23+
//!
24+
//! 1. Start by adding `omniqueue` to your `Cargo.toml`. If you don't need support for all of the
25+
//! backends, disable the default features and enable each required backend individually.
26+
//!
27+
//! 2. Create the configuration for your queue backend. Depending on which backend you use, this
28+
//! could be [`backends::rabbitmq::RabbitMqConfig`], [`backends::redis::RedisConfig`],
29+
//! [`backends::sqs::SqsConfig`], or a simple [`usize`] for memory queues.
30+
//!
31+
//! 3. Create the producer and/or consumer:
32+
//!
33+
//! ```compile_fail
34+
//! use omniqueue::backends::sqs::{SqsConfig, SqsQueueBackend};
35+
//! use
36+
//!
37+
//! let cfg = SqsConfig {
38+
//! queue_dsn: "http://localhost:9234/queue/queue_name".to_owned(),
39+
//! override_endpoint: true,
40+
//! };
41+
//!
42+
//! // Either both producer and consumer
43+
//! let (p, mut c) = SqsQueueBackend::builder(cfg.clone()).build_pair().await?;
44+
//!
45+
//! // Or one half
46+
//! let p = SqsQueueBackend::builder(cfg.clone()).build_producer().await?;
47+
//! let mut c = SqsQueueBackend::builder(cfg).build_consumer().await?;
48+
//!
49+
//! (p, c)
50+
//! ```
51+
//!
52+
//! 4. Send and receive information:
53+
//!
54+
//! ```compile_fail
55+
//! p.send_serde_json(&ExampleType::default()).await?;
56+
//!
57+
//! let delivery = c.receive().await?;
58+
//! let payload = delivery.payload_serde_json::<ExampleType>().await?;
59+
//! delivery.ack().await?;
60+
//! ```
61+
//! ## `DynProducer`s and `DynConsumer`s
62+
//!
63+
//! Dynamic-dispatch can be used easily for when you're not sure which backend is to be used at
64+
//! compile-time.
65+
//!
66+
//! Making a `DynProducer` or `DynConsumer` is as simple as adding one line to the builder:
67+
//!
68+
//! ```compile_fail
69+
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
70+
//! .make_dynamic()
71+
//! .build_pair()
72+
//! .await?;
73+
//! ```
74+
//!
75+
//! ## Encoders/Decoders
76+
//!
77+
//! The [`encoding::CustomEncoder`]s and [`decoding::CustomDecoder`]s given to the builder upon
78+
//! producer/consumer creation will be used to convert from/to the queue's native representation
79+
//! into/from a given type. This helps enforce a separation of responsibilities where only the
80+
//! application setting up a concrete queue instance should ever have to think about the internal
81+
//! data-representation of items within the queue while abstract uses of queues should be able to
82+
//! work with simple Rust types.
83+
//!
84+
//! Any function or closure with the right signature may be used as an encoder or decoder.
85+
//!
86+
//! ```compile_fail
87+
//! #[derive(Debug, PartialEq)]
88+
//! struct ExampleType {
89+
//! field: u8,
90+
//! }
91+
//!
92+
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
93+
//! .with_encoder(|et: &ExampleType| -> Result<Vec<u8>, QueueError> {
94+
//! Ok(vec![et.field])
95+
//! })
96+
//! .with_decoder(|v: &Vec<u8>| -> Result<ExampleType, QueueError> {
97+
//! Ok(ExampleType {
98+
//! field: *v.first().unwrap_or(&0),
99+
//! })
100+
//! })
101+
//! ```
1102
use std::fmt::Debug;
2103

3104
use thiserror::Error;

0 commit comments

Comments
 (0)