Skip to main content

Queues

Derive Macro Queues 

Source
#[derive(Queues)]
{
    // Attributes available to this derive:
    #[queues]
    #[queue]
}
Expand description

Implement queuey_core::QueueSet for a fieldless enum.

The enum must also derive the trait’s supertraits; the macro deliberately does not add them for you:

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Queues)]

§Attributes

Container attribute #[queues(...)], optional:

#[queues(
    prefix = "myapp",                  // queue names become "myapp.<name>"
    crate = "queuey",         // path to the core crate re-export
)]

Variant attribute #[queue(...)], optional on every variant:

#[queue(
    name = "img",                      // default: snake_case of the variant
    prefetch = 10,                     // u16
    durable = true,                    // bool
    message_ttl = "30s",               // duration literal
    max_priority = 10,                 // u8 in 0..=255; 0 disables priorities
    retry(max_attempts = 3, backoff = "exponential", base = "1s", factor = 2.0,
          max = "5m", jitter = true),
)]

max_priority is the number of AMQP priority levels the queue is declared with (x-max-priority). Omitted, the QueueConfig default applies; max_priority = 0 turns priorities off, so the queue carries no x-max-priority argument at all. Changing this value on a queue that already exists is refused by the broker: RabbitMQ answers a redeclare with different arguments with PRECONDITION_FAILED, so an existing deployment must delete the queue first.

§Example

use queuey_core::{QueueSet, Backoff};
use queuey_macros::Queues;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Queues)]
#[queues(prefix = "myapp")]
enum AppQueues {
    #[queue(prefetch = 10, max_priority = 5)]
    Emails,
    #[queue(name = "img", message_ttl = "30s", max_priority = 0, retry(max_attempts = 5))]
    ImageResize,
}

assert_eq!(AppQueues::Emails.name(), "myapp.emails");
assert_eq!(AppQueues::ImageResize.name(), "myapp.img");
assert_eq!(AppQueues::Emails.config().prefetch, 10);
assert_eq!(AppQueues::Emails.config().max_priority, Some(5));
assert_eq!(AppQueues::ImageResize.config().max_priority, None);
assert_eq!(AppQueues::from_name("myapp.img"), Some(AppQueues::ImageResize));

§Errors

Compile errors, spanned at the offending token, are produced for: a non-enum item, a generic enum, an enum without variants, a variant with fields, duplicate resolved queue names, unknown or duplicated attribute keys, a literal of the wrong type, an empty prefix/name/resolved queue name, a prefetch outside 1..=65535 (0 means unlimited in AMQP, so omit the key instead), a max_priority outside 0..=255, a max_attempts outside 1..=u32::MAX, a malformed or zero duration, an unknown backoff kind, base greater than max, delay outside of backoff = "fixed", and base/factor/max/jitter outside of backoff = "exponential".