hotot 0.0.0 → 0.0.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.
@@ -7,7 +7,7 @@ module Hotot
|
|
7
7
|
extend Configurable
|
8
8
|
extend ClassAttributeAccessors
|
9
9
|
|
10
|
-
cattr_reader :
|
10
|
+
cattr_reader :producer, :exchange, :consumer
|
11
11
|
|
12
12
|
@@setup = false
|
13
13
|
@@connected = false
|
@@ -22,7 +22,8 @@ module Hotot
|
|
22
22
|
@@env_config.keys.each {|key| @@env_config[(key.to_sym rescue key) || key] = @@env_config.delete(key) }
|
23
23
|
raise StandardError, "'exchange' key not found in config" if !@@env_config.has_key?(:exchange)
|
24
24
|
|
25
|
-
@@
|
25
|
+
@@producer = Bunny.new(@@env_config)
|
26
|
+
@@consumer = Bunny.new(@@env_config)
|
26
27
|
@@setup = true
|
27
28
|
end
|
28
29
|
end
|
@@ -33,7 +34,7 @@ module Hotot
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.subscribe(routing_key, &block)
|
36
|
-
q = @@
|
37
|
+
q = @@consumer.queue.bind(@@env_config[:exchange], :routing_key => routing_key)
|
37
38
|
|
38
39
|
q.subscribe do |delivery_info, metadata, payload|
|
39
40
|
block.call delivery_info, metadata, payload
|
@@ -44,17 +45,19 @@ module Hotot
|
|
44
45
|
# Establish a connection to the underlying exchange
|
45
46
|
def self.connect
|
46
47
|
raise StandardError, "AMQP not setup. Call setup before calling connect" if !self.setup?
|
47
|
-
@@
|
48
|
+
@@producer.start
|
49
|
+
@@consumer.start
|
48
50
|
|
49
51
|
# use defualt channel for exchange
|
50
|
-
@@exchange = @@
|
52
|
+
@@exchange = @@producer.exchange(@@env_config[:exchange], :type => :topic, :durable => true)
|
51
53
|
@@connected = true
|
52
54
|
end
|
53
55
|
|
54
56
|
# Disconnect from the underlying exchange
|
55
57
|
def self.disconnect
|
56
58
|
begin
|
57
|
-
@@
|
59
|
+
@@producer.stop
|
60
|
+
@@consumer.stop
|
58
61
|
rescue
|
59
62
|
# if this is being called because the underlying connection went bad
|
60
63
|
# calling stop will raise an error. that's ok....
|
@@ -67,7 +70,8 @@ module Hotot
|
|
67
70
|
def self.reconnect
|
68
71
|
self.disconnect
|
69
72
|
@@setup = false
|
70
|
-
@@
|
73
|
+
@@producer = Bunny.new(@@env_config)
|
74
|
+
@@consumer = Bunny.new(@@env_config)
|
71
75
|
@@setup = true
|
72
76
|
self.connect
|
73
77
|
end
|
data/lib/hotot/version.rb
CHANGED
@@ -11,8 +11,6 @@ describe "Hotot::SynchronousConnection" do
|
|
11
11
|
|
12
12
|
before do
|
13
13
|
@config_file = Pathname.new File.expand_path("../../fixtures/hotot.yml", __FILE__)
|
14
|
-
@bunny = Minitest::Mock.new
|
15
|
-
@exchange = Minitest::Mock.new
|
16
14
|
end
|
17
15
|
|
18
16
|
it "raise error if not setup yet" do
|
@@ -32,7 +30,8 @@ describe "Hotot::SynchronousConnection" do
|
|
32
30
|
|
33
31
|
before do
|
34
32
|
Hotot::SynchronousConnection.setup @config_file, 'test'
|
35
|
-
@
|
33
|
+
@producer = Hotot::SynchronousConnection.producer
|
34
|
+
@consumer = Hotot::SynchronousConnection.consumer
|
36
35
|
end
|
37
36
|
|
38
37
|
after do
|
@@ -42,8 +41,8 @@ describe "Hotot::SynchronousConnection" do
|
|
42
41
|
it "calls start and exchange" do
|
43
42
|
Hotot::SynchronousConnection.connect
|
44
43
|
Hotot::SynchronousConnection.connected?.must_equal true
|
45
|
-
assert_send [@
|
46
|
-
assert_send [@
|
44
|
+
assert_send [@producer, :start]
|
45
|
+
assert_send [@producer, :exchange, "heyook.topic", :type => :topic, :durable => true]
|
47
46
|
end
|
48
47
|
|
49
48
|
describe "publish" do
|
@@ -64,10 +63,8 @@ describe "Hotot::SynchronousConnection" do
|
|
64
63
|
describe "disconnect" do
|
65
64
|
|
66
65
|
it "disconnects and set connected to false" do
|
67
|
-
|
68
|
-
|
69
|
-
Hotot::SynchronousConnection.connected?.must_equal false
|
70
|
-
end
|
66
|
+
Hotot::SynchronousConnection.disconnect
|
67
|
+
Hotot::SynchronousConnection.connected?.must_equal false
|
71
68
|
end
|
72
69
|
|
73
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.2'
|
30
|
-
description: ! ' Hotot is a kind of rabbit that wraps bunny
|
30
|
+
description: ! ' Hotot is a kind of rabbit that wraps bunny''s topic exchange.
|
31
31
|
|
32
32
|
'
|
33
33
|
email: qihe229@gmail.com
|
@@ -72,7 +72,7 @@ rubyforge_project:
|
|
72
72
|
rubygems_version: 1.8.23
|
73
73
|
signing_key:
|
74
74
|
specification_version: 3
|
75
|
-
summary: A bunny
|
75
|
+
summary: A kind of rabbit that wraps bunny gem.
|
76
76
|
test_files:
|
77
77
|
- spec/hotot/configurable_spec.rb
|
78
78
|
- spec/hotot/message/base_spec.rb
|