v_queue 0.3.1

simple file based queue
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
# Installation Guide

How to build, install, and run V-Queue.

## Prerequisites

### System Requirements

- **Operating System**: Linux, macOS, or Windows
- **Disk Space**: Minimum 100MB for binaries, plus storage for queue data
- **Memory**: Minimum 512MB RAM
- **CPU**: Any modern CPU (no special requirements)

### Software Requirements

- **Rust**: Version 1.56 or higher (Rust 2021 edition)
- **Cargo**: Comes with Rust installation
- **Git**: For cloning the repository

## Quick Start

### 1. Install Rust

If you don't have Rust installed:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
```

Verify installation:

```bash
rustc --version
cargo --version
```

### 2. Clone Repository

```bash
git clone https://github.com/semantic-machines/v-queue.git
cd v-queue
```

### 3. Build Core Library

```bash
cargo build --release
```

This creates the core library at `target/release/libv_queue.so` (or `.dylib` on macOS, `.dll` on Windows).

### 4. Build and Run Server

```bash
cd v-queue-server
cargo build --release
```

Run with default settings:

```bash
./target/release/v-queue-server
```

Or run directly with cargo:

```bash
cargo run --release
```

### 5. Verify Server is Running

```bash
curl http://localhost:9093/health
```

Expected response:
```json
{
  "status": "ok",
  "version": "0.1.0"
}
```

## Installation Options

### Option 1: Run from Source

Best for development and testing:

```bash
cd v-queue-server
cargo run --release -- --bind 0.0.0.0:9093 --data-dir ./queues
```

### Option 2: Install Binary

Install to system path:

```bash
cd v-queue-server
cargo install --path .
```

This installs to `~/.cargo/bin/v-queue-server`.

Then run from anywhere:

```bash
v-queue-server --bind 0.0.0.0:9093 --data-dir /var/lib/vqueue
```

### Option 3: Copy Binary

Copy the binary to desired location:

```bash
cd v-queue-server
cargo build --release
sudo cp target/release/v-queue-server /usr/local/bin/
```

Run:

```bash
v-queue-server --config /etc/vqueue/server.toml
```

## Configuration

### Create Configuration File

On first run, a default configuration file is created:

```bash
v-queue-server
# Creates v-queue-server.toml in current directory
```

Edit the configuration:

```toml
# Server bind address
bind_address = "127.0.0.1:9093"

# Data storage directory
data_directory = "./queues"

# Logging level: debug, info, warn, error
log_level = "info"

# Maximum message size (bytes)
max_message_size = 1048576

# Default batch size
default_batch_size = 100

# Authentication
auth_enabled = false

# User accounts (when auth enabled)
[users]
admin = "changeme"
```

### Command-Line Options

Override config file settings:

```bash
v-queue-server --help
```

```
A network server for v-queue message queue

Usage: v-queue-server [OPTIONS]

Options:
  -b, --bind <BIND>              Override bind address
  -d, --data-dir <DATA_DIR>      Override data directory
  -l, --log-level <LOG_LEVEL>    Override log level
      --no-auth                  Disable authentication
  -c, --config <CONFIG>          Path to config file [default: v-queue-server.toml]
  -h, --help                     Print help
```

### Examples

Run on all interfaces:
```bash
v-queue-server --bind 0.0.0.0:9093
```

Custom data directory:
```bash
v-queue-server --data-dir /var/lib/vqueue/data
```

Enable debug logging:
```bash
v-queue-server --log-level debug
```

Disable authentication:
```bash
v-queue-server --no-auth
```

Use custom config:
```bash
v-queue-server --config /etc/vqueue/production.toml
```

## Running as a Service

### systemd Service (Linux)

Create `/etc/systemd/system/v-queue-server.service`:

```ini
[Unit]
Description=V-Queue Message Queue Server
After=network.target

[Service]
Type=simple
User=vqueue
Group=vqueue
WorkingDirectory=/var/lib/vqueue
ExecStart=/usr/local/bin/v-queue-server --config /etc/vqueue/server.toml
Restart=on-failure
RestartSec=5s

# Security
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/lib/vqueue

