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



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

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

#incrementObject



15
16
17
# File 'lib/estorm-message-processor/consumer.rb', line 15

def increment
   @mycount=self.count+1
end

#process_messages(delivery_info, metadata, body) ⇒ Object

process message



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/estorm-message-processor/consumer.rb', line 26

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.



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/estorm-message-processor/consumer.rb', line 44

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