rabbit_courier 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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/rabbit_courier.rb +13 -0
- data/lib/rabbit_courier/rpc_client.rb +53 -0
- data/lib/rabbit_courier/version.rb +3 -0
- data/rabbit_courier.gemspec +36 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c3f59610640c5dd4a8c94dd8be936f6fc6f1062
|
4
|
+
data.tar.gz: 59f6d2d537d96eea8288273e2ac6b33fed6875b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e70cc624c6638c47f83da78aa9be76a8b6266b26e51ee1b494fd9e64cdd82c86ea812ffb8b43c0e1bbc43ba04493e50515219ddae5715bcb1c7d2dee9319874
|
7
|
+
data.tar.gz: 4dbf258f50aec90e7bf004cad907b71d30f91542ece6ed1b27bb17d1d7580286b3e9e802139596e509e6e690d853cc16e545672fe40cac313c80af1ddede93cd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# RabbitCourier
|
2
|
+
|
3
|
+
A simplified interface for RPC over RabbitMQ.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rabbit_courier'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rabbit_courier
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/raycheung/rabbit_courier.
|
34
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "courier"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rabbit_courier/version"
|
2
|
+
require "rabbit_courier/rpc_client"
|
3
|
+
require "bunny"
|
4
|
+
|
5
|
+
module RabbitCourier
|
6
|
+
def self.connection
|
7
|
+
@connection ||= Bunny.new(recover_from_connection_close: false).tap(&:start)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.new(name, opts = {})
|
11
|
+
RabbitCourier::RPCClient.new(name, opts)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class RabbitCourier::RPCClient
|
2
|
+
DEFAULT_QUEUE_OPTS = {exclusive: false, auto_delete: false}
|
3
|
+
|
4
|
+
attr_accessor :correlation_id, :response
|
5
|
+
attr_reader :lock, :condition
|
6
|
+
|
7
|
+
def initialize(name, opts = {})
|
8
|
+
@name = name
|
9
|
+
@reply_queue = channel.queue(reply_queue_name(name), DEFAULT_QUEUE_OPTS.merge(opts))
|
10
|
+
|
11
|
+
@lock = Mutex.new
|
12
|
+
@condition = ConditionVariable.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(message, correlation_id)
|
16
|
+
self.correlation_id = correlation_id
|
17
|
+
|
18
|
+
consumer = subscribe_to_reply
|
19
|
+
exchange.publish(message.to_s, routing_key: @name, reply_to: @reply_queue.name, correlation_id: correlation_id)
|
20
|
+
|
21
|
+
# wait for condition
|
22
|
+
lock.synchronize { condition.wait(lock) }
|
23
|
+
consumer.cancel
|
24
|
+
|
25
|
+
response
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def subscribe_to_reply
|
31
|
+
myself = self
|
32
|
+
@reply_queue.subscribe do |delivery_info, properties, payload|
|
33
|
+
if properties[:correlation_id] == myself.correlation_id.to_s
|
34
|
+
myself.response = payload
|
35
|
+
|
36
|
+
# signal the condition
|
37
|
+
myself.lock.synchronize { myself.condition.signal }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def channel
|
43
|
+
@channel ||= RabbitCourier.connection.create_channel
|
44
|
+
end
|
45
|
+
|
46
|
+
def exchange
|
47
|
+
@exchange ||= channel.default_exchange
|
48
|
+
end
|
49
|
+
|
50
|
+
def reply_queue_name(name)
|
51
|
+
name + ".reply"
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rabbit_courier/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rabbit_courier"
|
8
|
+
spec.version = RabbitCourier::VERSION
|
9
|
+
spec.authors = ["Ray Cheung"]
|
10
|
+
spec.email = ["ray.swc@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simplified interface for RPC over RabbitMQ.}
|
13
|
+
spec.homepage = "https://github.com/raycheung/rabbit_courier"
|
14
|
+
spec.licenses = ["MIT"]
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency "bunny", "~> 2.6"
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rabbit_courier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ray Cheung
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bunny
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ray.swc@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- bin/console
|
81
|
+
- bin/setup
|
82
|
+
- lib/rabbit_courier.rb
|
83
|
+
- lib/rabbit_courier/rpc_client.rb
|
84
|
+
- lib/rabbit_courier/version.rb
|
85
|
+
- rabbit_courier.gemspec
|
86
|
+
homepage: https://github.com/raycheung/rabbit_courier
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata:
|
90
|
+
allowed_push_host: https://rubygems.org
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.5.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A simplified interface for RPC over RabbitMQ.
|
111
|
+
test_files: []
|