msgr 0.11.0.rc1 → 0.11.0.rc2

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: 5d96720fd1623cf5da1206a59f5d3bdd212cc051
4
- data.tar.gz: 78025a148dd7f43c406f0a9aeca9d8a7726b3758
3
+ metadata.gz: 1702792de09a7bdb79ac0cc05e7cdc89e00ed8ed
4
+ data.tar.gz: 138ef85e022e7346efc4e2960002c0b2f8bc3a62
5
5
  SHA512:
6
- metadata.gz: d3eb940e3e0e9b8db4c0ee314fd5d162fd4c07948b5b7692ef6e7f7949eb26297352f2823b0b539aafefa214d1d3e11ec00ca7752c31eee2392db7dd69802e66
7
- data.tar.gz: 5af7a695ac861ba16399acd1f0f3735209dbc051307a66b281ef154540ae020e4e107a3e31a292d53feb4fd32bdf09f2f79d4488261a032f3bfc9367d8f1dddd
6
+ metadata.gz: 3683e6cdcf37754eb553ceaa6db9c40c0837dd48b2702a619a6639a76a4ecc72d6f044bfa2c8cf26e856d1a47d55aa1471bd8896390fdcf9930ddf1358de4c29
7
+ data.tar.gz: fc5e451ecd1b6f983ea41f5b6ba06970186183f5efc178e17a071edb50f7346059f80c73d660e5eacd8edfb9e0af206b9b192b659eed26c5ae96b11aff815cf9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.rc2
4
+
5
+ * Add nack for messages when an error is rescued by dispatcher
6
+
7
+ ## 0.11.rc1
8
+
9
+ * Add pool_class config to override pool classes used by dispatcher
10
+
11
+ ## 0.4 - 0.10
12
+
13
+ * Some lost history due to several crises
14
+
3
15
  ## 0.4.1
4
16
 
5
17
  * Fix bug with empty routes on client start
@@ -103,6 +103,11 @@ module Msgr
103
103
  log(:debug) { "Acked message: #{delivery_tag}" }
104
104
  end
105
105
 
106
+ def nack(delivery_tag)
107
+ channel.nack delivery_tag, false, true
108
+ log(:debug) { "Nacked message: #{delivery_tag}" }
109
+ end
110
+
106
111
  def reject(delivery_tag, requeue = true)
107
112
  channel.reject delivery_tag, requeue
108
113
  log(:debug) { "Rejected message: #{delivery_tag}" }
@@ -34,6 +34,8 @@ module Msgr
34
34
  # Acknowledge message unless it is already acknowledged.
35
35
  message.ack unless message.acked?
36
36
  rescue => error
37
+ message.nack unless message.acked?
38
+
37
39
  log(:error) do
38
40
  "Dispatcher error: #{error.class.name}: #{error}\n" +
39
41
  error.backtrace.join("\n")
data/lib/msgr/message.rb CHANGED
@@ -37,7 +37,19 @@ module Msgr
37
37
  def ack
38
38
  unless acked?
39
39
  @acked = true
40
- @connection.ack(delivery_info.delivery_tag)
40
+ @connection.ack delivery_info.delivery_tag
41
+ end
42
+ end
43
+
44
+ # Send negative message acknowledge to broker unless
45
+ # message is already acknowledged.
46
+ #
47
+ # @api public
48
+ #
49
+ def nack
50
+ unless acked?
51
+ @acked = true
52
+ @connection.nack delivery_info.delivery_tag
41
53
  end
42
54
  end
43
55
  end
data/lib/msgr/version.rb CHANGED
@@ -3,7 +3,7 @@ module Msgr
3
3
  MAJOR = 0
4
4
  MINOR = 11
5
5
  PATCH = 0
6
- STAGE = 'rc1'
6
+ STAGE = 'rc2'
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
8
8
 
9
9
  def self.to_s; STRING end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestConsumer < Msgr::Consumer
3
+ class DispatcherTestConsumer < Msgr::Consumer
4
4
  def index
5
5
  puts "<<< #{payload}"
6
6
  end
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  describe Msgr::Dispatcher do
10
10
  let(:dispatcher) { described_class.new max: 1 }
11
- let(:consumer) { 'TestConsumer' }
11
+ let(:consumer) { 'DispatcherTestConsumer' }
12
12
  let(:route) do
13
13
  double(:route).tap do |t|
14
14
  allow(t).to receive(:consumer).and_return consumer
@@ -36,7 +36,7 @@ describe Msgr::Dispatcher do
36
36
 
37
37
  before do
38
38
  expect_any_instance_of(::Concurrent::CachedThreadPool).to receive(:post).and_return { |m, &block| block.call m}
39
- expect_any_instance_of(TestConsumer).to receive(:index)
39
+ expect_any_instance_of(DispatcherTestConsumer).to receive(:index)
40
40
  end
41
41
 
42
42
  it 'should consume message' do
@@ -1,8 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- class TestConsumer < Msgr::Consumer
3
+ class Receiver
4
+ end
5
+
6
+ #
7
+ class MsgrTestConsumer < Msgr::Consumer
4
8
  def index
5
- puts "<<< #{payload}"
9
+ Receiver.index
10
+ end
11
+
12
+ def error
13
+ Receiver.error
6
14
  end
7
15
  end
8
16
 
@@ -12,11 +20,13 @@ describe Msgr do
12
20
  Msgr.logger.level = Logger::Severity::DEBUG if Msgr.logger
13
21
  end
14
22
 
15
- let(:client) { Msgr::Client.new size: 1, prefix: SecureRandom.hex(32) }
23
+ let(:queue) { Queue.new }
24
+ let(:client) { Msgr::Client.new size: 1, prefix: SecureRandom.hex(2) }
16
25
 
17
26
  before do
18
27
  client.routes.configure do
19
- route '#', to: 'test#index'
28
+ route 'test.index', to: 'msgr_test#index'
29
+ route 'test.error', to: 'msgr_test#error'
20
30
  end
21
31
 
22
32
  client.start
@@ -27,10 +37,19 @@ describe Msgr do
27
37
  end
28
38
 
29
39
  it 'should dispatch published methods to consumer' do
30
- expect_any_instance_of(TestConsumer).to receive(:index).seconds.and_call_original
40
+ expect(Receiver).to receive(:index) { queue << :end }
41
+
42
+ client.publish 'Payload', to: 'test.index'
43
+
44
+ Timeout::timeout(4) { queue.pop }
45
+ end
46
+
47
+ it 'should redelivery failed messages' do
48
+ expect(Receiver).to receive(:error).ordered.and_raise RuntimeError
49
+ expect(Receiver).to receive(:error).ordered { queue << :end }
31
50
 
32
- client.publish 'Payload', to: 'routing.key'
51
+ client.publish 'Payload', to: 'test.error'
33
52
 
34
- sleep 4
53
+ Timeout::timeout(4) { queue.pop }
35
54
  end
36
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0.rc1
4
+ version: 0.11.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen