Skip to content

Commit 7932f88

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

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,101 @@
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+
//! let cfg = SqsConfig {
35+
//! queue_dsn: "http://localhost:9234/queue/queue_name".to_owned(),
36+
//! override_endpoint: true,
37+
//! };
38+
//!
39+
//! // Either both producer and consumer
40+
//! let (p, mut c) = SqsQueueBackend::builder(cfg.clone()).build_pair().await?;
41+
//!
42+
//! // Or one half
43+
//! let p = SqsQueueBackend::builder(cfg.clone()).build_producer().await?;
44+
//! let mut c = SqsQueueBackend::builder(cfg).build_consumer().await?;
45+
//!
46+
//! (p, c)
47+
//! ```
48+
//!
49+
//! 4. Send and receive information:
50+
//!
51+
//! ```compile_fail
52+
//! p.send_serde_json(&ExampleType::default()).await?;
53+
//!
54+
//! let delivery = c.receive().await?;
55+
//! let payload = delivery.payload_serde_json::<ExampleType>().await?;
56+
//! delivery.ack().await?;
57+
//! ```
58+
//! ## `DynProducer`s and `DynConsumer`s
59+
//!
60+
//! Dynamic-dispatch can be used easily for when you're not sure which backend is to be used at
61+
//! compile-time.
62+
//!
63+
//! Making a `DynProducer` or `DynConsumer` is as simple as adding one line to the builder:
64+
//!
65+
//! ```compile_fail
66+
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
67+
//! .make_dynamic()
68+
//! .build_pair()
69+
//! .await?;
70+
//! ```
71+
//!
72+
//! ## Encoders/Decoders
73+
//!
74+
//! The [`encoding::CustomEncoder`]s and [`decoding::CustomDecoder`]s given to the builder upon
75+
//! producer/consumer creation will be used to convert from/to the queue's native representation
76+
//! into/from a given type. This helps enforce a separation of responsibilities where only the
77+
//! application setting up a concrete queue instance should ever have to think about the internal
78+
//! data-representation of items within the queue while abstract uses of queues should be able to
79+
//! work with simple Rust types.
80+
//!
81+
//! Any function or closure with the right signature may be used as an encoder or decoder.
82+
//!
83+
//! ```compile_fail
84+
//! #[derive(Debug, PartialEq)]
85+
//! struct ExampleType {
86+
//! field: u8,
87+
//! }
88+
//!
89+
//! let (p, mut c) = RabbitMqBackend::builder(cfg)
90+
//! .with_encoder(|et: &ExampleType| -> Result<Vec<u8>, QueueError> {
91+
//! Ok(vec![et.field])
92+
//! })
93+
//! .with_decoder(|v: &Vec<u8>| -> Result<ExampleType, QueueError> {
94+
//! Ok(ExampleType {
95+
//! field: *v.first().unwrap_or(&0),
96+
//! })
97+
//! })
98+
//! ```
199
use std::fmt::Debug;
2100

3101
use thiserror::Error;

0 commit comments

Comments
 (0)