Sha256: f346b13fabbe4f11627b17c54ce21743bab81c898608d4b59f9eb7670b96b18e

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'cotton_tail'

app = CottonTail::App.new.define do
  # Create the queue 'hello_world_queue' if it does not exists
  queue 'hello_world_queue', exclusive: true do
    # Create a binding from the default topic exchange ('amq.topic') to
    # the queue 'hello_world_queue'. When a message is received with the
    # routing key 'say.hello' the block is executed.
    handle 'say.hello' do
      puts 'Hello world!'
    end

    handle 'say.goodbye' do
      puts 'Goodbye cruel world!'
    end

    handle 'inspect.message' do |delivery_info, properties, message|
      puts delivery_info: delivery_info
      puts properties: properties
      puts message: message
    end
  end

  queue 'require_ack_queue', exclusive: true, manual_ack: true do
    handle 'get.acked' do |delivery_info, _props, _msg, opts|
      conn = opts[:conn]
      delivery_tag = delivery_info[:delivery_tag]
      puts "acking with #{delivery_tag}"
      conn.ack(delivery_tag)
    end

    handle 'get.nacked' do |delivery_info, _props, _msg, opts|
      conn = opts[:conn]
      delivery_tag = delivery_info[:delivery_tag]
      puts "nacking with #{delivery_tag}"
      conn.nack(delivery_tag)
    end
  end
end

app.start

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cotton-tail-0.2.1 examples/app.rb
cotton-tail-0.2.0 examples/app.rb
cotton-tail-0.1.2 examples/app.rb
cotton-tail-0.1.1 examples/app.rb