[Install]
WantedBy=multi-user.target
```

Create user and directories:

```bash
sudo useradd -r -s /bin/false vqueue
sudo mkdir -p /var/lib/vqueue/queues
sudo mkdir -p /etc/vqueue
sudo chown -R vqueue:vqueue /var/lib/vqueue
```

Copy config file:

```bash
sudo cp v-queue-server.toml /etc/vqueue/server.toml
sudo chown vqueue:vqueue /etc/vqueue/server.toml
```

Enable and start:

```bash
sudo systemctl daemon-reload
sudo systemctl enable v-queue-server
sudo systemctl start v-queue-server
```

Check status:

```bash
sudo systemctl status v-queue-server
sudo journalctl -u v-queue-server -f
```

### Docker Container

Create `Dockerfile`:

```dockerfile
FROM rust:1.70 as builder

WORKDIR /build
COPY . .
RUN cd v-queue-server && cargo build --release

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /build/v-queue-server/target/release/v-queue-server /usr/local/bin/

RUN useradd -r -s /bin/false vqueue && \
    mkdir -p /var/lib/vqueue/queues && \
    chown -R vqueue:vqueue /var/lib/vqueue

USER vqueue
WORKDIR /var/lib/vqueue

EXPOSE 9093

CMD ["v-queue-server", "--bind", "0.0.0.0:9093", "--data-dir", "/var/lib/vqueue/queues", "--no-auth"]
```

Build and run:

```bash
docker build -t v-queue-server .
docker run -d -p 9093:9093 -v /path/to/data:/var/lib/vqueue/queues v-queue-server
```

### Docker Compose

Create `docker-compose.yml`:

```yaml
version: '3.8'

services:
  v-queue:
    build: .
    ports:
      - "9093:9093"
    volumes:
      - ./queues:/var/lib/vqueue/queues
      - ./v-queue-server.toml:/etc/vqueue/server.toml
    command: ["v-queue-server", "--config", "/etc/vqueue/server.toml"]
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9093/health"]
      interval: 30s
      timeout: 3s
      retries: 3
```

Run:

```bash
docker-compose up -d
```

## Data Directory Structure

After running, the data directory will look like:

```
queues/
├── events_info_queue          # Queue metadata
├── events_queue.lock          # Write lock
└── events-0/                  # Partition 0
    ├── events_queue           # Message data
    └── events_info_push       # Write position
```

Consumer data is also stored here:

```
queues/
├── events_info_pop_my-consumer    # Consumer offset tracking
└── ...
```

## Backup and Migration

### Backup

Simply copy the entire data directory:

```bash
cp -r /var/lib/vqueue/queues /backup/vqueue-$(date +%Y%m%d)
```

For live backups, ensure consumers are paused to maintain consistency.

### Restore

Copy the backup to the data directory:

```bash
cp -r /backup/vqueue-20240101/queues /var/lib/vqueue/
chown -R vqueue:vqueue /var/lib/vqueue/queues
```

Restart the server:

```bash
sudo systemctl restart v-queue-server
```

### Migration

To move to a different server:

1. Stop the old server
2. Copy data directory to new server
3. Install v-queue-server on new server
4. Start new server pointing to copied data
5. Update client configurations

## Troubleshooting

### Server won't start

Check port availability:
```bash
netstat -tlnp | grep 9093
```

Check permissions:
```bash
ls -la /var/lib/vqueue
```

Check logs:
```bash
v-queue-server --log-level debug
```

### Permission denied errors

Ensure data directory is writable:
```bash
sudo chown -R vqueue:vqueue /var/lib/vqueue
sudo chmod -R 755 /var/lib/vqueue
```

### Cannot bind to port

Use a different port or run as root (not recommended):
```bash
v-queue-server --bind 127.0.0.1:9094
```

Or allow binding to privileged ports:
```bash
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/v-queue-server
```

## Uninstallation

### Remove binary

```bash
sudo rm /usr/local/bin/v-queue-server
```

Or if installed via cargo:

```bash
cargo uninstall v-queue-server
```

### Remove service

```bash
sudo systemctl stop v-queue-server
sudo systemctl disable v-queue-server
sudo rm /etc/systemd/system/v-queue-server.service
sudo systemctl daemon-reload
```

### Remove data

```bash
sudo rm -rf /var/lib/vqueue
sudo rm -rf /etc/vqueue
sudo userdel vqueue
```

## Next Steps

- [Configuration Guide]04-configuration.md
- [API Reference]05-api-reference.md
- [Client Examples]07-client-examples.md