crystal-amqp-example
Use CloudAMQP from Crystal
A minimal example of publishing and consuming messages with amqp-client.cr, against CloudAMQP or any AMQP 0-9-1 broker such as LavinMQ or RabbitMQ.
All AMQP code is in src/example.cr:
publishpublishes a persistent message and blocks until the broker has confirmed it. amqp-client.cr publishes transient messages unlessdelivery_mode: 2is set.consumeconsumes with a prefetch of 10, acking each message after the block returns.subscribeacks automatically unlessno_ack: falseis passed.connectconnects using theCLOUDAMQP_URLenvironment variable, and verifies the server certificate foramqps://URLs.
amqp-client.cr doesn't reconnect: if the connection is lost, the programs exit.
Usage
Tool versions are in mise.toml; install them with mise, or use any Crystal 1.x.
shards build
export CLOUDAMQP_URL="amqps://user:password@host/vhost"
bin/worker # in one terminal
bin/publisher # in another
Without CLOUDAMQP_URL it connects to amqp://guest:guest@localhost.
Tests
crystal spec publishes and consumes a message through a real broker on localhost. CI runs it against LavinMQ, together with crystal tool format and ameba.
Repository
crystal-amqp-example
Owner
Statistic
- 0
- 0
- 0
- 0
- 2
- about 4 hours ago
- October 16, 2026
License
Links
Synced at
Fri, 16 Oct 2026 13:01:46 GMT
Languages