easy_bunny_rpc 0.1.0.alpha → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c7753440ae7622d08014667722d7d607b5e2ff7
4
- data.tar.gz: d6f58efefd2f73e5f2cc0dea692acae2dc14852d
3
+ metadata.gz: 8ea967e4d8823b80adb2ac43a1e1ab7d96d4d072
4
+ data.tar.gz: c5bf00052c37e0c693682298d9d52be8b939f72a
5
5
  SHA512:
6
- metadata.gz: 605aba5b4e0aa19e103e7e83c7c5cff7483d66fe104fabdf420f1bdab4489d464391e5f057c60376ee1648fbeefecd24a0df92efd1e43b2fed415a259027fa4c
7
- data.tar.gz: 2c53c15a9dd254a7a6a6032faca6e3b13ee23f00a72a24e00adf6620308e02ddc2e3aa3b36e8304a5a565c3b6816fcfb683165d4982818774b7d1ad44ca524ce
6
+ metadata.gz: 9bdf3cca67b828f1ba04254339dc4776f3f998a4421ba22834c43ff20f3a2e1289914f0276e5f7c7da0bb980315ff3cf1b9afd3f12b980e5cdb184b4d73c2ad4
7
+ data.tar.gz: 42109a3a629698e06eeb7d8aeb753be54dc20f48d2174b83b4427a03937d0f163b92fa64a39c83e654b86c7b24ef36ae3be94eb6f4f2ee73bfbfa259d7cb885b
data/README.md CHANGED
@@ -5,24 +5,9 @@ easy\_bunny\_rpc
5
5
  Generic RPC client/worker library handling data serialization built on top of bunny.
6
6
 
7
7
  Example usage
8
- -----
8
+ -------------
9
9
 
10
- Create an EchoWorker class which simply echoes whatever is received:
11
-
12
- ``` ruby
13
- class EchoWorker < EasyBunnyRPC::Worker
14
- def mediate
15
- subscribe do |payload|
16
- publish_success(payload) # Send a success message to the client
17
- # publish_failure(payload) # Send a failure message to the client
18
- end
19
- rescue Interrupt => _
20
- # close
21
- end
22
- end
23
- ```
24
-
25
- Now you can initialize it. Please note the :bunny key Hash is directly fed to Bunny.new:
10
+ The worker. Please note the :bunny key Hash is directly fed to Bunny.new:
26
11
 
27
12
  ``` ruby
28
13
  options = {
@@ -34,34 +19,18 @@ options = {
34
19
  }
35
20
  }
36
21
 
37
- echo_worker = EchoWorker.new options
38
- echo_worker.mediate
39
- ```
40
-
41
-
42
- Create an EchoClient class:
43
-
44
- ``` ruby
45
- class EchoClient < EasyBunnyRPC::Client
46
- def perform
47
- set_timeout(2) # timeout in seconds, default is 5
48
-
49
- # The first argument is the payload, the send argument is the correlation_id
50
- # The correlation_id is always send back as-is by the worker
51
- # This way you can correlate the replies with your requests
52
- publish('hi there', 'call 1')
53
- publish('hi there again', 'call 2')
54
-
55
- # Pop will raise a ::Timeout::Error when a timeout occurs and no message is received
56
- p pop
57
- p pop
58
- end
22
+ worker = EasyBunnyRPC::Worker.new(options)
23
+ worker.subscribe do |payload|
24
+ publish_success(payload) # Send a success message to the client
25
+ # publish_failure(payload) # Send a failure message to the client
59
26
  end
60
27
  ```
61
28
 
62
- Now you can initialize it:
29
+
30
+ The client:
63
31
 
64
32
  ``` ruby
33
+ # initialization options
65
34
  options = {
66
35
  queue: 'echo',
67
36
  bunny: {
@@ -71,8 +40,25 @@ options = {
71
40
  }
72
41
  }
73
42
 
74
- echo_client = EchoClient.new(options)
75
- echo_client.perform
43
+ client = EasyBunnyRPC::Client.new(options)
44
+
45
+ # timeout in seconds, default is 5
46
+ client.set_timeout(2)
47
+
48
+ # The first argument is the payload. The payload can be anything, just keep in
49
+ # mind it must be serializable to a String because .to_json is called on it
50
+ #
51
+ # The second argument is the correlation_id.
52
+ # The correlation_id is always send back as-is by the worker.
53
+ # This way you can correlate the replies with your requests.
54
+ client.publish('hi there', 'call 1')
55
+ client.publish('hi there again', 'call 2')
56
+
57
+ # Pop will raise a ::Timeout::Error when a timeout occurs and no message is received
58
+ puts client.pop
59
+ puts client.pop
60
+
61
+ client.close
76
62
  ```
77
63
 
78
64
  Output:
@@ -83,7 +69,7 @@ Output:
83
69
 
84
70
 
85
71
  Notes
86
- _____
72
+ -----
87
73
 
88
74
  - Tested with RabbitMQ
