kanina 0.6.0 → 0.6.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 +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -2
- data/Guardfile +5 -3
- data/History.md +12 -0
- data/README.md +2 -1
- data/lib/generators/kanina/install/install_generator.rb +1 -0
- data/lib/generators/kanina/message/message_generator.rb +4 -1
- data/lib/generators/kanina/subscription/subscription_generator.rb +1 -1
- data/lib/kanina/logger.rb +7 -1
- data/lib/kanina/message.rb +4 -4
- data/lib/kanina/server.rb +11 -2
- data/lib/kanina/subscription.rb +1 -1
- data/lib/kanina/version.rb +6 -1
- data/spec/kanina/message_spec.rb +36 -25
- data/spec/kanina/subscription_spec.rb +7 -7
- data/spec/spec_helper.rb +1 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dae9cec347810f3ce75541ae0ea7cf16d6af65eb
|
4
|
+
data.tar.gz: 21449f6b71e1b18e8011f6b2b584ca4ee7a38c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f78a97f53c19d54cd40e909d3857e00f1d163ca61e309ab4908a47393aa05a072498b8683ba3cef764e207c992be153df5ce18df6651cd9ebd4d8fa1c3f96b8
|
7
|
+
data.tar.gz: f1d0bfd1aa78393facac5a96f09febcb09f25f015fab7a45425b170a9f91a698fde1507a6618875d3f8077615a3bb8e679a8430342e84c3922eec58bee8a978e
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -4,6 +4,8 @@ guard :rspec, cmd: 'bundle exec rspec' do
|
|
4
4
|
watch('spec/spec_helper.rb') { 'spec' }
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# # TODO: Uncomment this to regenerate docs locally, AFTER Yardoc is fixed
|
8
|
+
# # post-Ruby 2.2.0
|
9
|
+
# guard 'yard', port: '8808' do
|
10
|
+
# watch(%r{lib/.+\.rb})
|
11
|
+
# end
|
data/History.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
v0.6.1
|
5
|
+
------
|
6
|
+
- Complete project rename! Once "Hare", now called "Kanina".
|
7
|
+
- "Kanina" means "Bunny" in Icelandic and "a while ago" in Tagalog. More importantly, it was available on Rubygems...
|
8
|
+
- Ruby 2.2.0 support.
|
9
|
+
- Mark an exchange as durable.
|
10
|
+
- More and better documentation.
|
11
|
+
- Better coverage.
|
12
|
+
- Tweak integration with Inch & Code Climate
|
13
|
+
- Stop using Coveralls, since it was conflicting, and I'm now sending coverage to Code Climate anyway.
|
14
|
+
- Renamed exchanges and queues in specs, so all Kanina output is namespaced.
|
15
|
+
|
4
16
|
v0.6.0
|
5
17
|
------
|
6
18
|
- Mark individual messages as persistent or transient.
|
data/README.md
CHANGED
@@ -3,10 +3,11 @@ Kanina
|
|
3
3
|
|
4
4
|
A Rails plugin that makes it easier for your models to communicate with RabbitMQ.
|
5
5
|
|
6
|
+
[](http://badge.fury.io/rb/kanina)
|
6
7
|
[](https://travis-ci.org/judy/kanina)
|
7
8
|
[](https://codeclimate.com/github/judy/kanina)
|
8
|
-
[](https://coveralls.io/r/judy/kanina)
|
9
9
|
[](http://inch-ci.org/github/judy/kanina)
|
10
|
+
[](https://www.omniref.com/ruby/gems/kanina)
|
10
11
|
|
11
12
|
Kanina abstracts away queue and exchange creation, so you can focus on the message and subscription side of things in Rails.
|
12
13
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'rails/generators'
|
2
2
|
|
3
3
|
module Kanina
|
4
|
-
#
|
4
|
+
# `Kanina::MessageGenerator` generates a template of a message file. Change the
|
5
5
|
# resulting file with your intended exchange or routing_key information. For example:
|
6
6
|
#
|
7
7
|
# rails generate message user_notification
|
8
|
+
#
|
9
|
+
# Then you'll want to update the generated message class with instructions on
|
10
|
+
# which exchange to send messages, the type of exchange, and so on.
|
8
11
|
class MessageGenerator < Rails::Generators::NamedBase
|
9
12
|
source_root File.expand_path('../templates', __FILE__)
|
10
13
|
|
data/lib/kanina/logger.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
3
|
module Kanina
|
4
|
-
#
|
4
|
+
# `Kanina::Logger` simplifies sending messages to standard output and/or the
|
5
|
+
# Rails log files.
|
5
6
|
module Logger
|
6
7
|
DEFAULT_LOG_LEVEL = ::Logger::INFO
|
7
8
|
|
9
|
+
# Sets up the Rails logger
|
10
|
+
# @return [Rails::Logger] the logger being used
|
8
11
|
def logger
|
9
12
|
Rails.logger ||= ::Logger.new(STDOUT)
|
10
13
|
@logger ||= Rails.logger
|
11
14
|
end
|
12
15
|
|
16
|
+
# Sends a message to the log
|
17
|
+
# @param text [String] the message to log
|
18
|
+
# @param level the importance of the logged message. Default is Logger::INFO
|
13
19
|
def say(text, level = DEFAULT_LOG_LEVEL)
|
14
20
|
puts text if @loud
|
15
21
|
logger.add level, "HARE: #{text}"
|
data/lib/kanina/message.rb
CHANGED
@@ -15,7 +15,8 @@ module Kanina
|
|
15
15
|
# parsed back out of JSON into native Ruby objects.
|
16
16
|
class Message
|
17
17
|
class << self
|
18
|
-
# Helper method to return the channel
|
18
|
+
# Helper method to return the channel that Kanina::Server is talking on.
|
19
|
+
# @return [Bunny::Channel]
|
19
20
|
def channel
|
20
21
|
Kanina::Server.channel or fail 'Kanina::Server.channel is not open'
|
21
22
|
end
|
@@ -25,12 +26,11 @@ module Kanina
|
|
25
26
|
# @overload exchange(name, *opts)
|
26
27
|
# Set the name and type of the exchange messages should be sent to.
|
27
28
|
# @param name [String] the name of the exchange
|
28
|
-
# @param type [:direct, :fanout, :topic] the type of exchange
|
29
29
|
# @return [String] the exchange
|
30
|
-
def exchange(name = nil, type: :direct)
|
30
|
+
def exchange(name = nil, type: :direct, durable: false)
|
31
31
|
if name.present?
|
32
32
|
@type = type
|
33
|
-
@exchange = channel.exchange(name, type: type)
|
33
|
+
@exchange = channel.exchange(name, type: type, durable: durable)
|
34
34
|
else
|
35
35
|
@exchange || channel.default_exchange
|
36
36
|
end
|
data/lib/kanina/server.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Kanina
|
2
|
-
#
|
2
|
+
# `Kanina::Server` loads configuration, opens a connection to RabbitMQ
|
3
3
|
# and opens a channel so messages can be received and sent. This class is
|
4
4
|
# automatically called and handled by a Railtie, so you shouldn't have to
|
5
5
|
# invoke it by hand.
|
@@ -10,10 +10,16 @@ module Kanina
|
|
10
10
|
attr_reader :connection, :channel
|
11
11
|
attr_accessor :config, :loud
|
12
12
|
|
13
|
+
# Returns the current status of the server connection.
|
14
|
+
# @return [String] status, as 'off', 'starting', 'started', or 'stopping'
|
13
15
|
def status
|
14
16
|
@status || 'off'
|
15
17
|
end
|
16
18
|
|
19
|
+
# Loads the configuration, opens a connection, and opens the channel. This
|
20
|
+
# will automatically be run in the railtie when you install Kanina into a
|
21
|
+
# Rails project, so you shouldn't have to run it yourself.
|
22
|
+
# @return [String] status as 'started', unless something went wrong.
|
17
23
|
def start
|
18
24
|
set_status 'starting'
|
19
25
|
load_config unless @config.present?
|
@@ -22,6 +28,8 @@ module Kanina
|
|
22
28
|
set_status 'started'
|
23
29
|
end
|
24
30
|
|
31
|
+
# Closes the connection to RabbitMQ.
|
32
|
+
# @return [String] status as 'stopping'
|
25
33
|
def stop
|
26
34
|
set_status 'stopping'
|
27
35
|
cleanup
|
@@ -32,6 +40,7 @@ module Kanina
|
|
32
40
|
def set_status(string)
|
33
41
|
@status = string
|
34
42
|
say "Status changed to #{@status}"
|
43
|
+
@status
|
35
44
|
end
|
36
45
|
|
37
46
|
def cleanup
|
@@ -40,7 +49,7 @@ module Kanina
|
|
40
49
|
end
|
41
50
|
|
42
51
|
def config_file_location
|
43
|
-
Rails.root + 'config/amqp.yml'
|
52
|
+
(Rails.try(:root) || './') + 'config/amqp.yml'
|
44
53
|
end
|
45
54
|
|
46
55
|
def load_config
|
data/lib/kanina/subscription.rb
CHANGED
@@ -22,7 +22,7 @@ module Kanina
|
|
22
22
|
# Helper method to return the channel that Kanina::Server is talking on.
|
23
23
|
# @return [Bunny::Channel]
|
24
24
|
def channel
|
25
|
-
Kanina::Server.channel
|
25
|
+
Kanina::Server.channel or fail 'Kanina::Server.channel is not open'
|
26
26
|
end
|
27
27
|
|
28
28
|
# Begins subscribing to the specified queue (or binds to an exchange and
|
data/lib/kanina/version.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# Dumb module definition to set VERSION. Kanina uses
|
2
|
+
# [Semantic Versioniong](http://semver.org/) religiously; the patch number is
|
3
|
+
# bumped for bug fixes, minor number is bumped for new features that don't break
|
4
|
+
# backward compatibility, and major numbers are only bumped when introducing
|
5
|
+
# major API changes that break backward compatibility.
|
1
6
|
module Kanina
|
2
|
-
VERSION = '0.6.
|
7
|
+
VERSION = '0.6.1'
|
3
8
|
end
|
data/spec/kanina/message_spec.rb
CHANGED
@@ -2,24 +2,33 @@ describe Kanina::Message do
|
|
2
2
|
describe '.exchange' do
|
3
3
|
it 'sets and returns the exchange' do
|
4
4
|
dummy_class = Class.new(Kanina::Message) do
|
5
|
-
exchange '
|
5
|
+
exchange 'kanina.message_spec.exchange', type: :direct
|
6
6
|
end
|
7
|
-
expect(dummy_class.exchange.name).to eql '
|
7
|
+
expect(dummy_class.exchange.name).to eql 'kanina.message_spec.exchange'
|
8
8
|
expect(dummy_class.exchange.type).to eql :direct
|
9
9
|
end
|
10
|
+
|
10
11
|
it "returns the default exchange if exchange hasn't been set." do
|
11
12
|
dummy_class = Class.new(Kanina::Message)
|
12
13
|
expect(dummy_class.exchange.name).to eql ''
|
13
14
|
expect(dummy_class.exchange.type).to eql :direct
|
14
15
|
end
|
16
|
+
|
17
|
+
it 'makes a durable exchange' do
|
18
|
+
dummy_class = Class.new(Kanina::Message) do
|
19
|
+
exchange 'kanina.message_spec.durable_exchange', durable: :true
|
20
|
+
end
|
21
|
+
|
22
|
+
expect(`rabbitmqctl list_exchanges name durable`).to include("kanina.message_spec.durable_exchange\ttrue")
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
describe '.routing_key' do
|
18
27
|
it 'sets and returns the routing_key variable' do
|
19
28
|
dummy_class = Class.new(Kanina::Message) do
|
20
|
-
routing_key '
|
29
|
+
routing_key 'kanina.message_spec.routing_key'
|
21
30
|
end
|
22
|
-
expect(dummy_class.routing_key).to eql '
|
31
|
+
expect(dummy_class.routing_key).to eql 'kanina.message_spec.routing_key'
|
23
32
|
end
|
24
33
|
end
|
25
34
|
|
@@ -59,10 +68,10 @@ describe Kanina::Message do
|
|
59
68
|
|
60
69
|
it 'delivers a message to the default exchange' do
|
61
70
|
dummy_class = Class.new(Kanina::Message) do
|
62
|
-
routing_key '
|
71
|
+
routing_key 'kanina.message_spec.default_exchange_to_queue'
|
63
72
|
end
|
64
73
|
|
65
|
-
q = Kanina::Server.channel.queue('
|
74
|
+
q = Kanina::Server.channel.queue('kanina.message_spec.default_exchange_to_queue')
|
66
75
|
message = dummy_class.new('test')
|
67
76
|
result = nil
|
68
77
|
message.deliver
|
@@ -77,11 +86,11 @@ describe Kanina::Message do
|
|
77
86
|
|
78
87
|
it 'delivers a message to a fanout exchange' do
|
79
88
|
dummy_class = Class.new(Kanina::Message) do
|
80
|
-
fanout '
|
89
|
+
fanout 'kanina.message_spec.fanout_exchange'
|
81
90
|
end
|
82
91
|
|
83
92
|
q = Kanina::Server.channel.queue('')
|
84
|
-
q.bind('
|
93
|
+
q.bind('kanina.message_spec.fanout_exchange')
|
85
94
|
message = dummy_class.new('data')
|
86
95
|
message.deliver
|
87
96
|
result = nil
|
@@ -94,13 +103,13 @@ describe Kanina::Message do
|
|
94
103
|
expect(result).to eql('"data"')
|
95
104
|
end
|
96
105
|
|
97
|
-
it 'delivers a message to a
|
106
|
+
it 'delivers a message to a direct exchange' do
|
98
107
|
dummy_class = Class.new(Kanina::Message) do
|
99
|
-
exchange '
|
108
|
+
exchange 'kanina.message_spec.direct_exchange', type: :direct
|
100
109
|
end
|
101
110
|
|
102
111
|
q = Kanina::Server.channel.queue('')
|
103
|
-
q.bind('
|
112
|
+
q.bind('kanina.message_spec.direct_exchange')
|
104
113
|
message = dummy_class.new('data')
|
105
114
|
message.deliver
|
106
115
|
result = nil
|
@@ -115,8 +124,8 @@ describe Kanina::Message do
|
|
115
124
|
context "with a topic exchange" do
|
116
125
|
before(:each) do
|
117
126
|
@dummy_class = Class.new(Kanina::Message) do
|
118
|
-
topic "topic_exchange"
|
119
|
-
routing_key "
|
127
|
+
topic "kanina.message_spec.topic_exchange"
|
128
|
+
routing_key "kanina.message_spec.topic_exchange.suffix"
|
120
129
|
end
|
121
130
|
@q = Kanina::Server.channel.queue('')
|
122
131
|
@ex = @dummy_class.class_eval{exchange}
|
@@ -131,24 +140,24 @@ describe Kanina::Message do
|
|
131
140
|
end
|
132
141
|
|
133
142
|
it "should match a full topic" do
|
134
|
-
@q.bind @ex, routing_key: "
|
143
|
+
@q.bind @ex, routing_key: "kanina.message_spec.topic_exchange.suffix"
|
135
144
|
end
|
136
145
|
|
137
146
|
it "should match a prefix" do
|
138
|
-
@q.bind @ex, routing_key: "
|
147
|
+
@q.bind @ex, routing_key: "kanina.message_spec.topic_exchange.#"
|
139
148
|
end
|
140
149
|
|
141
150
|
it "should match a suffix" do
|
142
|
-
@q.bind @ex, routing_key: "#.suffix"
|
151
|
+
@q.bind @ex, routing_key: "#.topic_exchange.suffix"
|
143
152
|
end
|
144
153
|
end
|
145
154
|
|
146
155
|
context 'with persistence turned on' do
|
147
156
|
it 'should make messages persistent' do
|
148
|
-
Kanina::Server.channel.queue('
|
157
|
+
Kanina::Server.channel.queue('kanina.message_spec.persistent_messages', durable: true)
|
149
158
|
|
150
159
|
dummy_class = Class.new(Kanina::Message) do
|
151
|
-
routing_key '
|
160
|
+
routing_key 'kanina.message_spec.persistent_messages'
|
152
161
|
persistent
|
153
162
|
end
|
154
163
|
result = nil
|
@@ -158,7 +167,7 @@ describe Kanina::Message do
|
|
158
167
|
Kanina::Server.stop
|
159
168
|
Kanina::Server.start
|
160
169
|
|
161
|
-
Kanina::Server.channel.queue('
|
170
|
+
Kanina::Server.channel.queue('kanina.message_spec.persistent_messages', durable: true).subscribe do |_, _, body|
|
162
171
|
result = body
|
163
172
|
end
|
164
173
|
|
@@ -169,12 +178,13 @@ describe Kanina::Message do
|
|
169
178
|
|
170
179
|
context 'with persistence turned off' do
|
171
180
|
it 'should make messages transient' do
|
172
|
-
# TODO: Fix this test so it reliably restarts RabbitMQ across all
|
181
|
+
# TODO: Fix this test so it reliably restarts RabbitMQ across all
|
182
|
+
# platforms, including TravisCI.
|
173
183
|
skip "can fail when restarting RabbitMQ server."
|
174
|
-
Kanina::Server.channel.queue('
|
184
|
+
Kanina::Server.channel.queue('kanina.message_spec.transient_messages', durable: true)
|
175
185
|
|
176
186
|
dummy_class = Class.new(Kanina::Message) do
|
177
|
-
routing_key '
|
187
|
+
routing_key 'kanina.message_spec.transient_messages'
|
178
188
|
transient
|
179
189
|
end
|
180
190
|
result = nil
|
@@ -183,13 +193,14 @@ describe Kanina::Message do
|
|
183
193
|
msg.deliver
|
184
194
|
|
185
195
|
Kanina::Server.stop
|
196
|
+
sleep 1
|
186
197
|
`rabbitmqctl stop_app`
|
198
|
+
sleep 1
|
187
199
|
`rabbitmqctl start_app`
|
188
|
-
|
189
|
-
# sleep 3
|
200
|
+
sleep 1
|
190
201
|
Kanina::Server.start
|
191
202
|
|
192
|
-
Kanina::Server.channel.queue('
|
203
|
+
Kanina::Server.channel.queue('kanina.message_spec.transient_messages', durable: true).subscribe do |_, _, body|
|
193
204
|
result = body
|
194
205
|
end
|
195
206
|
|
@@ -2,13 +2,13 @@ describe Kanina::Subscription do
|
|
2
2
|
describe '.subscribe' do
|
3
3
|
it 'watches a queue' do
|
4
4
|
result = nil
|
5
|
-
Kanina::Subscription.subscribe queue: '
|
5
|
+
Kanina::Subscription.subscribe queue: 'kanina.subscription_spec.subscribe' do |data|
|
6
6
|
result = data[:string]
|
7
7
|
end
|
8
8
|
|
9
9
|
Kanina::Server.channel.default_exchange.publish(
|
10
10
|
{ string: 'success' }.to_json,
|
11
|
-
routing_key: '
|
11
|
+
routing_key: 'kanina.subscription_spec.subscribe'
|
12
12
|
)
|
13
13
|
|
14
14
|
sleep(0.1)
|
@@ -19,19 +19,19 @@ describe Kanina::Subscription do
|
|
19
19
|
result = nil
|
20
20
|
|
21
21
|
# The queue must exist first before we send messages to it.
|
22
|
-
Kanina::Subscription.create_queue('
|
22
|
+
Kanina::Subscription.create_queue('kanina.subscription_spec.durable_queue', durable: true)
|
23
23
|
|
24
24
|
# Push the message
|
25
25
|
Kanina::Server.channel.default_exchange.publish(
|
26
26
|
{ string: 'success' }.to_json,
|
27
|
-
routing_key: '
|
27
|
+
routing_key: 'kanina.subscription_spec.durable_queue'
|
28
28
|
)
|
29
29
|
|
30
30
|
Kanina::Server.stop
|
31
31
|
Kanina::Server.start
|
32
32
|
|
33
33
|
# Re-open the subscription to the queue
|
34
|
-
Kanina::Subscription.subscribe queue: '
|
34
|
+
Kanina::Subscription.subscribe queue: 'kanina.subscription_spec.durable_queue', durable: true do |data|
|
35
35
|
result = data[:string]
|
36
36
|
end
|
37
37
|
|
@@ -41,10 +41,10 @@ describe Kanina::Subscription do
|
|
41
41
|
|
42
42
|
it 'sets up a binding to a named exchange' do
|
43
43
|
result = nil
|
44
|
-
Kanina::Subscription.subscribe bind: '
|
44
|
+
Kanina::Subscription.subscribe bind: 'kanina.subscription_spec.binding_to_named_exchange' do |data|
|
45
45
|
result = data[:string]
|
46
46
|
end
|
47
|
-
Kanina::Server.channel.direct('
|
47
|
+
Kanina::Server.channel.direct('kanina.subscription_spec.binding_to_named_exchange').publish(
|
48
48
|
{ string: 'success' }.to_json
|
49
49
|
)
|
50
50
|
|
data/spec/spec_helper.rb
CHANGED
@@ -5,17 +5,13 @@ require 'simplecov'
|
|
5
5
|
original_process = Process.pid
|
6
6
|
|
7
7
|
SimpleCov.start do
|
8
|
-
add_filter 'spec
|
8
|
+
add_filter 'spec'
|
9
9
|
end
|
10
10
|
|
11
11
|
SimpleCov.at_exit do
|
12
12
|
SimpleCov.result.format! if Process.pid == original_process
|
13
13
|
end
|
14
14
|
|
15
|
-
# Coveralls for online code coverage generation.
|
16
|
-
require 'coveralls'
|
17
|
-
Coveralls.wear!
|
18
|
-
|
19
15
|
# Send code coverage to Code Climate
|
20
16
|
require "codeclimate-test-reporter"
|
21
17
|
CodeClimate::TestReporter.start
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clinton Judy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
351
|
version: '0'
|
352
352
|
requirements: []
|
353
353
|
rubyforge_project:
|
354
|
-
rubygems_version: 2.4.
|
354
|
+
rubygems_version: 2.4.5
|
355
355
|
signing_key:
|
356
356
|
specification_version: 4
|
357
357
|
summary: Rails plugin for RabbitMQ
|