Class: Loops::Queue
Instance Attribute Summary
Attributes inherited from Base
#config, #name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #logger, #shutdown?, #with_lock, #with_period_of
Constructor Details
This class inherits a constructor from Loops::Base
Class Method Details
.check_dependencies ⇒ Object
11
12
13
|
# File 'lib/loops/queue.rb', line 11
def self.check_dependencies
raise "No stomp gem installed!" unless defined?(Stomp::Client)
end
|
Instance Method Details
#process_message(msg) ⇒ Object
52
53
54
|
# File 'lib/loops/queue.rb', line 52
def process_message(msg)
raise "This method process_message(msg) should be overriden in the loop class!"
end
|
#run ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/loops/queue.rb', line 15
def run
create_client
config['queue_name'] ||= "/queue/loops/#{name}"
config['prefetch_size'] ||= 1
debug "Subscribing for the queue #{config['queue_name']}..."
= { :ack => :client }
["activemq.prefetchSize"] = config['prefetch_size'] if config['prefetch_size']
@total_served = 0
@client.subscribe(config['queue_name'], ) do |msg|
begin
if config['action_timeout']
timeout(config['action_timeout']) { process_message(msg) }
else
process_message(msg)
end
@client.acknowledge(msg)
@total_served += 1
if config['max_requests'] && @total_served >= config['max_requests'].to_i
disconnect_client_and_exit
end
rescue Exception => e
error "Exception from process message! We won't be ACKing the message."
error "Details: #{e} at #{e.backtrace.first}"
disconnect_client_and_exit
end
end
@client.join
rescue Exception => e
error "Closing queue connection because of exception: #{e} at #{e.backtrace.first}"
disconnect_client_and_exit
end
|