queue-runtime 0.2.0

Multi-provider queue runtime for Queue-Keeper
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# Queue Naming Strategy


This document defines the standardized naming conventions and patterns for queues, dead letter queues, and related resources across different deployment environments.

## Overview


Consistent queue naming is critical for:

- Clear identification of queue purpose and ownership
- Environment isolation and resource management
- Automated deployment and configuration
- Monitoring and observability
- Troubleshooting and operational support

## Naming Conventions


### Base Queue Naming Pattern


```
[prefix-]environment-botname[-suffix]
```

**Components:**

- **prefix** (optional): Organization or project prefix
- **environment**: Deployment environment (dev, staging, prod)
- **botname**: Bot service name in kebab-case
- **suffix** (optional): Special purpose suffix (dlq, retry, etc.)

### Standard Queue Names


#### Production Environment


```
prod-task-tactician
prod-merge-warden
prod-spec-sentinel
prod-security-scanner
prod-dependency-updater
```

#### Staging Environment


```
staging-task-tactician
staging-merge-warden
staging-spec-sentinel
```

#### Development Environment


```
dev-task-tactician
dev-merge-warden
dev-spec-sentinel
```

#### With Organization Prefix


```
offaxis-prod-task-tactician
offaxis-staging-merge-warden
offaxis-dev-spec-sentinel
```

### Dead Letter Queue Naming


Dead letter queues follow the base queue name with `-dlq` suffix:

```
prod-task-tactician-dlq
prod-merge-warden-dlq
staging-spec-sentinel-dlq
```

### Retry Queue Naming


Retry queues for delayed processing use `-retry` suffix:

```
prod-task-tactician-retry
prod-merge-warden-retry
```

### Session-Based Queue Naming


For providers that support multiple queues per bot (like SQS), session-based queues include the session strategy:

```
prod-task-tactician-entity
prod-task-tactician-repository
prod-merge-warden-fifo
```

## Naming Rules and Constraints


### General Rules


1. **Lowercase Only**: All queue names must be lowercase
2. **Kebab Case**: Use hyphens to separate words
3. **ASCII Characters**: Only letters, numbers, and hyphens
4. **Length Limits**: Maximum 50 characters total
5. **Unique Names**: No duplicate names within an environment

### Provider-Specific Constraints


#### Azure Service Bus


- Maximum length: 50 characters
- Valid characters: letters, numbers, hyphens
- Cannot start or end with hyphen
- Cannot have consecutive hyphens

#### AWS SQS


- Maximum length: 80 characters
- Valid characters: letters, numbers, hyphens, underscores
- FIFO queues must end with `.fifo`
- No periods except for FIFO suffix

#### FIFO Queue Names (AWS SQS)


```
prod-task-tactician.fifo
prod-merge-warden.fifo
staging-spec-sentinel.fifo
```

## Queue Naming Implementation


### QueueNaming Struct


