freddy 0.3.2 → 0.3.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
  SHA1:
3
- metadata.gz: cca77c9b3fbbe1d36a577b1f83dac5403d622951
4
- data.tar.gz: 173f636703aa687c57ab451739736aa55e082021
3
+ metadata.gz: 0d677aed926ebfba37c90931e9cf1945e68b9b25
4
+ data.tar.gz: cf670f4b31d6d15434edf9f53876cf447f6a4b5a
5
5
  SHA512:
6
- metadata.gz: 6eb122206afd0ed15c142b8b70a63f68501033be27e54cc4c459f7f028daf03bf9b697efd46bea521348ce38e04c5f59b936d0e0174cda572499b26456e0116c
7
- data.tar.gz: 388f18d7af6a373c9952a4a36b2e4a32ccefa78ff160511993da9b18f6b4b06a527036ab648f63230d06bdf36ee644be5b2a4bf6fb0f9444bcc6f7595acc56ed
6
+ metadata.gz: 71e4c1cfe3a93a877fd05f04962c2c63b14e9bf9d5b14bbef0657855e649d30aa90c152c224d059030932e98c5e7b80c7474cf8238eb6425965ed138f9d62837
7
+ data.tar.gz: 2f84c367f1b5d2bfb6108962343c92ef8dc160479bd79d14b1bdf166ef6f4fa9608a5a71e9299664a9b00b09cab1102f2e1b93c859d383544099ac2c27da1e8b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- freddy (0.3.2)
4
+ freddy (0.3.3)
5
5
  bunny (= 1.6.3)
6
6
  hamster (~> 1.0.1.pre.rc3)
7
7
  symbolizer
data/README.md CHANGED
@@ -145,7 +145,7 @@ The underlying bunny implementation uses 1 responder thread by default. This mea
145
145
 
146
146
  This is especially devious when using `deliver_with_response` in a responder because `deliver_with_response` creates a new anonymous responder which will not receive the response if the parent responder uses a sleep call.
147
147
 
148
- To resolve this problem *freddy* uses 4 responder threads by default (configurable by `responder_thread_count`). Note that this means that ordered message processing is not guaranteed by default. Read more from <http://rubybunny.info/articles/concurrency.html>.
148
+ To resolve this problem *freddy* creates separate threads for processing. Read more from <http://rubybunny.info/articles/concurrency.html>.
149
149
 
150
150
  ## Credits
151
151
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "freddy"
7
- spec.version = '0.3.2'
7
+ spec.version = '0.3.3'
8
8
  spec.authors = ["Urmas Talimaa"]
9
9
  spec.email = ["urmas.talimaa@gmail.com"]
10
10
  spec.description = %q{Messaging API}
@@ -50,7 +50,7 @@ class Freddy
50
50
  bunny = Bunny.new(bunny_config)
51
51
  bunny.start
52
52
 
53
- channel = bunny.create_channel(nil, bunny_config[:responder_thread_count] || 4)
53
+ channel = bunny.create_channel
54
54
  new(channel, logger)
55
55
  end
56
56
 
@@ -21,9 +21,11 @@ class Freddy
21
21
 
22
22
  def consume_from_queue(queue, options = {}, &block)
23
23
  consumer = queue.subscribe options do |delivery_info, properties, payload|
24
- parsed_payload = parse_payload(payload)
25
- log_receive_event(queue.name, parsed_payload)
26
- block.call parsed_payload, Delivery.new(delivery_info, properties)
24
+ Thread.new do
25
+ parsed_payload = parse_payload(payload)
26
+ log_receive_event(queue.name, parsed_payload)
27
+ block.call parsed_payload, Delivery.new(delivery_info, properties)
28
+ end
27
29
  end
28
30
  @logger.debug "Consuming messages on #{queue.name}"
29
31
  ResponderHandler.new consumer, @channel
@@ -32,7 +34,9 @@ class Freddy
32
34
  def tap_into(pattern, &block)
33
35
  queue = @channel.queue("", exclusive: true).bind(@topic_exchange, routing_key: pattern)
34
36
  consumer = queue.subscribe do |delivery_info, properties, payload|
35
- block.call parse_payload(payload), delivery_info.routing_key
37
+ Thread.new do
38
+ block.call parse_payload(payload), delivery_info.routing_key
39
+ end
36
40
  end
37
41
  @logger.debug "Tapping into messages that match #{pattern}"
38
42
  ResponderHandler.new consumer, @channel
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Concurrency' do
4
+ let(:freddy) { Freddy.build(logger, config) }
5
+
6
+ it 'supports nested calls in #respond_to' do
7
+ freddy.respond_to 'Concurrency1' do |payload, msg_handler|
8
+ begin
9
+ result = freddy.deliver_with_response 'Concurrency2', msg: 'noop'
10
+ msg_handler.success(result)
11
+ rescue Freddy::ErrorResponse => e
12
+ msg_handler.error(e.response)
13
+ end
14
+ end
15
+
16
+ freddy.respond_to 'Concurrency2' do |payload, msg_handler|
17
+ begin
18
+ result = freddy.deliver_with_response 'Concurrency3', msg: 'noop'
19
+ msg_handler.success(result)
20
+ rescue Freddy::ErrorResponse => e
21
+ msg_handler.error(e.response)
22
+ end
23
+ end
24
+
25
+ freddy.respond_to 'Concurrency3' do |payload, msg_handler|
26
+ msg_handler.success({from: 'Concurrency3'})
27
+ end
28
+
29
+ result =
30
+ begin
31
+ freddy.deliver_with_response 'Concurrency1', msg: 'noop'
32
+ rescue Freddy::ErrorResponse => e
33
+ e.response
34
+ end
35
+
36
+ expect(result).to eq(from: 'Concurrency3')
37
+ end
38
+
39
+ it 'supports nested calls in #tap_into' do
40
+ received1 = false
41
+ received2 = false
42
+
43
+ freddy.tap_into 'concurrency.*.queue1' do
44
+ result = freddy.deliver_with_response 'TapConcurrency', msg: 'noop'
45
+ expect(result).to eq(from: 'TapConcurrency')
46
+ received1 = true
47
+ end
48
+
49
+ freddy.respond_to 'TapConcurrency' do |payload, msg_handler|
50
+ msg_handler.success({from: 'TapConcurrency'})
51
+ received2 = true
52
+ end
53
+
54
+ freddy.deliver 'concurrency.q.queue1', msg: 'noop'
55
+
56
+ wait_for { received1 && received2 }
57
+
58
+ expect(received1).to be(true)
59
+ expect(received2).to be(true)
60
+ end
61
+ 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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urmas Talimaa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - spec/freddy/message_handler_spec.rb
115
115
  - spec/freddy/request_spec.rb
116
116
  - spec/freddy/responder_handler_spec.rb
117
+ - spec/integration/concurrency_spec.rb
117
118
  - spec/integration/logging_spec.rb
118
119
  - spec/spec_helper.rb
119
120
  homepage:
@@ -146,5 +147,6 @@ test_files:
146
147
  - spec/freddy/message_handler_spec.rb
147
148
  - spec/freddy/request_spec.rb
148
149
  - spec/freddy/responder_handler_spec.rb
150
+ - spec/integration/concurrency_spec.rb
149
151
  - spec/integration/logging_spec.rb
150
152
  - spec/spec_helper.rb