Class: TorqueBox::Stomp::JmsStomplet::MessageListener Private

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/stomp/jms_stomplet.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(subscriber, options = {}) ⇒ MessageListener

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MessageListener.



110
111
112
113
# File 'lib/torquebox/stomp/jms_stomplet.rb', line 110

def initialize(subscriber, options={})
  @subscriber = subscriber
  @encoding = options[:encoding] 
end

Instance Method Details

#onMessage(jms_message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/torquebox/stomp/jms_stomplet.rb', line 115

def onMessage(jms_message)
  content = TorqueBox::Messaging::Message.new( jms_message ).decode
  ( content = TorqueBox::Codecs.encode( content, @encoding ) ) if @encoding
  stomp_message = TorqueBox::Stomp::Message.new( content )
  jms_message.property_names.each do |name|
    value = jms_message.getObjectProperty( name ).to_s
    stomp_message.headers.put( name.to_s.to_java( java.lang.String ), value.to_java( java.lang.String) ) if value
  end
  if ( stomp_message.headers[ 'content-type' ] == nil )
    if ( @encoding == :json )
      stomp_message.headers.put( "content-type", "application/json" )
    else
      stomp_message.headers.put( "content-type", "text/plain" )
    end
  end
  @subscriber.send( stomp_message )
end