```rust
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct QueueNaming {
    /// Optional organization or project prefix
    pub prefix: Option<String>,

    /// Deployment environment
    pub environment: String,

    /// Provider-specific naming rules
    pub provider: QueueProvider,

    /// Maximum queue name length
    pub max_length: usize,
}

impl QueueNaming {
    pub fn new(environment: String, provider: QueueProvider) -> Self {
        let max_length = match provider {
            QueueProvider::AzureServiceBus => 50,
            QueueProvider::AwsSqs => 80,
            QueueProvider::InMemory => 100,
        };

        Self {
            prefix: None,
            environment,
            provider,
            max_length,
        }
    }

    /// Generate main queue name for a bot
    pub fn queue_name(&self, bot_name: &str) -> Result<String, NamingError> {
        let name = match &self.prefix {
            Some(prefix) => format!("{}-{}-{}", prefix, self.environment, bot_name),
            None => format!("{}-{}", self.environment, bot_name),
        };

        self.validate_name(&name)?;
        Ok(name)
    }

    /// Generate dead letter queue name
    pub fn dlq_name(&self, bot_name: &str) -> Result<String, NamingError> {
        let base_name = self.queue_name(bot_name)?;
        let dlq_name = format!("{}-dlq", base_name);

        self.validate_name(&dlq_name)?;
        Ok(dlq_name)
    }

    /// Generate retry queue name
    pub fn retry_name(&self, bot_name: &str) -> Result<String, NamingError> {
        let base_name = self.queue_name(bot_name)?;
        let retry_name = format!("{}-retry", base_name);

        self.validate_name(&retry_name)?;
        Ok(retry_name)
    }

    /// Generate session-specific queue name
    pub fn session_queue_name(&self, bot_name: &str, session_strategy: &str) -> Result<String, NamingError> {
        let base_name = self.queue_name(bot_name)?;
        let session_name = format!("{}-{}", base_name, session_strategy);

        self.validate_name(&session_name)?;
        Ok(session_name)
    }

    /// Generate FIFO queue name for AWS SQS
    pub fn fifo_name(&self, bot_name: &str) -> Result<String, NamingError> {
        if !matches!(self.provider, QueueProvider::AwsSqs) {
            return Err(NamingError::UnsupportedProvider {
                provider: format!("{:?}", self.provider),
                feature: "FIFO queues".to_string(),
            });
        }

        let base_name = self.queue_name(bot_name)?;
        let fifo_name = format!("{}.fifo", base_name);

        self.validate_name(&fifo_name)?;
        Ok(fifo_name)
    }

    /// Validate queue name against provider constraints
    pub fn validate_name(&self, name: &str) -> Result<(), NamingError> {
        // Check length
        if name.len() > self.max_length {
            return Err(NamingError::TooLong {
                name: name.to_string(),
                length: name.len(),
                max_length: self.max_length,
            });
        }

        // Check empty
        if name.is_empty() {
            return Err(NamingError::Empty);
        }

        // Provider-specific validation
        match self.provider {
            QueueProvider::AzureServiceBus => self.validate_azure_name(name)?,
            QueueProvider::AwsSqs => self.validate_aws_name(name)?,
            QueueProvider::InMemory => self.validate_memory_name(name)?,
        }

        Ok(())
    }

    fn validate_azure_name(&self, name: &str) -> Result<(), NamingError> {
        // Azure Service Bus naming rules
        if name.starts_with('-') || name.ends_with('-') {
            return Err(NamingError::InvalidFormat {
                name: name.to_string(),
                reason: "Cannot start or end with hyphen".to_string(),
            });
        }

        if name.contains("--") {
            return Err(NamingError::InvalidFormat {
                name: name.to_string(),
                reason: "Cannot contain consecutive hyphens".to_string(),
            });
        }

        for char in name.chars() {
            if !char.is_ascii_alphanumeric() && char != '-' {
                return Err(NamingError::InvalidCharacter {
                    name: name.to_string(),
                    character: char,
                });
            }
        }

        Ok(())
    }

    fn validate_aws_name(&self, name: &str) -> Result<(), NamingError> {
        // AWS SQS naming rules
        for char in name.chars() {
            if !char.is_ascii_alphanumeric() && char != '-' && char != '_' && char != '.' {
                return Err(NamingError::InvalidCharacter {
                    name: name.to_string(),
                    character: char,
                });
            }
        }

        // FIFO queues must end with .fifo
        if name.contains(".fifo") && !name.ends_with(".fifo") {
            return Err(NamingError::InvalidFormat {
                name: name.to_string(),
                reason: "FIFO suffix '.fifo' must be at the end".to_string(),
            });
        }

        Ok(())
    }

    fn validate_memory_name(&self, name: &str) -> Result<(), NamingError> {
        // In-memory queues have relaxed rules
        for char in name.chars() {
            if !char.is_ascii_alphanumeric() && char != '-' && char != '_' {
                return Err(NamingError::InvalidCharacter {
                    name: name.to_string(),
                    character: char,
                });
            }
        }

        Ok(())
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]

pub enum QueueProvider {
    AzureServiceBus,
    AwsSqs,
    InMemory,
}
```

### Bot Queue Registry


