Configure Retention
Set time-based, size-based, or count-based retention policies for stored events.
Events Store persists messages to disk. Without retention policies, storage grows indefinitely. KubeMQ provides three types of retention controls: time-based, size-based, and count-based. You can combine them — the most restrictive policy wins.
Retention Options
| Setting | Config Key | Default | Description |
|---|---|---|---|
| Max retention time | Store.MaxRetention | 1440 (24 hours) | Maximum age of messages in minutes. 0 = unlimited. |
| Max channel size | Store.MaxQueueSize | 0 (unlimited) | Maximum total bytes per channel. Oldest removed when exceeded. |
| Max message count | Store.MaxMessages | 0 (unlimited) | Maximum messages per channel. Oldest removed when exceeded. |
| Inactive channel purge | Store.MaxPurgeInactive | 1440 (24 hours) | Minutes of inactivity before an empty channel is purged. |
How Retention Works
As events accumulate, KubeMQ checks each retention threshold and purges the oldest events by time, size, or count — keeping everything that still fits within every limit.
Configure via Docker
Set retention options using environment variables:
docker run -d \ --name kubemq \ -p 50000:50000 \ -p 9090:9090 \ -p 8080:8080 \ -e KUBEMQ_TOKEN=YOUR_LICENSE_KEY \ -e STORE_MAX_RETENTION=4320 \ -e STORE_MAX_QUEUE_SIZE=1073741824 \ -e STORE_MAX_MESSAGES=1000000 \ -e STORE_MAX_PURGE_INACTIVE=10080 \ europe-docker.pkg.dev/kubemq/images/kubemq:nextThis configures:
- 3-day retention (4320 minutes)
- 1 GB max per channel (1073741824 bytes)
- 1 million messages max per channel
- 7-day inactive channel purge (10080 minutes)
Configure via Helm
Set retention in your values.yaml:
store:
maxRetention: 4320
maxQueueSize: 1073741824
maxMessages: 1000000
maxPurgeInactive: 10080Then install or upgrade:
helm upgrade kubemq kubemq/kubemq --values values.yamlConfigure via Kubernetes Operator
Set retention in the KubeMQ CRD:
apiVersion: core.k8s.kubemq.io/v1beta1
kind: KubemqCluster
metadata:
name: kubemq
spec:
store:
maxRetention: 4320
maxQueueSize: 1073741824
maxMessages: 1000000
maxPurgeInactive: 10080Common Retention Strategies
Development (Short Retention)
STORE_MAX_RETENTION=60 # 1 hour
STORE_MAX_MESSAGES=10000 # 10K messages
STORE_CLEAN_STORE=true # Clean on restartProduction — Event Streaming
STORE_MAX_RETENTION=10080 # 7 days
STORE_MAX_QUEUE_SIZE=5368709120 # 5 GB per channel
STORE_MAX_MESSAGES=0 # Unlimited messagesProduction — Event Sourcing
STORE_MAX_RETENTION=0 # Unlimited (no time expiry)
STORE_MAX_QUEUE_SIZE=0 # Unlimited size
STORE_MAX_MESSAGES=0 # Unlimited messagesSetting all retention values to 0 (unlimited) means events are stored indefinitely. Monitor disk usage with the storage utilization thresholds to prevent disk exhaustion.
Production — Compliance (Fixed Window)
STORE_MAX_RETENTION=525600 # 365 days (1 year)
STORE_MAX_QUEUE_SIZE=0 # Unlimited size
STORE_MAX_MESSAGES=0 # Unlimited messages
STORE_MAX_PURGE_INACTIVE=525600 # Purge inactive after 1 yearPersistence and Recovery
Clean Start
To clear all stored data on startup:
docker run -d \ --name kubemq \ -p 50000:50000 \ -p 9090:9090 \ -p 8080:8080 \ -e KUBEMQ_TOKEN=YOUR_LICENSE_KEY \ -e STORE_CLEAN_STORE=true \ europe-docker.pkg.dev/kubemq/images/kubemq:nextVolume Persistence
For data to survive container restarts, mount a volume to the store path:
docker run -d \ --name kubemq \ -p 50000:50000 \ -e KUBEMQ_TOKEN=YOUR_LICENSE_KEY \ --hostname kubemq \ -v kubemq-data:/kubemq/store \ europe-docker.pkg.dev/kubemq/images/kubemq:nextRecovery from Corruption
If the server detects recovery errors on startup, it automatically removes and recreates the store directory. The TruncateUnexpectedEOF option (enabled by default) truncates corrupted file tails rather than failing.
File store tuning (WriteBufferSize, ReadBufferSize, DiskSyncSeconds, etc.) is rarely needed. The defaults are suitable for most workloads. See the Events Store Reference for advanced settings.
Related
- Monitor Storage Utilization for disk usage thresholds
- Resume After Disconnect for durable subscription behavior
- Events Store Reference for complete configuration
Was this page helpful?