Sha256: 2ab61363b14ade582d9361264fa0dcc501c785fea19e395e3336da5cca5b02aa

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

__dir = File.dirname(File.expand_path(__FILE__))
require File.join(__dir, "example_helper")

amq_client_example "Acknowledge a message using basic.ack" do |client|
  channel = AMQ::Client::Channel.new(client, 1)
  channel.open do
    puts "Channel #{channel.id} is now open!"
  end

  queue = AMQ::Client::Queue.new(client, channel)
  queue.declare

  queue.bind("amq.fanout") do
    puts "Queue #{queue.name} is now bound to amq.fanout"
  end

  queue.consume do |consumer_tag|
    queue.on_delivery do |method, header, payload|
      puts "Got a delivery: #{payload} (delivery tag: #{method.delivery_tag}), ack-ing..."

      queue.acknowledge(method.delivery_tag)
    end

    exchange = AMQ::Client::Exchange.new(client, channel, "amq.fanout", :fanout)
    10.times do |i|
      exchange.publish("Message ##{i}")
    end
  end

  show_stopper = Proc.new {
    client.disconnect do
      puts
      puts "AMQP connection is now properly closed"
      EventMachine.stop
    end
  }

  Signal.trap "INT",  show_stopper
  Signal.trap "TERM", show_stopper

  EM.add_timer(1, show_stopper)
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
amq-client-0.7.0.alpha35 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha34 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha33 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha32 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha31 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha30 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha29 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb
amq-client-0.7.0.alpha28 examples/eventmachine_adapter/basic_consume_with_acknowledgements.rb