```rust
use std::collections::HashMap;

/// Registry of all bot queue configurations
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct BotQueueRegistry {
    pub naming: QueueNaming,
    pub bots: HashMap<String, BotQueueConfig>,
}

impl BotQueueRegistry {
    pub fn new(naming: QueueNaming) -> Self {
        Self {
            naming,
            bots: HashMap::new(),
        }
    }

    /// Register a bot with its queue configuration
    pub fn register_bot(&mut self, bot_name: String, config: BotQueueConfig) -> Result<(), NamingError> {
        // Validate the bot name
        let queue_name = self.naming.queue_name(&bot_name)?;

        self.bots.insert(bot_name, config);
        Ok(())
    }

    /// Get all queue names for a bot
    pub fn get_bot_queues(&self, bot_name: &str) -> Result<BotQueues, NamingError> {
        let config = self.bots.get(bot_name)
            .ok_or_else(|| NamingError::BotNotFound { bot_name: bot_name.to_string() })?;

        let main_queue = if config.enable_fifo && matches!(self.naming.provider, QueueProvider::AwsSqs) {
            self.naming.fifo_name(bot_name)?
        } else {
            self.naming.queue_name(bot_name)?
        };

        let dlq = if config.enable_dead_letter {
            Some(self.naming.dlq_name(bot_name)?)
        } else {
            None
        };

        let retry_queue = if config.enable_retry_queue {
            Some(self.naming.retry_name(bot_name)?)
        } else {
            None
        };

        Ok(BotQueues {
            main_queue,
            dead_letter_queue: dlq,
            retry_queue,
            session_queues: Vec::new(), // TODO: Add session queue support
        })
    }

    /// Get all queues in the registry
    pub fn all_queues(&self) -> Result<Vec<String>, NamingError> {
        let mut queues = Vec::new();

        for bot_name in self.bots.keys() {
            let bot_queues = self.get_bot_queues(bot_name)?;
            queues.push(bot_queues.main_queue);

            if let Some(dlq) = bot_queues.dead_letter_queue {
                queues.push(dlq);
            }

            if let Some(retry) = bot_queues.retry_queue {
                queues.push(retry);
            }
        }

        Ok(queues)
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct BotQueueConfig {
    pub enable_sessions: bool,
    pub enable_dead_letter: bool,
    pub enable_retry_queue: bool,
    pub enable_fifo: bool,
    pub max_delivery_count: u32,
    pub message_ttl: Duration,
}

impl Default for BotQueueConfig {
    fn default() -> Self {
        Self {
            enable_sessions: true,
            enable_dead_letter: true,
            enable_retry_queue: false,
            enable_fifo: false,
            max_delivery_count: 3,
            message_ttl: Duration::from_hours(24),
        }
    }
}

#[derive(Debug, Clone)]

pub struct BotQueues {
    pub main_queue: String,
    pub dead_letter_queue: Option<String>,
    pub retry_queue: Option<String>,
    pub session_queues: Vec<String>,
}
```

## Environment-Specific Configurations


### Development Environment


```rust
impl QueueNaming {
    pub fn development() -> Self {
        Self::new("dev".to_string(), QueueProvider::InMemory)
    }

    pub fn development_azure() -> Self {
        Self::new("dev".to_string(), QueueProvider::AzureServiceBus)
    }
}

// Development queue names
// dev-task-tactician
// dev-merge-warden
// dev-spec-sentinel
```

### Staging Environment


```rust
impl QueueNaming {
    pub fn staging() -> Self {
        Self::new("staging".to_string(), QueueProvider::AzureServiceBus)
    }

    pub fn staging_aws() -> Self {
        Self::new("staging".to_string(), QueueProvider::AwsSqs)
    }
}

// Staging queue names
// staging-task-tactician
// staging-merge-warden
// staging-spec-sentinel
```

### Production Environment


```rust
impl QueueNaming {
    pub fn production() -> Self {
        Self::new("prod".to_string(), QueueProvider::AzureServiceBus)
    }

    pub fn production_with_prefix(prefix: String) -> Self {
        let mut naming = Self::production();
        naming.prefix = Some(prefix);
        naming
    }
}

// Production queue names
// prod-task-tactician
// prod-merge-warden
// prod-spec-sentinel

// With prefix
// offaxis-prod-task-tactician
// offaxis-prod-merge-warden
// offaxis-prod-spec-sentinel
```

## Standard Bot Names


### Predefined Bot Identifiers


```rust
pub const TASK_TACTICIAN: &str = "task-tactician";
pub const MERGE_WARDEN: &str = "merge-warden";
pub const SPEC_SENTINEL: &str = "spec-sentinel";
pub const SECURITY_SCANNER: &str = "security-scanner";
pub const DEPENDENCY_UPDATER: &str = "dependency-updater";
pub const BUILD_ORCHESTRATOR: &str = "build-orchestrator";
pub const RELEASE_MANAGER: &str = "release-manager";
pub const DOCS_GENERATOR: &str = "docs-generator";

/// All standard bot names
pub const STANDARD_BOTS: &[&str] = &[
    TASK_TACTICIAN,
    MERGE_WARDEN,
    SPEC_SENTINEL,
    SECURITY_SCANNER,
    DEPENDENCY_UPDATER,
    BUILD_ORCHESTRATOR,
    RELEASE_MANAGER,
    DOCS_GENERATOR,
];
```

### Bot Name Validation


```rust
impl QueueNaming {
    pub fn validate_bot_name(bot_name: &str) -> Result<(), NamingError> {
        if bot_name.is_empty() {
            return Err(NamingError::Empty);
        }

        if bot_name.len() > 30 {
            return Err(NamingError::TooLong {
                name: bot_name.to_string(),
                length: bot_name.len(),
                max_length: 30,
            });
        }

        // Must be kebab-case
        if !bot_name.chars().all(|c| c.is_ascii_lowercase() || c == '-') {
            return Err(NamingError::InvalidFormat {
                name: bot_name.to_string(),
                reason: "Bot name must be lowercase kebab-case".to_string(),
            });
        }

        // Cannot start or end with hyphen
        if bot_name.starts_with('-') || bot_name.ends_with('-') {
            return Err(NamingError::InvalidFormat {
                name: bot_name.to_string(),
                reason: "Bot name cannot start or end with hyphen".to_string(),
            });
        }

        // Cannot have consecutive hyphens
        if bot_name.contains("--") {
            return Err(NamingError::InvalidFormat {
                name: bot_name.to_string(),
                reason: "Bot name cannot contain consecutive hyphens".to_string(),
            });
        }

        Ok(())
    }
}
```