89
75
  - Uses the expiration feature of RabbitMQ to expire messages sent by the client
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.license = 'MIT'
11
11
  gem.authors = ['Tom van Leeuwen']
12
12
  gem.email = 'tom@vleeuwen.eu'
13
- gem.homepage = 'https://rubygems.org/gems/easy_bunny_rpc'
13
+ gem.homepage = 'https://github.com/TvL2386/easy_bunny_rpc'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,8 +15,6 @@ module EasyBunnyRPC
15
15
  set_timeout(5)
16
16
  end
17
17
 
18
- private
19
-
20
18
  def pop
21
19
  correlation_id, payload = @timed_queue.pop_with_timeout(@timeout)
22
20
 
@@ -27,6 +25,26 @@ module EasyBunnyRPC
27
25
  @timeout = value
28
26
  end
29
27
 
28
+ def publish(payload, correlation_id=default_correlation_id)
29
+ start_subscription unless @subscribed
30
+ exchange.publish([payload].to_json, routing_key: @options[:queue], correlation_id: correlation_id, reply_to: queue.name, expiration: (@timeout*1000).to_i)
31
+ end
32
+
33
+ def close
34
+ if defined?(@channel)
35
+ channel.close
36
+ remove_instance_variable :@channel
37
+ remove_instance_variable :@queue
38
+ end
39
+
40
+ if defined?(@connection)
41
+ connection.close
42
+ remove_instance_variable :@connection
43
+ end
44
+ end
45
+
46
+ private
47
+
30
48
  def start_subscription
31
49
  queue.subscribe(block: false) do |delivery_info, properties, payload|
32
50
  @timed_queue.push([properties.correlation_id, payload])
@@ -35,11 +53,6 @@ module EasyBunnyRPC
35
53
  @subscribed = true
36
54
  end
37
55
 
38
- def publish(payload, correlation_id=default_correlation_id)
39
- start_subscription unless @subscribed
40
- exchange.publish([payload].to_json, routing_key: @options[:queue], correlation_id: correlation_id, reply_to: queue.name, expiration: (@timeout*1000).to_i)
41
- end
42
-
43
56
  def connection
44
57
  return @connection if defined?(@connection)
45
58
 
@@ -26,6 +26,7 @@ module EasyBunnyRPC
26
26
 
27
27
  raise(Timeout::Error, "Waited #{timeout} seconds to pop") if(remaining <= 0)
28
28
 
29
+ # unlocks mutex, waits for remaining seconds, locks mutex on wake-up
29
30
  @cv.wait(@mutex, remaining)
30
31
  else
31
32
  return @array.pop
@@ -1,4 +1,4 @@
1
1
  module EasyBunnyRPC
2
2
  # easy_bunny_rpc version
3
- VERSION = '0.1.0.alpha'
3
+ VERSION = '0.1.1'
4
4
  end
@@ -7,7 +7,13 @@ module EasyBunnyRPC
7
7
  @options = options
8
8
  end
9
9
 
10
- private
10
+ def publish_success(payload)
11
+ publish true, payload
12
+ end
13
+
14
+ def publish_failure(payload)
15
+ publish false, payload
16
+ end
11
17
 
12
18
  def subscribe
13
19
  queue.subscribe(block: true) do |delivery_info, properties, payload|
@@ -17,18 +23,25 @@ module EasyBunnyRPC
17
23
  end
18
24
  end
19
25
 
20
- def publish(success, payload)
21
- obj = { 'success' => success, 'payload' => payload }.to_json
26
+ def close
27
+ if defined?(@channel)
28
+ channel.close
29
+ remove_instance_variable :@channel
30
+ remove_instance_variable :@queue
31
+ end
22
32
 
23
- exchange.publish(obj, routing_key: @properties.reply_to, correlation_id: @properties.correlation_id)
33
+ if defined?(@connection)
34
+ connection.close
35
+ remove_instance_variable :@connection
36
+ end
24
37
  end
25
38
 
26
- def publish_success(payload)
27
- publish true, payload
28
- end
39
+ private
29
40
 
30
- def publish_failure(payload)
31
- publish false, payload
41
+ def publish(success, payload)
42
+ obj = { 'success' => success, 'payload' => payload }.to_json
43
+
44
+ exchange.publish(obj, routing_key: @properties.reply_to, correlation_id: @properties.correlation_id)
32
45
  end
33
46
 
34
47
  def connection
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_bunny_rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.alpha
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom van Leeuwen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-21 00:00:00.000000000 Z
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -85,7 +85,7 @@ files:
85
85
  - lib/easy_bunny_rpc/timed_queue.rb
86
86
  - lib/easy_bunny_rpc/version.rb
87
87
  - lib/easy_bunny_rpc/worker.rb
88
- homepage: https://rubygems.org/gems/easy_bunny_rpc
88
+ homepage: https://github.com/TvL2386/easy_bunny_rpc
89
89
  licenses:
90
90
  - MIT
91
91
  metadata: {}
@@ -100,9 +100,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">"
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
- version: 1.3.1
105
+ version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
108
  rubygems_version: 2.2.0