Skip to content
maxpertPublic

About

AMQP server written in Golang

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Repository files navigation

StrangeQ

A message broker for AMQP 0-9-1 and MQTT, written in Go, built to replace RabbitMQ without changing your clients.

Build Status License: MIT

StrangeQ is a single binary that serves AMQP 0-9-1 and MQTT 3.1.1 and 5.0, with HTTP publish and Server-Sent Events alongside. Existing RabbitMQ client libraries connect to it unchanged. The same binary runs as one node or as a replicated cluster, and a running single node can be promoted to a cluster without dropping connections. Its goal is RabbitMQ's behaviour at higher throughput and a fraction of the memory.

Features

Protocols

  • AMQP 0-9-1 with direct, fanout, topic and headers exchanges, exchange-to-exchange bindings and alternate exchanges.
  • Publisher confirms, mandatory returns, acks, nacks and rejects, basic.qos prefetch, transactions, and consumer cancel notifications.
  • Message TTL, queue expiry, length limits with drop-head, reject-publish and reject-publish-dlx overflow, and dead-letter exchanges with x-death headers, at-least-once or at-most-once.
  • MQTT 3.1.1 and 5.0 over TCP, TLS and WebSockets: QoS 0, 1 and 2, shared subscriptions, retained messages, Last Will, and session takeover. See the MQTT support matrix.
  • HTTP publish and Server-Sent Events subscriptions, and optional bridging between AMQP and MQTT topics.

Durability

  • process: a confirm survives a broker process crash. No disk sync before the confirm. Single-node only.
  • barrier (default): a confirm survives a process crash and an OS crash.
  • flush: as barrier, and on macOS also power loss.

Clustering

  • Raft replication with up to three voting replicas per shard. A shard keeps committing while one replica is down.
  • Clients connect to any node.
  • Rolling upgrades, with drain, remove and leader-balance operations.

Management and observability

  • A management API and web UI on port 15672, off by default.
  • Prometheus metrics and a /health readiness probe on port 9419, off by default.
  • Memory and disk alarms that raise connection.blocked.

RabbitMQ compatibility

  • A subset of the RabbitMQ 4.4 management HTTP API, including definitions import and export (with a dry-run mode).
  • Users carry RabbitMQ-style password_hash and hashing_algorithm, and POST /api/auth/hash_password produces the default salted SHA-256 form.
  • Configure, write and read permissions per user.
  • Users, permissions and MQTT topic ACLs can be provisioned at runtime over the HTTP API. Changes are replicated to every cluster node and enforced on MQTT publish and subscribe.
  • Tested with pika, amqplib and amqp091-go. An opt-in interop suite runs the same checks against a real RabbitMQ.

How clustering works

StrangeQ uses one storage engine for every deployment: a segmented, Raft-replicated journal. A node started without cluster.id is a single-node cluster, so there is no separate standalone code path.

  • Shards. Queues are spread over a fixed number of shards (32 by default, 1 to 1024, fixed for the life of the cluster). Each shard is its own Raft group, built on etcd's Raft library, with up to three voting replicas. A node routes each queue operation to the shard that owns the queue.
  • Shared journal. Each node keeps one journal that all of its shard groups write to, capped by cluster.journal_quota_bytes (8 GiB by default). Space is reclaimed as messages are acknowledged.
  • Confirms. With barrier durability a publisher confirm means the message reached a majority of the shard's replicas, each of which has synced it to disk. A publish is stored at most once per queue while its channel stays open, across leader changes and lost replies. After a leader failure the broker asks the shard which messages it stored, confirms those and resends the rest.
  • Process and barrier. process skips the disk sync and is available only to a single node that has never had peers. Turning on peers moves the node to full durability for good.
  • Failure and recovery. If a shard's leader fails, a new one is elected and confirms and deliveries pause until it is. If a broker fails, clients reconnect to another node. Unacknowledged deliveries are redelivered, so consumers should be idempotent. Consumers with auto-ack are at-most-once.
  • Membership. Peers authenticate with a shared token, and traffic between hosts requires TLS. New nodes join as learners, catch up, then vote. Retired node IDs are permanently tombstoned.

The clustering guide covers setup, quorum and readiness, and the full configuration reference.