## Error Types


```rust
#[derive(Debug, thiserror::Error)]

pub enum NamingError {
    #[error("Queue name is empty")]
    Empty,

    #[error("Queue name too long: '{name}' ({length} chars, max: {max_length})")]
    TooLong { name: String, length: usize, max_length: usize },

    #[error("Invalid character '{character}' in queue name: '{name}'")]
    InvalidCharacter { name: String, character: char },

    #[error("Invalid queue name format: '{name}' - {reason}")]
    InvalidFormat { name: String, reason: String },

    #[error("Bot not found: {bot_name}")]
    BotNotFound { bot_name: String },

    #[error("Provider '{provider}' does not support {feature}")]
    UnsupportedProvider { provider: String, feature: String },

    #[error("Duplicate queue name: {name}")]
    DuplicateName { name: String },
}
```

## Configuration Examples


### Complete Registry Setup


```rust
use queue_runtime::naming::*;
use std::time::Duration;

fn setup_production_registry() -> Result<BotQueueRegistry, NamingError> {
    let naming = QueueNaming::production_with_prefix("offaxis".to_string());
    let mut registry = BotQueueRegistry::new(naming);

    // Task Tactician - handles task automation
    registry.register_bot(TASK_TACTICIAN.to_string(), BotQueueConfig {
        enable_sessions: true,
        enable_dead_letter: true,
        enable_retry_queue: false,
        enable_fifo: false,
        max_delivery_count: 3,
        message_ttl: Duration::from_hours(24),
    })?;

    // Merge Warden - handles PR automation
    registry.register_bot(MERGE_WARDEN.to_string(), BotQueueConfig {
        enable_sessions: true,
        enable_dead_letter: true,
        enable_retry_queue: true,
        enable_fifo: false,
        max_delivery_count: 5,
        message_ttl: Duration::from_hours(48),
    })?;

    // Spec Sentinel - handles specification validation
    registry.register_bot(SPEC_SENTINEL.to_string(), BotQueueConfig::default())?;

    Ok(registry)
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let registry = setup_production_registry()?;

    // Get queue names for Task Tactician
    let task_queues = registry.get_bot_queues(TASK_TACTICIAN)?;
    println!("Task Tactician queues:");
    println!("  Main: {}", task_queues.main_queue);
    if let Some(dlq) = &task_queues.dead_letter_queue {
        println!("  DLQ: {}", dlq);
    }

    // List all queues
    let all_queues = registry.all_queues()?;
    println!("\nAll queues:");
    for queue in all_queues {
        println!("  {}", queue);
    }

    Ok(())
}
```

### Environment-Specific Examples


```yaml
# Development configuration

development:
  provider: InMemory
  environment: dev
  bots:
    - name: task-tactician
      sessions: true
      dead_letter: false
      retry: false
    - name: merge-warden
      sessions: true
      dead_letter: false
      retry: false

# Staging configuration

staging:
  provider: AzureServiceBus
  environment: staging
  prefix: offaxis
  bots:
    - name: task-tactician
      sessions: true
      dead_letter: true
      retry: false
    - name: merge-warden
      sessions: true
      dead_letter: true
      retry: true

# Production configuration

production:
  provider: AzureServiceBus
  environment: prod
  prefix: offaxis
  bots:
    - name: task-tactician
      sessions: true
      dead_letter: true
      retry: true
      max_delivery_count: 3
    - name: merge-warden
      sessions: true
      dead_letter: true
      retry: true
      max_delivery_count: 5
    - name: spec-sentinel
      sessions: true
      dead_letter: true
      retry: false
      max_delivery_count: 2
```

## Best Practices


1. **Environment Isolation**: Always include environment in queue names
2. **Consistent Prefixes**: Use organization prefixes for multi-tenant scenarios
3. **Clear Bot Names**: Use descriptive, kebab-case bot names
4. **DLQ Naming**: Always append `-dlq` for dead letter queues
5. **Length Management**: Keep names under provider limits
6. **Character Safety**: Use only ASCII alphanumeric and hyphens
7. **Validation**: Always validate names before creating queues
8. **Documentation**: Maintain registry of all queue names and purposes