Created
May 25, 2013 18:59
-
-
Save mguymon/5650321 to your computer and use it in GitHub Desktop.
Ruby StompClient updated to support headers
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
class StompClient < Stilts::Stomp::Client | |
field_accessor :destroyExecutor, :channel, :bootstrap | |
# override send to add header support | |
def send(destination, message, headers = nil) | |
method_args = [destination] | |
if headers | |
# convert Ruby hash to org.projectodd.stilts.stomp.Headers | |
stomp_headers = org.projectodd.stilts.stomp.DefaultHeaders.new | |
headers.each do |key,val| | |
stomp_headers.put(key.to_s, val.to_s) | |
end | |
method_args << stomp_headers | |
end | |
method_args << message | |
stomp_message = org.projectodd.stilts.stomp::StompMessages.createStompMessage( *method_args ) | |
original_send( stomp_message ) | |
end | |
# override broken disconnect | |
def disconnect | |
self.setConnectionState( ::StompClient::State::DISCONNECTING ) | |
begin | |
self.channel.close() | |
self.waitForDisconnected( ::StompClient::DEFAULT_DISCONNECT_WAIT_TIME ) | |
ensure | |
begin | |
if self.channel.isConnected() | |
self.channel.disconnect().await( ::StompClient::DEFAULT_DISCONNECT_WAIT_TIME ) | |
end | |
ensure | |
if self.destroyExecutor | |
if self.executor.is_a? java.util.concurrent.ExecutorService | |
self.executor.shutdown() | |
end | |
self.executor = nil | |
self.destroyExecutor = false | |
end | |
end | |
end | |
self.bootstrap.releaseExternalResources() | |
self.bootstrap = nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the pull request - projectodd/stilts#14