Sha256: d101387c17c5da862027f12e2c6768fa6484acf7c187a053c96c58286e236dc8

Contents?: true

Size: 857 Bytes

Versions: 15

Compression:

Stored size: 857 Bytes

Contents

# encoding: utf - 8

$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)

require "amqp"

# Imagine we have for example 10 servers, on each of them runs this
# script, just the server_name variable will be different on each of them.
server_name = "server - 1"

AMQP.start do
  amq = AMQP::Channel.new

  # Tasks distribution has to be based on load on each clients rather
  # than on the number of distributed messages. (The default behaviour
  # is to dispatches every n - th message to the n - th consumer.
  amq.prefetch(1)

  # Acknowledgements are good for letting the server know
  # that the task is finished. If the consumer doesn't send
  # the acknowledgement, then the task is considered to be unfinished.
  amq.queue(server_name).subscribe(:ack => true) do |h, message|
    puts message
    puts system(message)
    h.ack
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
amqp-0.8.0.rc13 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc12 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc11 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc10 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc9 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc8 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc7 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc6 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc5 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc4 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc3 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc2 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.rc1 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.pre.beta1 examples/real-world/task-queue/consumer.rb
amqp-0.8.0.beta1 examples/real-world/task-queue/consumer.rb