eventbus 0.27 → 0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,8 +6,6 @@ require 'socket'
6
6
  require 'stomp'
7
7
  module StompConnectionDriver
8
8
 
9
- @@StompConnector_Connection = nil
10
-
11
9
  def connection_driver_initialize
12
10
 
13
11
  end
@@ -76,15 +74,15 @@ module StompConnectionDriver
76
74
  }
77
75
 
78
76
  # If we never opened one, or if it's closed and not reliable, then open a new connection.
79
- if @@StompConnector_Connection.nil? || (@@StompConnector_Connection.closed? && ! @@StompConnector_Connction.reliable?)
77
+ if Thread.current[:stomp_connection].nil? || (Thread.current[:stomp_connection].closed? && ! Thread.current[:stomp_connection].reliable?)
80
78
  EventBus.logger.info("Connecting to STOMP with options: #{opts.to_s}")
81
- @@StompConnector_Connection = Stomp::Client.new(opts)
79
+ Thread.current[:stomp_connection] = Stomp::Client.new(opts)
82
80
  end
83
81
 
84
82
  # I'm not sure whether we should sleep here if the connection is closed?() but is reliable?()
85
83
  # Assuming that the connection will do the right thing and punting until I find out different.
86
84
 
87
- return @@StompConnector_Connection
85
+ return Thread.current[:stomp_connection]
88
86
 
89
87
  end
90
88
 
@@ -125,7 +123,7 @@ module StompConnectionDriver
125
123
  # and only take blocks of one message rather than claiming large blocks. These assumptions should become
126
124
  # configurable at some point, but for now it's not really a concern.
127
125
 
128
- client.subscribe(queue_name, {"activemq.prefetchSize" => 1, "activemq.exclusive" => false}) do |msg|
126
+ client.subscribe(queue_name, {"activemq.prefetchSize".to_sym => 1, :exclusive => "false"}) do |msg|
129
127
  yield msg.body
130
128
  end
131
129
 
@@ -10,7 +10,7 @@ class Message
10
10
 
11
11
  attr_reader :data
12
12
 
13
- def initialize(application_id)
13
+ def initialize(application_id = EventBus.application_id)
14
14
 
15
15
  raise "No application ID specified!" if application_id.nil?
16
16
 
@@ -49,32 +49,34 @@ class Service
49
49
  def start ( opts = {} )
50
50
 
51
51
  max_workers = opts.delete(:max_workers) || 5
52
+ async_service = opts.delete(:async_service) || false
52
53
 
53
54
  opts[:system_queue] = @system_process
54
55
  opts[:global_process] = @global_process
55
56
 
56
57
  queue_name = Queue.calc_name(listen_queue, @application_id, EventBus.PROD_LEVEL, opts)
57
58
 
58
- watch_queue(queue_name) do |message|
59
-
60
- # The +2 stuff is because the main thread counts in the list, even though it's not a "worker" thread.
61
- # What makes it worse is that, depending on the broker connector, watch_queue may also start a thread.
62
- # With this implementation, that extra thread (e.g. with the stomp connector) would count in this.
63
- # Bottom line is allow a little wiggle room with the :max_workers. Don't tighten down the threads too much
64
- # for now.
65
- while (Thread.list.length >= max_workers + 2) do
66
- sleep 0.25
67
- end
68
-
69
- Thread.new do
70
- process_message_wrapper message
59
+ # I tried to have a single connection dole out to a worker pool, but I was having
60
+ # weird issues which I think were due to race conditions on the broker connections.
61
+ # Just spin off threads prior to starting connections so every thread has a private
62
+ # connection.
63
+
64
+ (1..max_workers).each do
65
+ Thread.new {
66
+ watch_queue(queue_name) do |message|
67
+ process_message_wrapper message
68
+ end
69
+ }
70
+ end
71
+
72
+ # If async_service is false, we'll
73
+ # just return and leave it up to the caller to not
74
+ # exit too soon.
75
+
76
+ unless async_service
77
+ loop do
78
+ sleep 6000
71
79
  end
72
-
73
- end
74
-
75
- # Just sleep in the main thread. Nothing going on here anymore.
76
- loop do
77
- sleep 6000
78
80
  end
79
81
 
80
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventbus
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.27'
4
+ version: '0.28'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-13 00:00:00.000000000 Z
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amqp