crystal-amqp-example

Version, currently main branch1 version
  • main branchlatestOct 16, 2026

github.com/cloudamqp/crystal-amqp-example

Example of Crystal with LavinMQ or RabbitMQ

0 stars
0 dependents
License: not declared

The last crawl could not reach this repository on its host: cloudamqp/crystal-amqp-example is not a repository this token can see. The entry stays because repositories come back, and because other shards still link to it.

Installation

# Add this to your shard.yml
dependencies:
  crystal-amqp-example:
    github: cloudamqp/crystal-amqp-example
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.0.0
Targets
  • worker from src/worker.cr
  • publisher from src/publisher.cr

Dependencies

Runtime Dependencies

Development Dependencies

  • ameba*github: crystal-ameba/amebadev

README

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:

  • publish publishes a persistent message and blocks until the broker has confirmed it. amqp-client.cr publishes transient messages unless delivery_mode: 2 is set.
  • consume consumes with a prefetch of 10, acking each message after the block returns. subscribe acks automatically unless no_ack: false is passed.
  • connect connects using the CLOUDAMQP_URL environment variable, and verifies the server certificate for amqps:// 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.