amqp-client
amqp-client
An AMQP 0-9-1 client for Crystal.
Installation
- Add the dependency to your
shard.yml
:
dependencies:
amqp-client:
github: cloudamqp/amqp-client.cr
- Run
shards install
Usage
require "amqp-client"
AMQP::Client.start("amqp://guest:guest@localhost") do |c|
c.channel do |ch|
q = ch.queue("my-queue")
q.subscribe(no_ack: false) do |msg|
puts "Received: #{msg.body_io.to_s}"
ch.basic_ack(msg.delivery_tag)
end
# publish directly to a queue without confirm
q.publish "msg"
# publish directly to a queue, blocking while waiting for confirm
q.publish_confirm "msg"
# publish to any exchange/routing-key
ch.basic_publish "msg", exchange: "amq.topic", routing_key: "a"
# publish to any exchange/routing-key and wait for confirm
ch.basic_publish_confirm "msg", exchange: "amq.topic", routing_key: "a"
end
end
Contributing
- Fork it (https://github.com/cloudamqp/amqp-client.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Carl Hörberg - creator and maintainer