Why StrangeQ

  • Throughput. Higher message rates than RabbitMQ 4.4 in the preliminary measurements below.
  • Memory. Resident memory is a fraction of RabbitMQ's in the workloads measured.
  • One engine, one binary. Single node and cluster share the same code and data format. Going from one node to three needs a config change and SIGHUP, not a migration.
  • Drop-in clients. Standard AMQP and MQTT client libraries work without changes, and the management API and definitions format follow RabbitMQ's.
  • MQTT, HTTP and AMQP in one broker. No plugin to enable and no second service to run.

Preliminary measurements, single host, against RabbitMQ 4.4. See benchmark/ and docs/BENCHMARKS.md:

Workload StrangeQ vs RabbitMQ
Single-node AMQP, 1 KiB messages, throughput about 1.6x
Single-node MQTT, 1 KiB messages, throughput about 2 to 2.5x
Resident memory (RSS) across measured workloads 0.1 to 0.4x
3-node cluster vs RabbitMQ quorum queues, throughput 1.1 to 1.5x

These numbers do not show an advantage in latency or for large (64 KiB) messages, and they have not been confirmed on separate server hosts.

Quick start

Build from source. The release archives predate the Raft journal, clustering and MQTT. You need the Go version declared in go.mod.

git clone https://github.com/maxpert/strangeq.git
cd strangeq/src/amqp-go
go build -o amqp-server ./cmd/amqp-server

Single node

./amqp-server

The broker listens on 127.0.0.1:5672 and stores data in ./data/cluster. Authentication is off by default and everything binds to loopback. Point any AMQP 0-9-1 client at amqp://127.0.0.1:5672/. See the client examples for Python, Node.js and Go, and authentication and TLS before exposing it.

Three-node cluster

Create a shared peer token, then write one config per node.

umask 077
openssl rand -base64 32 | tr -- '+/' '-_' | tr -d '=\n' > peer.token

node-1.yaml (use node_id 2 and 3, ports 5673 and 5674, peer ports 7662 and 7663, and their own path for the others):

network:
  address: "127.0.0.1:5672"
storage:
  path: "./node-1-data"
cluster:
  id: "example"
  node_id: 1
  peer_address: "127.0.0.1:7661"
  seeds: ["1@127.0.0.1:7661", "2@127.0.0.1:7662", "3@127.0.0.1:7663"]
  token_file: "./peer.token"
  allow_loopback_plaintext: true
for i in 1 2 3; do ./amqp-server --config node-$i.yaml --initialize-cluster; done
for i in 1 2 3; do ./amqp-server --config node-$i.yaml & done

allow_loopback_plaintext is for local tests only. Across hosts, configure peer TLS. To start from one node and add peers later, or to run the ready-made three-node demo, see the clustering guide and examples/cluster-demo.

Configuration and documentation

./amqp-server --generate-config config.yaml writes a file with every default, and ./amqp-server --config config.yaml starts with it. Files layer over defaults, AMQP_* environment variables override files, and flags override both. ./amqp-server -h lists the flags, and the commented sample config explains each setting.

Benchmarks

src/amqp-go/benchmark/matrix.py runs the head-to-head matrix of StrangeQ against RabbitMQ 4.4 across workloads, and matrix.py list shows the cells. benchmark/README.md describes the method, the AMQP load generator and the Go micro-benchmarks. docs/BENCHMARKS.md has results and the commands to reproduce them.

Status and compatibility

StrangeQ is under active development. The Raft journal, clustering and MQTT are available from source and are not in the latest release archive. Known differences from RabbitMQ:

  • Only the default virtual host / is accepted.
  • x-max-priority, x-priority, x-single-active-consumer and x-queue-mode are accepted and ignored. x-queue-type: stream is refused. There are no policies, streams, federation or shovel.
  • Prefetch by size is not supported, and a consumer holds at most 2000 unacknowledged deliveries.
  • A publish routed to several queues commits per queue, so a failure can leave a partial fanout. A confirm-mode publisher receives basic.nack, as with RabbitMQ.
  • Queues are placed on a fixed set of Raft shards (32 by default) chosen when the cluster is created, rather than one Raft group per quorum queue as in RabbitMQ. The shard count cannot be changed later.
  • At-least-once dead letters with no route keep their journal space, and can fill the quota if nothing is bound to the dead-letter exchange.

Contributing

See CONTRIBUTING.md. Report bugs through GitHub Issues and vulnerabilities through the security policy.

License

MIT.

About

AMQP server written in Golang

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages