║  Publish-Subscribe (PUB/SUB) Messaging Pattern              ║
╚═══════════════════════════════════════════════════════════════╝

[2m2025-11-23T13:55:27.974990Z[0m [32m INFO[0m [2mrepartir::messaging[0m[2m:[0m Creating PUB/SUB channel with capacity 1000
✓ Created PUB/SUB channel

┌─────────────────────────────────────────────────────────────┐
│ Scenario 1: Multiple Subscribers (Broadcast)                
└─────────────────────────────────────────────────────────────┘

  Subscribers: 3

  ✓ Published to 3 subscribers

  Worker 1 received: New task available: compute-pi
    Priority: high
  Worker 2 received: New task available: compute-pi
    Priority: high
  Worker 3 received: New task available: compute-pi
    Priority: high

┌─────────────────────────────────────────────────────────────┐
│ Scenario 2: Topic Isolation                                 
└─────────────────────────────────────────────────────────────┘

  Topics: 3

  Events subscriber: Task completed: job-123
  Alerts subscriber: CPU usage above 80%

┌─────────────────────────────────────────────────────────────┐
│ Scenario 3: Real-Time Monitoring                            
└─────────────────────────────────────────────────────────────┘

  ✓ Published 3 metrics

  Monitor 1 received:
    - CPU: 60% (source: worker-1)
    - CPU: 70% (source: worker-1)
    - CPU: 80% (source: worker-1)

  Monitor 2 received:
    - CPU: 60% (source: worker-1)
    - CPU: 70% (source: worker-1)
    - CPU: 80% (source: worker-1)

╔═══════════════════════════════════════════════════════════════╗
║  ✅ PUB/SUB Pattern Demonstrated Successfully                 ║
╚═══════════════════════════════════════════════════════════════╝

Key Characteristics:
  • One publisher → Many subscribers (broadcast)
  • Each subscriber receives all messages
  • Topic-based isolation
  • Useful for events, logging, monitoring

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 11.48    0.000598           6        97           rt_sigprocmask
 21.69    0.001130          13        81         3 futex
 11.11    0.000579           8        65           mmap
  7.93    0.000413           7        58           write
 10.04    0.000523           9        55           mprotect
 17.66    0.000920          19        48           clone3
  6.83    0.000356          11        31           munmap
  2.57    0.000134          10        13         6 openat
  2.15    0.000112           9        12           read
  1.25    0.000065           7         9           unknown
  0.90    0.000047           6         7           close
  1.00    0.000052           8         6           brk
  0.73    0.000038           6         6           rt_sigaction
  0.77    0.000040           8         5           newfstatat
  0.96    0.000050          12         4           pread64
  0.65    0.000034          11         3           statx
  0.38    0.000020           6         3           sigaltstack
  0.25    0.000013           6         2           lseek
  0.23    0.000012           6         2           fcntl
  0.27    0.000014           7         2           getrandom
  0.27    0.000014           7         2         1 arch_prctl
  0.33    0.000017          17         1           socketpair
  0.13    0.000007           7         1           set_tid_address
  0.15    0.000008           8         1           poll
  0.15    0.000008           8         1         1 access
  0.12    0.000006           6         1           set_robust_list
------ ----------- ----------- --------- --------- ----------------
100.00    0.005210          10       516        11 total
