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

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

Instance Method Summary (collapse)

Constructor Details

- (MessageListener) initialize(subscriber, options = {})

Returns a new instance of MessageListener



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

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

Instance Method Details

- (Object) onMessage(jms_message)



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'stomp/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