Ruby e STOMP

Um editor e assinante em Ruby usando ApacheMQ como fila de mensagens.

publicar.rb

require 'stomp'
@emailclient = Stomp::Connection.open '','',"localhost", 61613, true, {'client-id' => "hpustomp"}
@emailclient.publish('/topic/hpumail', {:to => email, :token => register_confirm.token, :reason => 'register'}.to_json, {:persistent => 'true'})

subscribe.rb

client_id = "hpustomp"
subscription_name
= "hpustomp"

stomp_params
= {
:hosts => [
{:host => "localhost", :port => 61613}
],
:connect_headers => {'client-id' => client_id},
}

client
= Stomp::Client.new stomp_params
client
.subscribe "/topic/hpumail", {"ack" => "client", "activemq.subscriptionName" => subscription_name} do |message|
logstr
= "received: #{message.body} on #{message.headers['destination']}"
begin
process
(message.body)
client
.acknowledge message
rescue Exception => e
puts
"Error #{e}"
end
end
client
.join