istox 0.1.156.2 → 0.1.156.3
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/istox/helpers/publisher.rb +18 -18
- data/lib/istox/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f39e624095d20c469e1e24d3b61448c93f3a796175040e12b23a23814b3620a
|
|
4
|
+
data.tar.gz: 92c47cdde1b2fa375bdfaa328609fe2fab5ac5c8eb259bcf40297f29df6cb88e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7af1cc4e35bb038b358ecde3bebbc27693fb4bab7ec90fbd34a03052ca4f32f8ea5628f0be8b583eaa8fa6f9db18808d69241f4fcd6c024cd0a361e86de031f2
|
|
7
|
+
data.tar.gz: 01e83c80885c937736a6688032503855592ccbb1146e8ab36903031be87b1a02b168e79320178e1203bdb83cc95929d6bbe4a5faf1318b4540d1431ecbe19159
|
data/Gemfile.lock
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
require 'securerandom'
|
|
2
2
|
require 'istox/helpers/logger'
|
|
3
3
|
|
|
4
|
+
class RabbitMQPublishError < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
4
7
|
module Istox
|
|
5
8
|
# Publisher is relying on BunnyBoot to publish message, please make sure BunnyBoot is initalised properly first during runtime.
|
|
6
9
|
class Publisher
|
|
@@ -179,13 +182,7 @@ module Istox
|
|
|
179
182
|
log.debug "Got a returned message info: #{return_info}"
|
|
180
183
|
log.debug "Got a returned message properties: #{properties}"
|
|
181
184
|
log.debug "Got a returned message content: #{content}"
|
|
182
|
-
|
|
183
|
-
::Istox::BunnyBoot.find_trackers("message_id:#{properties[:message_id]}").each do |key|
|
|
184
|
-
log.debug("On_return, update key #{key} in redis on status and retry counter")
|
|
185
|
-
::Istox::BunnyBoot.update_tracker_by_status(key, 2)
|
|
186
|
-
::Istox::BunnyBoot.update_tracker_incr_retry(key)
|
|
187
|
-
end
|
|
188
|
-
=end
|
|
185
|
+
|
|
189
186
|
if properties[:headers] && properties[:headers][:sender]
|
|
190
187
|
@error = Hash.new if @error.nil?
|
|
191
188
|
tid = properties[:headers][:sender]
|
|
@@ -204,7 +201,7 @@ module Istox
|
|
|
204
201
|
end
|
|
205
202
|
|
|
206
203
|
# Handle republish: check and increase retry count
|
|
207
|
-
def republish(ex, options = {}, message)
|
|
204
|
+
def republish(ex, options = {}, message, error)
|
|
208
205
|
options[:headers] = {} if options[:headers].nil?
|
|
209
206
|
|
|
210
207
|
if options[:headers][:republish].nil?
|
|
@@ -213,11 +210,12 @@ module Istox
|
|
|
213
210
|
else
|
|
214
211
|
options[:headers][:republish_count] += 1
|
|
215
212
|
if options[:headers][:republish_count] > 10
|
|
216
|
-
log.
|
|
213
|
+
log.fatal "Already retry to publish for 10 times, and give up retry"
|
|
217
214
|
log.info "Publish options: #{options.inspect}"
|
|
218
215
|
log.info "Publish to exchange: #{ex.name}"
|
|
219
216
|
log.info "Publish payload: #{message.inspect}"
|
|
220
|
-
|
|
217
|
+
|
|
218
|
+
raise RabbitMQPublishError, "Publish fails after retries(10): #{error}"
|
|
221
219
|
end
|
|
222
220
|
end
|
|
223
221
|
|
|
@@ -250,13 +248,13 @@ module Istox
|
|
|
250
248
|
success = ex.channel.wait_for_confirms
|
|
251
249
|
if success
|
|
252
250
|
log.debug("Message confirm success: remove message for #{channel_id}")
|
|
253
|
-
# ::Istox::BunnyBoot.del_tracker_on_channel channel_id
|
|
254
|
-
# republish(ex, options, message)
|
|
255
251
|
if @error.nil? || @error[Thread.current.object_id].nil?
|
|
252
|
+
# republish(ex, options, message, 'simulate errors')
|
|
256
253
|
true
|
|
257
254
|
else
|
|
255
|
+
error = @error[Thread.current.object_id][:return_info][:reply_text]
|
|
258
256
|
@error[Thread.current.object_id] = nil
|
|
259
|
-
republish(ex,options,message)
|
|
257
|
+
republish(ex, options, message, error)
|
|
260
258
|
end
|
|
261
259
|
else
|
|
262
260
|
ex.channel.nacked_set.each do |n|
|
|
@@ -264,18 +262,20 @@ module Istox
|
|
|
264
262
|
# options = ::Istox::BunnyBoot.find_tracker_on_channel(channel_id, n, 'options')
|
|
265
263
|
# options = JSON.parse(options, :symbolize_names => true)
|
|
266
264
|
# options[:delivery_tag] = n
|
|
267
|
-
republish(ex, options, message)
|
|
265
|
+
republish(ex, options, message, 'broker processing fails')
|
|
268
266
|
end
|
|
269
267
|
end
|
|
270
268
|
end
|
|
271
269
|
rescue Bunny::ConnectionClosedError => e
|
|
272
|
-
log.
|
|
270
|
+
log.error "Publish fails due to #{e}"
|
|
273
271
|
# For network related retry, sleep 2 second before retry
|
|
274
272
|
# Because it may take some seconds for automatic recovery of network
|
|
275
273
|
sleep 2
|
|
276
|
-
republish(ex,options,message)
|
|
274
|
+
republish(ex, options, message, e.message)
|
|
275
|
+
rescue RabbitMQPublishError => e
|
|
276
|
+
raise RabbitMQPublishError, e.message
|
|
277
277
|
rescue => e
|
|
278
|
-
log.
|
|
278
|
+
log.error "Publish error happening: #{e.message}"
|
|
279
279
|
|
|
280
280
|
# If the error indicates that the channel is already closed
|
|
281
281
|
# then clear hash @channel and @exchange
|
|
@@ -287,7 +287,7 @@ module Istox
|
|
|
287
287
|
end
|
|
288
288
|
|
|
289
289
|
# Republish msg
|
|
290
|
-
republish(ex, options, message)
|
|
290
|
+
republish(ex, options, message, e.message)
|
|
291
291
|
end
|
|
292
292
|
end
|
|
293
293
|
end
|
data/lib/istox/version.rb
CHANGED