Skip to content

Instantly share code, notes, and snippets.

@mguymon
Created May 25, 2013 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mguymon/5650321 to your computer and use it in GitHub Desktop.
Save mguymon/5650321 to your computer and use it in GitHub Desktop.
Ruby StompClient updated to support headers
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
@mguymon
Copy link
Author

mguymon commented May 25, 2013

Based on the pull request - projectodd/stilts#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment