action_subscriber 5.0.2 → 5.0.3.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c2ce0b5789687cc8b7eaded44e031397e8c1dab
4
- data.tar.gz: 65120e0f0d0ab4a61e61cd345328e61edbd26437
3
+ metadata.gz: 0ca7cccf89023f06ddaa142cc7d9ad152857dff0
4
+ data.tar.gz: f8c77d9e20ec595946f9bb93e58b316007726ed0
5
5
  SHA512:
6
- metadata.gz: aa163dea8481ad2f701970bedc7f9675f65de5b6b0a62824c07926075f724f7f0b75308074ce22b9ea55ad3513e9cbc4a13aacf5cbd32a6b37e3964674db6e49
7
- data.tar.gz: 02f818f0a770f553e5b172bfb031c8c6b3c662ededa7b5f34020e98a90dbad5d1dd451a59a1fdf18f34a6efd03b9d89b0174d7e55975be49e696da49f826bc31
6
+ metadata.gz: e2b75379c1de445dfe3febfdd980b6fcbca36ec3b6ea968bda1f5f8c17deee0f2e1af98e51f5a0bcbf022041f47ba0621c8e7efc6885c46dc22e66e79e01a772
7
+ data.tar.gz: 26f142393ae73dcc8dbddd96150e65d87793265e9c4f9f42052e933de9b1a4c7f724d2994a939c938bde5081ec86fca8ca1315012ac54504057bb7dd5a6eba71
@@ -9,9 +9,10 @@ module ActionSubscriber
9
9
  !!@_at_least_once
10
10
  end
11
11
 
12
- def at_most_once!
12
+ def at_most_once!(ack_every_n_messages = 1)
13
13
  @_acknowledge_messages = true
14
14
  @_at_most_once = true
15
+ @_ack_every_n_messages = ack_every_n_messages
15
16
  end
16
17
 
17
18
  def at_most_once?
@@ -54,6 +55,10 @@ module ActionSubscriber
54
55
  !!@_manual_acknowedgement
55
56
  end
56
57
 
58
+ def ack_every_n_messages
59
+ @_ack_every_n_messages || 1
60
+ end
61
+
57
62
  def no_acknowledgement!
58
63
  @_acknowledge_messages = false
59
64
  end
@@ -131,6 +136,41 @@ module ActionSubscriber
131
136
  end
132
137
  end
133
138
 
139
+ def _run_action_at_most_once_multiple_with_filters(env, action)
140
+ processed_acknowledgement = false
141
+ rejected_message = false
142
+ if env.delivery_tag % ack_every_n_messages == 0 # tags are monotonically increasing integers
143
+ processed_acknowledgement = env.acknowledge(true)
144
+ else
145
+ processed_acknowledgement = true # we are not acknowledging on this message and will wait for the offset to acknowledge
146
+ end
147
+
148
+ _run_action_with_filters(env, action)
149
+ ensure
150
+ rejected_message = env.reject if !processed_acknowledgement
151
+
152
+ if !rejected_message && !processed_acknowledgement
153
+ $stdout << <<-UNREJECTABLE
154
+ CANNOT ACKNOWLEDGE OR REJECT THE MESSAGE
155
+
156
+ This is a exceptional state for ActionSubscriber to enter and puts the current
157
+ Process in the position of "I can't get new work from RabbitMQ, but also
158
+ can't acknowledge or reject the work that I currently have" ... While rare
159
+ this state can happen.
160
+
161
+ Instead of continuing to try to process the message ActionSubscriber is
162
+ sending a Kill signal to the current running process to gracefully shutdown
163
+ so that the RabbitMQ server will purge any outstanding acknowledgements. If
164
+ you are running a process monitoring tool (like Upstart) the Subscriber
165
+ process will be restarted and be able to take on new work.
166
+
167
+ ** Running a process monitoring tool like Upstart is recommended for this reason **
168
+ UNREJECTABLE
169
+
170
+ Process.kill(:TERM, Process.pid)
171
+ end
172
+ end
173
+
134
174
  def _run_action_at_least_once_with_filters(env, action)
135
175
  processed_acknowledgement = false
136
176
  rejected_message = false
@@ -172,8 +212,10 @@ module ActionSubscriber
172
212
  case
173
213
  when at_least_once?
174
214
  _run_action_at_least_once_with_filters(env, action)
175
- when at_most_once?
215
+ when at_most_once? && ack_every_n_messages <= 1 # Acknowledging every single message
176
216
  _run_action_at_most_once_with_filters(env, action)
217
+ when at_most_once? && ack_every_n_messages > 1 # Acknowledging messages in offset groups (every 10 messages or whatever the offset is)
218
+ _run_action_at_most_once_multiple_with_filters(env, action)
177
219
  else
178
220
  _run_action_with_filters(env, action)
179
221
  end
@@ -7,6 +7,7 @@ module ActionSubscriber
7
7
 
8
8
  attr_reader :action,
9
9
  :content_type,
10
+ :delivery_tag,
10
11
  :encoded_payload,
11
12
  :exchange,
12
13
  :headers,
@@ -40,9 +41,8 @@ module ActionSubscriber
40
41
  @subscriber = subscriber
41
42
  end
42
43
 
43
- def acknowledge
44
+ def acknowledge(acknowledge_multiple_messages = false)
44
45
  fail ::RuntimeError, "you can't acknowledge messages under the polling API" unless @channel
45
- acknowledge_multiple_messages = false
46
46
  @channel.ack(@delivery_tag, acknowledge_multiple_messages)
47
47
  true
48
48
  end
@@ -23,6 +23,11 @@ module ActionSubscriber
23
23
  logger.info " -- queue: #{route.queue}"
24
24
  logger.info " -- routing_key: #{route.routing_key}"
25
25
  logger.info " -- prefetch: #{route.prefetch}"
26
+ if subscriber.at_most_once? && (route.prefetch < subscriber.ack_every_n_messages || subscriber.ack_every_n_messages <= 0)
27
+ # https://www.rabbitmq.com/blog/2011/09/24/sizing-your-rabbits/
28
+ logger.error "ERROR Subscriber has ack_every_n_messages as #{subscriber.ack_every_n_messages} and route has prefetch as #{route.prefetch}"
29
+ fail "prefetch < ack_every_n_messages, deadlock will occur"
30
+ end
26
31
  if route.acknowledgements != subscriber.acknowledge_messages?
27
32
  logger.error "WARNING subscriber has acknowledgements as #{subscriber.acknowledge_messages?} and route has acknowledgements as #{route.acknowledgements}"
28
33
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "5.0.2"
2
+ VERSION = "5.0.3.pre1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.2
4
+ version: 5.0.3.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-12-08 00:00:00.000000000 Z
15
+ date: 2017-12-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -278,9 +278,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
278
  version: '0'
279
279
  required_rubygems_version: !ruby/object:Gem::Requirement
280
280
  requirements:
281
- - - ">="
281
+ - - ">"
282
282
  - !ruby/object:Gem::Version
283
- version: '0'
283
+ version: 1.3.1
284
284
  requirements: []
285
285
  rubyforge_project:
286
286
  rubygems_version: 2.6.13