freddy 1.5.0 → 1.6.0

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
- SHA1:
3
- metadata.gz: b88342f4abad123fd8c0d118482a9b4337d2456b
4
- data.tar.gz: 7c951d5e3a6256216aedc40618ecf72ba13f2e1e
2
+ SHA256:
3
+ metadata.gz: c2c342119c1a4c330673258a8c5dbeb5d33ea15bc06ddbe261e1cfb8485829fe
4
+ data.tar.gz: a66de9b5b4f97ff58e1f8a321daa5846526a68c41fb4d7e4121d0c90fed55101
5
5
  SHA512:
6
- metadata.gz: 464832871f2743a4af000d6a37e65e0f1058c0f1e0b06714b273b481fc9c90c09ff35c7199fb083c3a959944cf194a7e5744aabc30aaddf8815037be2f1627d2
7
- data.tar.gz: 4945d3dd2d281746ce4a239aa2fd48a5bb92fe097a0773ba584b13d2252381743813ec4c579c2f23b58ff2f4d74e2f04cae763f74bec1f971c2acf4cb117ab28
6
+ metadata.gz: fa9f61272f5f792c2e944ad39d2604693a14950d0a7bef43f3fcba8d3865ce0ff992877bc27427d66aa29314e1b6ae1fc6acde15e1f513169fbe49a1cc1c496a
7
+ data.tar.gz: '0678e4121e3eaaa5669d5d5ef4963c91a31ace9f605ecaf1050136f98a3df1c3b6e24b6709e5abaed8b530c21f89695b18d6ed7c5ab7f6543e47e254abd01b18'
data/freddy.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  else
9
9
  'freddy'
10
10
  end
11
- spec.version = '1.5.0'
11
+ spec.version = '1.6.0'
12
12
  spec.authors = ['Salemove TechMovers']
13
13
  spec.email = ['techmovers@salemove.com']
14
14
  spec.description = 'Messaging API'
@@ -34,7 +34,7 @@ class Freddy
34
34
  @channel = channel
35
35
  end
36
36
 
37
- def_delegators :@channel, :topic, :default_exchange, :consumers, :acknowledge
37
+ def_delegators :@channel, :topic, :default_exchange, :consumers, :acknowledge, :reject
38
38
 
39
39
  def queue(*args)
40
40
  Queue.new(@channel.queue(*args))
@@ -33,7 +33,7 @@ class Freddy
33
33
  @channel = channel
34
34
  end
35
35
 
36
- def_delegators :@channel, :topic, :default_exchange, :consumers, :acknowledge
36
+ def_delegators :@channel, :topic, :default_exchange, :consumers, :acknowledge, :reject
37
37
 
38
38
  def queue(*args)
39
39
  Queue.new(@channel.queue(*args))
@@ -12,6 +12,8 @@ class Freddy
12
12
  @pattern = pattern
13
13
  @channel = channel
14
14
  @options = options
15
+
16
+ raise 'Do not use durable queues without specifying a group' if durable? && !group
15
17
  end
16
18
 
17
19
  def consume(&block)
@@ -28,11 +30,10 @@ class Freddy
28
30
 
29
31
  def create_queue
30
32
  topic_exchange = @channel.topic(Freddy::FREDDY_TOPIC_EXCHANGE_NAME)
31
- group = @options.fetch(:group, nil)
32
33
 
33
34
  if group
34
35
  @channel
35
- .queue("groups.#{group}")
36
+ .queue("groups.#{group}", durable: durable?)
36
37
  .bind(topic_exchange, routing_key: @pattern)
37
38
  else
38
39
  @channel
@@ -54,12 +55,36 @@ class Freddy
54
55
  force_follows_from: true)
55
56
 
56
57
  yield delivery.payload, delivery.routing_key
58
+
59
+ @channel.acknowledge(delivery.tag)
60
+ rescue StandardError
61
+ case on_exception
62
+ when :reject
63
+ @channel.reject(delivery.tag)
64
+ when :requeue
65
+ @channel.reject(delivery.tag, true)
66
+ else
67
+ @channel.acknowledge(delivery.tag)
68
+ end
69
+
70
+ raise
57
71
  ensure
58
- @channel.acknowledge(delivery.tag, false)
59
72
  scope.close
60
73
  end
61
74
  end
62
75
  end
76
+
77
+ def group
78
+ @options.fetch(:group, nil)
79
+ end
80
+
81
+ def durable?
82
+ @options.fetch(:durable, false)
83
+ end
84
+
85
+ def on_exception
86
+ @options.fetch(:on_exception, :ack)
87
+ end
63
88
  end
64
89
  end
65
90
  end
data/lib/freddy.rb CHANGED
@@ -111,6 +111,15 @@ class Freddy
111
111
  # @option options [String] :group
112
112
  # only one of the listeners in given group will receive a message. All
113
113
  # listeners will receive a message if the group is not specified.
114
+ # @option options [Boolean] :durable
115
+ # Should the consumer queue be durable? Default is `false`. This option can
116
+ # be used only in combination with option `:group`.
117
+ # @option options [Boolean] :on_exception
118
+ # Defines consumer's behaviour when the callback fails to process a message
119
+ # and raises an exception. Can be one of `:ack`, `:reject` or `:requeue`.
120
+ # `:ack` simply acknowledges the message and re-raises the exception. `:reject`
121
+ # rejects the message without requeueing it. `:requeue` rejects the message with
122
+ # `requeue` flag.
114
123
  #
115
124
  # @yield [message] Yields received message to the block
116
125
  #
@@ -10,6 +10,11 @@ describe 'Tapping into with group identifier' do
10
10
 
11
11
  after { [deliverer, responder1, responder2].each(&:close) }
12
12
 
13
+ it 'raises an exception if option :durable is provided without group' do
14
+ expect { responder1.tap_into(destination, durable: true) }
15
+ .to raise_error(RuntimeError)
16
+ end
17
+
13
18
  it 'receives a message once' do
14
19
  msg_counter = Hamster::MutableSet[]
15
20
 
@@ -21,4 +26,18 @@ describe 'Tapping into with group identifier' do
21
26
  default_sleep
22
27
  expect(msg_counter.count).to eq(1)
23
28
  end
29
+
30
+ it 'can requeue message on exception' do
31
+ counter = 0
32
+
33
+ responder1.tap_into(destination, group: arbitrary_id, on_exception: :requeue) do
34
+ counter += 1
35
+ raise 'error' if counter == 1
36
+ end
37
+
38
+ deliverer.deliver(destination, {})
39
+
40
+ wait_for { counter == 2 }
41
+ expect(counter).to eq(2)
42
+ end
24
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.6.11
172
+ rubygems_version: 2.7.6
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: API for inter-application messaging supporting acknowledgements and request-response