Class: EstormMessageProcessor::Consumer

Inherits:
Bunny::Consumer
  • Object
show all
Defined in:
lib/estorm-message-processor/consumer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/estorm-message-processor/consumer.rb', line 7

def logger
  @logger
end

Instance Method Details

#cancelled?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/estorm-message-processor/consumer.rb', line 8

def cancelled?
  @cancelled
end

#countObject



11
12
13
14
# File 'lib/estorm-message-processor/consumer.rb', line 11

def count
    @mycount=0  if @mycount==nil
    @mycount
end

#handle_cancellation(_) ⇒ Object



29
30
31
32
33
# File 'lib/estorm-message-processor/consumer.rb', line 29

def handle_cancellation(_)
  msg="consumer cancellation queue called"
  @logger.info msg
  @cancelled = true
end

#incrementObject



23
24
25
26
27
# File 'lib/estorm-message-processor/consumer.rb', line 23

def increment
   @mycount=self.count+1
   @cancelled=true if @exit_flag && @exit_count < @mycount
   @mycount
end

#process_messages(delivery_info, metadata, body) ⇒ Object

process message



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/estorm-message-processor/consumer.rb', line 35

def process_messages(delivery_info,,body)
  begin
    cmdhash=YAML.load(body)
    delegatestring="delegate_#{cmdhash['command']}"
    # create procedures named delegate_command accepting cmdhash
    msg = "-----> [gem estorm message processor:  consumer] Received from App #{body} calling delegate #{delegatestring} count: #{self.count} "
    @logger.info msg
    self.send(delegatestring,cmdhash)
    # self.send(delegatestring,cmdhash)
    #load the promotion and process through data
    self.increment
  rescue  Exception => e    # add could not convert integer
    msg= "[gem estorm message processor] bunny exception #{e.message} found #{e.inspect} #{e.backtrace}..."  #THIS NEEDS WORK!
    @logger.info msg

   end
end

#queue_statisticsObject

get the queue statistics and log it.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/estorm-message-processor/consumer.rb', line 53

def queue_statistics
 msg_count=0
 begin
 msg_count =@queue.message_count
 consumer_count =@queue.consumer_count
 msg = "queue status for queue [#{@queue.name}] message count: #{msg_count} consumers: #{consumer_count}"
 @logger.info msg if @logger!=nil
 rescue  Exception => e
   msg = "exception in queue statistics #{e.inspect}"
   @logger.info msg  if @logger!=nil
 end
 [msg_count, consumer_count]
end

#target(count, flag) ⇒ Object

this is a target to count messages and exit if needed



17
18
19
20
21
22
# File 'lib/estorm-message-processor/consumer.rb', line 17

def target(count,flag)
  msg = "-- Message Processor exit when complete flag set: target messages is #{count} flag is #{flag}"
  logger.info msg
  @exit_flag=flag
  @exit_count=count-1
end