pika_q 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +118 -0
- data/Rakefile +19 -0
- data/lib/pika_q/connection.rb +13 -0
- data/lib/pika_q/consumers/base.rb +53 -0
- data/lib/pika_q/exchanges/base.rb +15 -0
- data/lib/pika_q/exchanges/default.rb +11 -0
- data/lib/pika_q/publisher.rb +45 -0
- data/lib/pika_q/queues/base.rb +15 -0
- data/lib/pika_q/version.rb +5 -0
- data/lib/pika_q.rb +14 -0
- data/pika_q.gemspec +22 -0
- data/spec/pika_q/connection_spec.rb +15 -0
- data/spec/pika_q/consumers/base_spec.rb +30 -0
- data/spec/pika_q/exchanges/base_spec.rb +13 -0
- data/spec/pika_q/exchanges/default_spec.rb +9 -0
- data/spec/pika_q/publisher_spec.rb +27 -0
- data/spec/pika_q/queues/base_spec.rb +13 -0
- data/spec/spec_helper.rb +10 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 951a4d2ae70a0d126742d38e474ff382657c351e
|
4
|
+
data.tar.gz: 819074c2a632ef1081a64d1237820ce064a38baf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c62c0a7c4d95a439bac2efd04135a67fde5e81621594fc50c4870b4b0a4ad2e16739eec4413f2d6d6c201055c8a1a75018e326577280c8892d3b83092f53a2e1
|
7
|
+
data.tar.gz: 3cd6a7c6b89afce072deafa1a42981d89c0fb2b7aa58fc1622d516a0ec699f47c4f3f9b9abbc89c39987c923526afc6a78584b51a31fd5fcd153665eaf5b9a28
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :test, :rake do
|
6
|
+
gem 'bundler'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :rake do
|
10
|
+
gem 'rake'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'minitest'
|
15
|
+
gem 'minitest-spec-context'
|
16
|
+
gem 'minitest-reporters', require: 'minitest/reporters'
|
17
|
+
end
|
18
|
+
|
19
|
+
group :development do
|
20
|
+
gem 'gem-release', require: false
|
21
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Eric Marden
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# pika_q
|
2
|
+
[![Build Status](https://travis-ci.org/xentek/pika_q.svg)](https://travis-ci.org/xentek/pika_q)
|
3
|
+
|
4
|
+
---
|
5
|
+
|
6
|
+
![PikaQ, I choose you!](http://xentek-images.s3.amazonaws.com/pikachu-and-ash.png "PikaQ, I choose you!")
|
7
|
+
|
8
|
+
#### __PikaQ, I choose YOU!__
|
9
|
+
|
10
|
+
PikaQ makes working with Rabbit MQ _even_ easier. It provides a thin layer around [Bunny](http://rubybunny.info), the defacto standard ruby library for Rabbit MQ. It provides objects for writing your own high performance, message consumers, as well a generic service object for publishing messages to any Rabbit MQ exchange.
|
11
|
+
|
12
|
+
> The name "pika" is used for any member of the Ochotonidae, a family within the order of lagomorphs, which also includes the Leporidae (rabbits and hares).
|
13
|
+
> __-- [Wikipedia](https://en.wikipedia.org/wiki/Pika)__
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
### Gemfile
|
18
|
+
|
19
|
+
gem 'pika_q'
|
20
|
+
|
21
|
+
## Require
|
22
|
+
|
23
|
+
require 'pika_q'
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Creating a connection
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
connection = PikaQ::Connection.new
|
31
|
+
channel = connection.channel
|
32
|
+
```
|
33
|
+
|
34
|
+
By default, it uses the value of `ENV['RABBITMQ_URL']` as the connection string, which if `nil`, will fallback to Bunny's default connection string (i.e. `ampq://guest:guest@localhost:5672'`). You can also supply a connection string when initalizing `PikaQ::Connection`.
|
35
|
+
|
36
|
+
### Publishing a message
|
37
|
+
|
38
|
+
This sends a message to the default exchange:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
channel = PikaQ::Connection.new.channel
|
42
|
+
publisher = PikaQ::Publisher.new(channel, '', :default)
|
43
|
+
|
44
|
+
# publish a message to the exchange
|
45
|
+
publisher.send_message('{"test":"ok"}')
|
46
|
+
```
|
47
|
+
|
48
|
+
`PikaQ::Publisher.new` takes the same arguments as [`Bunny::Exchange.new`](http://reference.rubybunny.info/Bunny/Exchange.html#initialize-instance_method).
|
49
|
+
|
50
|
+
### Establishing an Exchange
|
51
|
+
|
52
|
+
Establish the default exchange:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
channel = PikaQ::Connection.new.channel
|
56
|
+
exchange = PikaQ::Exchanges::Default.establish(channel)
|
57
|
+
```
|
58
|
+
|
59
|
+
__The default exchange is special and can't be removed -- it's built into the Rabbit MQ server.__
|
60
|
+
|
61
|
+
To establish other types of exchanges, you need to create an object that responds to `establish` and takes a `channel` as an argument. The easiest way to do this is to subclass `PikaQ::Exchanges::Base` and overwrite the `establish` method.
|
62
|
+
|
63
|
+
`PikaQ::Exchanges::Base.establish` provides a default implementation that returns a `:direct` exchange. The name is created automatically by `PikaQ::Exchanges::Base.generated_exchange_name`, which will return a string based on the name of your class and the value of `ENV['RUBY_ENV']`, e.g. `pikaq.exchanges.base.development`.
|
64
|
+
|
65
|
+
### Creating a Queue
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
channel = PikaQ::Connection.new.channel
|
69
|
+
queue = PikaQ::Queues::Base.create(channel, { durable: false, auto_delete: false, exclusive: false })
|
70
|
+
```
|
71
|
+
|
72
|
+
Your consumer will bind your queues to exhcnages. Create subclasses only for the sake of identity (helpful if the queue throws an exception). `PikaQ::Queues::Base.create` is a factory method that returns an instance of `Bunny::Queue`. Like exchanges, the `PikaQ::Queues::Base.generated_queue_name` method will generate a queue name for you based on the name of your subclass, e.g. `pikaq.queues.base.development`.
|
73
|
+
|
74
|
+
### Creating a Consumer
|
75
|
+
|
76
|
+
Create and configure a consumer subclass:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
class MyConsumer < PikaQ::Consumers::Base
|
80
|
+
config queue: PikaQ::Queues::Default,
|
81
|
+
exchange: PikaQ::Exchanges::Default,
|
82
|
+
consumer_tag: default_consumer_tag('abcd-1234-efgh-5678'),
|
83
|
+
routing_key: 'test.routing.key'
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Pass the name of your `queue` and `exchange` clases. You can use any string for the optional `consumer_tag`, but it must be unique. It's recommended to use the `default_consumer_tag` method, which will generate a new UUID for you if you don't supply an argument. The routing key is also optional, and only required by some types of exchanges.
|
88
|
+
|
89
|
+
Now you're ready to make it do some actual work when it recieves a message. I prefer to create an executable shellscript for these but you can run them however you like. Just know that a consumer is a essentially a daemon and will keep running until it's stopped. Use `foreman` to manaage these and export them to upstart, etc for use in production.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
#!/usr/bin/env ruby
|
93
|
+
|
94
|
+
require 'pika/mq'
|
95
|
+
require 'my_consumer'
|
96
|
+
channel = PikaQ::Connection.new.channel
|
97
|
+
channel.prefetch(20) # this will affect your throughput, so expiriment with what's right for your environment.
|
98
|
+
Log = Logger.new(STDOUT)
|
99
|
+
|
100
|
+
MyConsumer.start do |delivery_info, properties, payload|
|
101
|
+
Log.info(delivery_info)
|
102
|
+
Log.info(properties)
|
103
|
+
Log.info(payload)
|
104
|
+
end
|
105
|
+
|
106
|
+
channel.close # this will run when the consumer is stopped
|
107
|
+
```
|
108
|
+
|
109
|
+
---
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
Bug reports and pull requests are welcome on GitHub at [xentek/pika_q](https://github.com/xentek/pika_q). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
114
|
+
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
# environment
|
6
|
+
ENV['RUBY_ENV'] ||= 'development'
|
7
|
+
ENV['RABBITMQ_URL'] = 'amqp://guest:guest@127.0.0.1:5672'
|
8
|
+
|
9
|
+
# load path
|
10
|
+
lib_path = File.expand_path('../lib', __FILE__)
|
11
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
12
|
+
|
13
|
+
Rake::TestTask.new do |t|
|
14
|
+
t.libs << "spec"
|
15
|
+
t.pattern = "spec/**/*_spec.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
# tasks
|
19
|
+
task :default => [:test]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PikaQ
|
4
|
+
class Connection
|
5
|
+
attr_reader :channel, :rabbitmq_url, :session
|
6
|
+
|
7
|
+
def initialize(rabbitmq_url = ENV['RABBITMQ_URL'])
|
8
|
+
@session = Bunny.new(rabbitmq_url)
|
9
|
+
@session.start
|
10
|
+
@channel = @session.create_channel
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PikaQ
|
4
|
+
module Consumers
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
attr_reader :consumer, :consumer_tag, :exchange, :routing_key, :queue
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.config(options = {})
|
11
|
+
options ||= {} if options.nil?
|
12
|
+
options = default_config.merge(options)
|
13
|
+
@consumer_tag = options.fetch(:consumer_tag)
|
14
|
+
@exchange = options.fetch(:exchange)
|
15
|
+
@routing_key = options.fetch(:routing_key)
|
16
|
+
@queue = options.fetch(:queue)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.start(channel, &block)
|
20
|
+
@exchange = exchange.establish(channel) if exchange.respond_to? :establish
|
21
|
+
@queue = queue.create(channel) if queue.respond_to? :create
|
22
|
+
|
23
|
+
unless exchange.predeclared?
|
24
|
+
queue.bind(exchange, { routing_key: routing_key })
|
25
|
+
end
|
26
|
+
|
27
|
+
@consumer = queue.subscribe(manual_ack: true,
|
28
|
+
block: true,
|
29
|
+
consumer_tag: consumer_tag,
|
30
|
+
&Proc.new)
|
31
|
+
consumer
|
32
|
+
rescue Interrupt
|
33
|
+
consumer.cancel
|
34
|
+
consumer.channel.close
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.default_consumer_tag(unique_id = SecureRandom.uuid)
|
40
|
+
"#{self.to_s.gsub('::','.')}.#{ENV['RUBY_ENV']}.#{unique_id}".downcase
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.default_config
|
44
|
+
{
|
45
|
+
consumer_tag: default_consumer_tag,
|
46
|
+
exchange: PikaQ::Exchanges::Default,
|
47
|
+
routing_key: nil,
|
48
|
+
queue: ''
|
49
|
+
}.freeze
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PikaQ
|
4
|
+
module Exchanges
|
5
|
+
class Base < Bunny::Exchange
|
6
|
+
def self.establish(channel)
|
7
|
+
new(channel, :direct, generated_exchange_name, auto_delete: false, durable: false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.generated_exchange_name
|
11
|
+
"#{self.to_s.gsub('::','.')}.#{ENV['RUBY_ENV']}".downcase
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bunny'
|
4
|
+
|
5
|
+
module PikaQ
|
6
|
+
class Publisher
|
7
|
+
attr_reader :channel, :exchange, :exchange_name, :exchange_type, :exchange_options
|
8
|
+
|
9
|
+
def initialize(channel, exchange_name, exchange_type = :default, exchange_options = { durable: false, auto_delete: false })
|
10
|
+
@channel = channel
|
11
|
+
@exchange_name = exchange_name
|
12
|
+
@exchange_type = exchange_type
|
13
|
+
@exchange_options = exchange_options
|
14
|
+
@exchange = connect_to_exchange
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_message(payload, message_options = {})
|
18
|
+
message_options ||= {}
|
19
|
+
message_options = default_message_options.merge(message_options)
|
20
|
+
published = exchange.publish(payload, message_options)
|
21
|
+
channel.close
|
22
|
+
published
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def default_message_options
|
28
|
+
{
|
29
|
+
content_type: 'application/json',
|
30
|
+
message_id: SecureRandom.uuid,
|
31
|
+
persistent: false,
|
32
|
+
routing_key: nil,
|
33
|
+
timestamp: DateTime.now.to_time.to_i
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def connect_to_exchange
|
38
|
+
if exchange_type == :default
|
39
|
+
channel.default_exchange
|
40
|
+
else
|
41
|
+
::Bunny::Exchange.new(channel, exchange_type, exchange_name, exchange_options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module PikaQ
|
4
|
+
module Queues
|
5
|
+
class Base < Bunny::Queue
|
6
|
+
def self.create(channel, options = { durable: false, auto_delete: false, exclusive: false })
|
7
|
+
new(channel, generated_queue_name, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.generated_queue_name
|
11
|
+
"#{self.to_s.gsub('::','.')}.#{ENV['RUBY_ENV']}".downcase
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/pika_q.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# dependencies
|
4
|
+
require 'securerandom'
|
5
|
+
require 'bunny'
|
6
|
+
|
7
|
+
# mq
|
8
|
+
require 'pika_q/connection'
|
9
|
+
require 'pika_q/publisher'
|
10
|
+
require 'pika_q/exchanges/base'
|
11
|
+
require 'pika_q/exchanges/default'
|
12
|
+
require 'pika_q/queues/base'
|
13
|
+
require 'pika_q/consumers/base'
|
14
|
+
require 'pika_q/version'
|
data/pika_q.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pika_q/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "pika_q"
|
8
|
+
gem.version = PikaQ::VERSION
|
9
|
+
gem.authors = ["Eric Marden"]
|
10
|
+
gem.email = ["eric.marden@gmail.com"]
|
11
|
+
gem.summary = %q{PikaQ makes working with Rabbit MQ easier.}
|
12
|
+
gem.description = %q{PikaQ makes working with Rabbit MQ easier. It provides a thin layer around Bunny, the defacto standard ruby library for Rabbit MQ.}
|
13
|
+
gem.homepage = "http://github.com/xentek/pika_q"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files -z`.split("\x0")
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'bunny'
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe PikaQ::Connection do
|
6
|
+
let(:connection) { PikaQ::Connection.new }
|
7
|
+
|
8
|
+
it 'has a session' do
|
9
|
+
connection.session.must_be_kind_of Bunny::Session
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has a channel' do
|
13
|
+
connection.channel.must_be_kind_of Bunny::Channel
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe PikaQ::Consumers::Base do
|
6
|
+
before do
|
7
|
+
class TestConsumer < PikaQ::Consumers::Base
|
8
|
+
config queue: PikaQ::Queues::Base,
|
9
|
+
exchange: PikaQ::Exchanges::Default,
|
10
|
+
consumer_tag: default_consumer_tag('2d931510-d99f-494a-8c67-87feb05e1594'),
|
11
|
+
routing_key: 'test.routing.key'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has a queue' do
|
16
|
+
TestConsumer.queue.must_equal PikaQ::Queues::Base
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has an exchange' do
|
20
|
+
TestConsumer.exchange.must_equal PikaQ::Exchanges::Default
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has a consumer tag' do
|
24
|
+
TestConsumer.consumer_tag.must_equal 'testconsumer.test.2d931510-d99f-494a-8c67-87feb05e1594'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has a routing key' do
|
28
|
+
TestConsumer.routing_key.must_equal 'test.routing.key'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe PikaQ::Exchanges::Base do
|
6
|
+
it 'can establish the default exchange' do
|
7
|
+
PikaQ::Exchanges::Base.establish(PikaQ::Connection.new.channel).must_be_kind_of ::Bunny::Exchange
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can generate the exchange name' do
|
11
|
+
PikaQ::Exchanges::Base.generated_exchange_name.must_equal 'pikaq.exchanges.base.test'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe PikaQ::Publisher do
|
6
|
+
let(:publisher) { PikaQ::Publisher.new(PikaQ::Connection.new.channel, '', :default) }
|
7
|
+
|
8
|
+
it "has a channel" do
|
9
|
+
publisher.channel.must_be_kind_of ::Bunny::Channel
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has an exchange name" do
|
13
|
+
publisher.exchange_name.must_equal ''
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has an exchange type" do
|
17
|
+
publisher.exchange_type.must_equal :default
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has an exchange" do
|
21
|
+
publisher.exchange.must_be_kind_of ::Bunny::Exchange
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can publish a message" do
|
25
|
+
publisher.send_message('{"test":"ok"}').must_be_kind_of ::Bunny::Exchange
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe PikaQ::Queues::Base do
|
6
|
+
it 'can create the default queue' do
|
7
|
+
PikaQ::Queues::Base.new(PikaQ::Connection.new.channel).must_be_kind_of ::Bunny::Queue
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can generate a queue name' do
|
11
|
+
PikaQ::Queues::Base.generated_queue_name.must_equal 'pikaq.queues.base.test'
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
ENV['RUBY_ENV'] = 'test'
|
4
|
+
ENV['RABBITMQ_URL'] ||= 'amqp://guest:guest@127.0.0.1:5672'
|
5
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
6
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
7
|
+
Bundler.require(:default, ENV['RUBY_ENV'])
|
8
|
+
require 'minitest-spec-context'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pika_q
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Marden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-08 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: PikaQ makes working with Rabbit MQ easier. It provides a thin layer
|
28
|
+
around Bunny, the defacto standard ruby library for Rabbit MQ.
|
29
|
+
email:
|
30
|
+
- eric.marden@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/pika_q.rb
|
43
|
+
- lib/pika_q/connection.rb
|
44
|
+
- lib/pika_q/consumers/base.rb
|
45
|
+
- lib/pika_q/exchanges/base.rb
|
46
|
+
- lib/pika_q/exchanges/default.rb
|
47
|
+
- lib/pika_q/publisher.rb
|
48
|
+
- lib/pika_q/queues/base.rb
|
49
|
+
- lib/pika_q/version.rb
|
50
|
+
- pika_q.gemspec
|
51
|
+
- spec/pika_q/connection_spec.rb
|
52
|
+
- spec/pika_q/consumers/base_spec.rb
|
53
|
+
- spec/pika_q/exchanges/base_spec.rb
|
54
|
+
- spec/pika_q/exchanges/default_spec.rb
|
55
|
+
- spec/pika_q/publisher_spec.rb
|
56
|
+
- spec/pika_q/queues/base_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
homepage: http://github.com/xentek/pika_q
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.5.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: PikaQ makes working with Rabbit MQ easier.
|
82
|
+
test_files:
|
83
|
+
- spec/pika_q/connection_spec.rb
|
84
|
+
- spec/pika_q/consumers/base_spec.rb
|
85
|
+
- spec/pika_q/exchanges/base_spec.rb
|
86
|
+
- spec/pika_q/exchanges/default_spec.rb
|
87
|
+
- spec/pika_q/publisher_spec.rb
|
88
|
+
- spec/pika_q/queues/base_spec.rb
|
89
|
+
- spec/spec_helper.rb
|