How peterfraedrich/consulmq works
Main components
a. Client Application (producer/consumer) – any Go program that calls consulmq.Connect(...), Push, Pop, etc.
b. ConsulMQ Library – your Go package consisting of consulmq.go, functions.go, and associated tests.
c. Consul Cluster (external service) – the distributed KV store and lock/session subsystem.
d. Queue Artifacts in KV Store – the _index key (JSON list of message IDs) plus per-message keys under unique IDs.
Interactions and data flows
• Client → ConsulMQ Library: calls API methods Connect, Push, Pop, etc.
• Library → Consul HTTP API:
• Acquire distributed lock (using Consul sessions) on the queue’s _index.
• Read _index key (JSON array of IDs).
• For Push: generate new ID, write message body under <MQName>/<ID>, append ID to _index, write back.
• For Pop: remove first ID from _index, write back index, then read or delete the message key.
• Release the lock.
• Library returns results/errors to Client.
Architectural patterns and design principles
• Single shared resource (the _index) protected by a distributed lock.
• Each message is an independent KV entry, enabling durability and distribution.
• The library is a thin adapter over Consul’s KV + Session APIs (no external broker).
• JSON is used as the on-chain format for the index; message payloads are raw bytes.