freddy 0.6.3 → 0.7.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
2
  SHA1:
3
- metadata.gz: 8f97109147edff0d5b3632c66652601b61c6c476
4
- data.tar.gz: f2d777e287b18015d886646957f622310feb2042
3
+ metadata.gz: 97120d29c1d86841e5dfc5158c31f14d54336387
4
+ data.tar.gz: 874dbaf996a7c8b77a6311e8689c991db17ecb9b
5
5
  SHA512:
6
- metadata.gz: 699e54d1b6a0fbde8c0bdde435b0177984ff3b0a80ad9f1d5698a98ef75ba32798475fda4cf16cdeb38e9ff7abebaac33347f2226ef1285dc7fe99dac09438ed
7
- data.tar.gz: 8179925e34bd321be85ba9219513f7279c57b525efcea941beb5584fe6bfda0af4aa4ed149f427645969ee3f51c4babaff497152fe01c4f23783c041de13e01f
6
+ metadata.gz: b88611a8cfde225622dba6b36d024732f5eaf6d436cd933262d9e2dafd76f412cc535f0e0bc6ea6a8445c2270cfd17b99a3c910448e7fdf61bbed6fa02740e77
7
+ data.tar.gz: 0346023d9e030b033e32b14322694ed16c4c14fe465cf7d93f54d907308b8799aa64f493cfe36cecca04cb93da40c771008bc751e7fc0b172707605d14dc6b33
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  else
9
9
  spec.name = "freddy"
10
10
  end
11
- spec.version = '0.6.3'
11
+ spec.version = '0.7.0'
12
12
  spec.authors = ["Urmas Talimaa"]
13
13
  spec.email = ["urmas.talimaa@gmail.com"]
14
14
  spec.description = %q{Messaging API}
@@ -90,6 +90,10 @@ class Freddy
90
90
  # @param [String] pattern
91
91
  # the destination pattern. Use `#` wildcard for matching 0 or more words.
92
92
  # Use `*` to match exactly one word.
93
+ # @param [Hash] options
94
+ # @option options [String] :group
95
+ # only one of the listeners in given group will receive a message. All
96
+ # listeners will receive a message if the group is not specified.
93
97
  #
94
98
  # @yield [message] Yields received message to the block
95
99
  #
@@ -99,9 +103,9 @@ class Freddy
99
103
  # freddy.tap_into 'notifications.*' do |message|
100
104
  # puts "Notification showed #{message.inspect}"
101
105
  # end
102
- def tap_into(pattern, &callback)
106
+ def tap_into(pattern, options = {}, &callback)
103
107
  @logger.debug "Tapping into messages that match #{pattern}"
104
- @tap_into_consumer.consume(pattern, @connection.create_channel, &callback)
108
+ @tap_into_consumer.consume(pattern, @connection.create_channel, options, &callback)
105
109
  end
106
110
 
107
111
  # Sends a message to given destination
@@ -6,8 +6,8 @@ class Freddy
6
6
  @consume_thread_pool = consume_thread_pool
7
7
  end
8
8
 
9
- def consume(pattern, channel, &block)
10
- queue = create_queue(pattern, channel)
9
+ def consume(pattern, channel, options, &block)
10
+ queue = create_queue(pattern, channel, options)
11
11
 
12
12
  consumer = queue.subscribe do |delivery|
13
13
  process_message(queue, delivery, &block)
@@ -18,12 +18,18 @@ class Freddy
18
18
 
19
19
  private
20
20
 
21
- def create_queue(pattern, channel)
21
+ def create_queue(pattern, channel, group: nil)
22
22
  topic_exchange = channel.topic(Freddy::FREDDY_TOPIC_EXCHANGE_NAME)
23
23
 
24
- channel
25
- .queue('', exclusive: true)
26
- .bind(topic_exchange, routing_key: pattern)
24
+ if group
25
+ channel
26
+ .queue("groups.#{group}")
27
+ .bind(topic_exchange, routing_key: pattern)
28
+ else
29
+ channel
30
+ .queue('', exclusive: true)
31
+ .bind(topic_exchange, routing_key: pattern)
32
+ end
27
33
  end
28
34
 
29
35
  def process_message(queue, delivery, &block)
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'hamster/experimental/mutable_set'
3
+
4
+ describe 'Tapping into with group identifier' do
5
+ let(:deliverer) { Freddy.build(logger, config) }
6
+ let(:responder1) { Freddy.build(logger, config) }
7
+ let(:responder2) { Freddy.build(logger, config) }
8
+
9
+ let(:destination) { random_destination }
10
+
11
+ after { [deliverer, responder1, responder2].each(&:close) }
12
+
13
+ it 'receives a message once' do
14
+ msg_counter = Hamster::MutableSet[]
15
+
16
+ group_id = arbitrary_id
17
+ responder1.tap_into(destination, group: group_id) {|msg| msg_counter << 'r1' }
18
+ responder2.tap_into(destination, group: group_id) {|msg| msg_counter << 'r2' }
19
+ deliverer.deliver(destination, {})
20
+
21
+ default_sleep
22
+ expect(msg_counter.count).to eq(1)
23
+ end
24
+ end
@@ -29,6 +29,10 @@ def random_destination
29
29
  SecureRandom.hex
30
30
  end
31
31
 
32
+ def arbitrary_id
33
+ SecureRandom.hex
34
+ end
35
+
32
36
  def default_sleep
33
37
  sleep 0.05
34
38
  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: 0.6.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urmas Talimaa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,6 +129,7 @@ files:
129
129
  - spec/integration/concurrency_spec.rb
130
130
  - spec/integration/logging_spec.rb
131
131
  - spec/integration/reply_spec.rb
132
+ - spec/integration/tap_into_with_group_spec.rb
132
133
  - spec/spec_helper.rb
133
134
  homepage:
134
135
  licenses:
@@ -164,4 +165,5 @@ test_files:
164
165
  - spec/integration/concurrency_spec.rb
165
166
  - spec/integration/logging_spec.rb
166
167
  - spec/integration/reply_spec.rb
168
+ - spec/integration/tap_into_with_group_spec.rb
167
169
  - spec/spec_helper.rb