Created
February 3, 2014 10:13
-
-
Save waynerobinson/8781389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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