Class: TraceFilter

Inherits:
ActiveMessaging::Filter show all
Includes:
ActiveMessaging::MessageSender
Defined in:
lib/activemessaging/trace_filter.rb

Instance Method Summary collapse

Methods included from ActiveMessaging::MessageSender

included, #publish, #publish_with_reset, #receive

Methods inherited from ActiveMessaging::Filter

#logger

Constructor Details

#initialize(options) ⇒ TraceFilter

Returns a new instance of TraceFilter.



4
5
6
7
# File 'lib/activemessaging/trace_filter.rb', line 4

def initialize(options)
  @queue = options[:queue]
  TraceFilter.publishes_to @queue
end

Instance Method Details

#process(message, routing) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/activemessaging/trace_filter.rb', line 9

def process message, routing
  
  unless ( routing[:destination].name == @queue ) then
    ActiveMessaging.logger.debug "Trace: direction = #{routing[:direction]} publisher=#{routing[:publisher]} queue=#{routing[:destination].name} @queue=#{@queue}"
    if routing[:direction].to_sym==:outgoing then
      "trace from outgoing"
      publish @queue, "<sent>"+
                      "<from>#{routing[:publisher]}</from>" +        
                      "<queue>#{routing[:destination].name}</queue>" +
                      "<message>#{message.body}</message>" + 
                      "</sent>"
    end
    if routing[:direction].to_sym==:incoming then
      "trace from incoming"
      publish @queue, "<received>"+
                      "<by>#{routing[:receiver]}</by>" +        
                      "<queue>#{routing[:destination].name}</queue>" +
                      "<message>#{message.body}</message>" + 
                      "</received>"
    end
  end

end