istox 0.1.156.2 → 0.1.156.3

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
  SHA256:
3
- metadata.gz: 5daed90ec2d88ac9c15ab6829e93b1d91ceec8b3bbf0447e18a322bc23782676
4
- data.tar.gz: 2b952122ec1ecad78de28d15e3bb239d521a7bbfbdf2323dff7407d70538548a
3
+ metadata.gz: 5f39e624095d20c469e1e24d3b61448c93f3a796175040e12b23a23814b3620a
4
+ data.tar.gz: 92c47cdde1b2fa375bdfaa328609fe2fab5ac5c8eb259bcf40297f29df6cb88e
5
5
  SHA512:
6
- metadata.gz: 848726c06a306e5dfc451769f9392bc9c94716b8959da247e71681d4d932cc8fca2e1f8dd5cdded582c198c7bc53cc96dbd3e636c96943152213df4e1184e886
7
- data.tar.gz: 717fe201a3068be826b51cfa008a2d9ecb57f2ceb25bcabf470458d0ed841378c695f2add1a2bcf20a74bb7a37a5721ebbcd6b7ef0006c64f1e31c56a470f944
6
+ metadata.gz: 7af1cc4e35bb038b358ecde3bebbc27693fb4bab7ec90fbd34a03052ca4f32f8ea5628f0be8b583eaa8fa6f9db18808d69241f4fcd6c024cd0a361e86de031f2
7
+ data.tar.gz: 01e83c80885c937736a6688032503855592ccbb1146e8ab36903031be87b1a02b168e79320178e1203bdb83cc95929d6bbe4a5faf1318b4540d1431ecbe19159
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- istox (0.1.156.2)
4
+ istox (0.1.156.3)
5
5
  amazing_print
6
6
  awesome_print
7
7
  binding_of_caller
@@ -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
- =begin
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.info "Already retry to publish for 10 times, and give up retry"
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
- return false
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.debug "Publish fails due to #{e}"
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.debug "Publish error happening: #{e.message}"
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
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.156.2'.freeze
2
+ VERSION = '0.1.156.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: istox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.156.2
4
+ version: 0.1.156.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siong Leng