Add a main_thread method to allow for serializing some invocations on the main thread
This wlil help different worker threads perform client acknowledgements or any other STOMP client work, which should be done in the main thread to ensure that we're not stomping on other messages
This commit is contained in:
parent
9bb3079b1f
commit
f90fe9e763
|
@ -21,7 +21,9 @@ class Worker < Stapfen::Worker
|
|||
end
|
||||
|
||||
consume 'jms.topic.foo', {:ack => 'client'} do |message|
|
||||
client.acknowledge(message)
|
||||
main_thread do
|
||||
client.acknowledge(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,9 +29,14 @@ module Stapfen
|
|||
|
||||
def initialize
|
||||
@pool = []
|
||||
@workqueue = Queue.new
|
||||
handle_signals!
|
||||
end
|
||||
|
||||
def main_thread(&block)
|
||||
@workqueue << block
|
||||
end
|
||||
|
||||
def run
|
||||
@client = Stomp::Client.new(self.class.configuration)
|
||||
|
||||
|
@ -49,6 +54,16 @@ module Stapfen
|
|||
# close the connection, and an infinite Client#join call
|
||||
while client.open? do
|
||||
client.join(1)
|
||||
|
||||
until @workqueue.empty?
|
||||
block = @workqueue.pop
|
||||
begin
|
||||
block.call
|
||||
rescue => e
|
||||
puts "Exception! #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
@pool = @pool.select { |t| t.alive? }
|
||||
end
|
||||
rescue Interrupt
|
||||
|
|
Loading…
Reference in New Issue