Class: EstormMessageProcessor::Base
- Inherits:
-
Object
- Object
- EstormMessageProcessor::Base
- Defined in:
- lib/estorm-message-processor/base.rb
Constant Summary collapse
- @@mt_id =
MT id counter.
0
Class Method Summary collapse
Instance Method Summary collapse
- #logger ⇒ Object
- #process_messages(delivery_info, properties, body) ⇒ Object
- #setup_bunny_communications(url, flag, queuename) ⇒ Object
- #start(config) ⇒ Object
- #tear_down_bunny ⇒ Object
Class Method Details
.logger ⇒ Object
10 11 12 |
# File 'lib/estorm-message-processor/base.rb', line 10 def Base.logger @@logger end |
.logger=(logger) ⇒ Object
14 15 16 |
# File 'lib/estorm-message-processor/base.rb', line 14 def Base.logger=(logger) @@logger = logger end |
Instance Method Details
#logger ⇒ Object
18 19 20 |
# File 'lib/estorm-message-processor/base.rb', line 18 def logger @@logger end |
#process_messages(delivery_info, properties, body) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/estorm-message-processor/base.rb', line 22 def (delivery_info,properties,body) begin cmdhash=YAML.load(body) delegatestring="delegate_#{cmdhash['command']}" # create procedures named delegate_command accepting cmdhash msg = "-----> [gem estorm message processor] Received from App #{body} calling delegate #{delegatestring} " logger.info msg self.send(delegatestring,cmdhash) #load the promotion and process through data rescue Exception => e # add could not convert integer msg= "found bunny exception #{e.message} found #{e.inspect} #{e.backtrace}..." #THIS NEEDS WORK! logger.info msg end end |
#setup_bunny_communications(url, flag, queuename) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/estorm-message-processor/base.rb', line 43 def setup_bunny_communications(url,flag,queuename) begin # pass flag in as Rails.env.production? @client = Bunny.new(url) if flag @client = Bunny.new if !flag @client.start # msg= "client inspect #{@client.inspect}" # logger.info msg rescue Bunny::PossibleAuthenticationFailureError => e puts "Could not authenticate " msg= "logger could not authenticate #{e.message}" logger.info msg end @channel = @client.create_channel @queue = @channel.queue(queuename) msg= "set up active MQ on #{queuename}" logger.info msg end |
#start(config) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/estorm-message-processor/base.rb', line 68 def start(config) setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename]) # Run EventMachine in loop so we can reconnect when the SMSC drops our connection. msg= "Connecting to bunny #{config.inspect} environment #{config.inspect}" logger.info msg loop do msg= "[*] Waiting for messages in #{@queue.name}. blocking is #{config[:blocking]}" logger.info msg msg_count =@queue. consumer_count =@queue.consumer_count msg = "queue status for queue #{config[:queuename]} message count: #{msg_count} consumers: #{consumer_count}" logger.info msg @queue.subscribe(:block => config[:blocking]) do |delivery_info, properties, body| (delivery_info,properties,body) # cancel the consumer to exit #delivery_info.consumer.cancel end end msg= "Disconnected. Reconnecting in 5 seconds.." logger.info msg #puts msg tear_down_bunny sleep 1 setup_bunny_communications sleep 4 end |
#tear_down_bunny ⇒ Object
62 63 64 65 66 |
# File 'lib/estorm-message-processor/base.rb', line 62 def tear_down_bunny @client.close if @client!=nil msg= "closing bunny" logger.info msg end |