Created
November 27, 2013 07:14
-
-
Save swistaczek/7671807 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 'stilts-stomp-client' | |
require 'json' | |
client = Stilts::Stomp::Client.new("localhost:8675") | |
client.connect | |
# Using headers due to missing TorqueBox stomp username and password functionality | |
headers = org.projectodd.stilts.stomp::DefaultHeaders.new | |
headers.putAll({ 'api_key' => 'tpG8jY1SnbSeQvS9Ip2dhQ' }) | |
stomp_message = org.projectodd.stilts.stomp::StompMessages.createStompMessage( "/reporters/event", headers, 'authorize') | |
begin | |
message = client.original_send(stomp_message) | |
rescue java.nio.channels.ClosedChannelException => e | |
# retry and reconnect manually? | |
end | |
client.subscribe("/reporters/event") do |message| | |
message = JSON.parse(message.body) | |
puts message | |
end | |
# If server goes down client.is_connected still returns true | |
client.is_connected # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment