Skip to content

Instantly share code, notes, and snippets.

@waynerobinson
Created February 3, 2014 10:13
Show Gist options
  • Save waynerobinson/8781389 to your computer and use it in GitHub Desktop.
Save waynerobinson/8781389 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'stomp'
#
# == Example message consumer.
#
class ExampleConsumer
# Initialize.
def initialize
end
# Run example.
def run
client = Stomp::Client.new("failover://(stomp://:@localhost:61613,stomp://:@remotehost:61613)?initialReconnectDelay=5000&randomize=false&useExponentialBackOff=false")
puts "Subscribing ronaldo"
client.subscribe("/queue/ronaldo", {:ack => "client", "activemq.prefetchSize" => 1, "activemq.exclusive" => true }) do |msg|
puts msg.body
client.acknowledge(msg)
if msg.headers[:executions] < 2
client.publish "/queue/ronaldo", msg + "\n\tExecute again #{Time.now}", {persistent: true, executions: msg[:executions] + 1}
end
end
2.times do |i|
client.publish "/queue/ronaldo", "Test #{i} #{Time.now}", {persisitent: true, executions: 1}
end
loop do
sleep(1)
puts "."
end
end
end
#
e = ExampleConsumer.new
e.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment