a13g 0.1.0.beta3 → 0.1.0.beta4
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/Rakefile +53 -0
- data/a13g-0.1.0.beta3.gem +0 -0
- data/a13g.gemspec +100 -0
- data/examples/consumer.rb +16 -0
- data/examples/multiple_connections.rb +26 -0
- data/examples/producer.rb +11 -0
- data/examples/simple_project/README +3 -0
- data/examples/simple_project/Rakefile +6 -0
- data/examples/simple_project/config/broker.yml +10 -0
- data/examples/simple_project/lib/consumers/first_consumer.rb +7 -0
- data/examples/simple_project/lib/consumers/second_consumer.rb +9 -0
- data/examples/simple_project/lib/simple_project.rb +20 -0
- data/lib/a13g.rb +68 -0
- data/lib/a13g/adapters.rb +45 -0
- data/lib/a13g/adapters/abstract_adapter.rb +330 -0
- data/lib/a13g/adapters/stomp_adapter.rb +163 -0
- data/lib/a13g/adapters/test_adapter.rb +102 -0
- data/lib/a13g/base.rb +448 -0
- data/lib/a13g/command.rb +69 -0
- data/lib/a13g/consumer.rb +129 -0
- data/lib/a13g/destination.rb +22 -0
- data/lib/a13g/errors.rb +60 -0
- data/lib/a13g/listener.rb +190 -0
- data/lib/a13g/message.rb +68 -0
- data/lib/a13g/producer.rb +107 -0
- data/lib/a13g/railtie.rb +4 -0
- data/lib/a13g/recipes.rb +31 -0
- data/lib/a13g/subscription.rb +123 -0
- data/lib/a13g/support/logger.rb +194 -0
- data/lib/a13g/support/utils.rb +25 -0
- data/lib/a13g/utils.rb +25 -0
- data/lib/a13g/version.rb +10 -0
- data/spec/a13g_spec.rb +74 -0
- data/spec/config/broker.yml +4 -0
- data/spec/dconfig/broker.yml +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- metadata +50 -4
@@ -0,0 +1,25 @@
|
|
1
|
+
module A13g
|
2
|
+
module Utils
|
3
|
+
# It will preetify message and prepare for display, eg. in logs.
|
4
|
+
#
|
5
|
+
# @param [String] target
|
6
|
+
# message destination or source
|
7
|
+
# @param [String] message
|
8
|
+
# the message to format
|
9
|
+
# @param [Hash] headers
|
10
|
+
# message headers
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
# formatted message with headers
|
14
|
+
#
|
15
|
+
# @api public
|
16
|
+
def self.format_message(target, message, headers={})
|
17
|
+
result = ''
|
18
|
+
result << "(#{target}): MESSAGE ["
|
19
|
+
result << headers.to_a.collect {|x| "#{x[0]}: #{x[1]}" }.join(", ")
|
20
|
+
result << "] "
|
21
|
+
result << message.split(/$/).collect {|x| "#{x}" }.join('\n')
|
22
|
+
result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/a13g/utils.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module A13g
|
2
|
+
module Utils
|
3
|
+
# It will preetify message and prepare for display, eg. in logs.
|
4
|
+
#
|
5
|
+
# @param [String] target
|
6
|
+
# message destination or source
|
7
|
+
# @param [String] message
|
8
|
+
# the message to format
|
9
|
+
# @param [Hash] headers
|
10
|
+
# message headers
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
# formatted message with headers
|
14
|
+
#
|
15
|
+
# @api public
|
16
|
+
def self.format_message(target, message, headers={})
|
17
|
+
result = ''
|
18
|
+
result << "(#{target}): MESSAGE ["
|
19
|
+
result << headers.to_a.collect {|x| "#{x[0]}: #{x[1]}" }.join(", ")
|
20
|
+
result << "] "
|
21
|
+
result << message.split(/$/).collect {|x| "#{x}" }.join('\n')
|
22
|
+
result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/a13g/version.rb
ADDED
data/spec/a13g_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "A13g" do
|
4
|
+
it "should load configuration from defult file if exists" do
|
5
|
+
A13g.setup(:default, :development)
|
6
|
+
A13g.configurations[:default][:development].should be_kind_of Hash
|
7
|
+
A13g.configurations[:default][:development][:adapter].should == 'test'
|
8
|
+
A13g.configurations[:default][:development][:host].should == 'test.com'
|
9
|
+
A13g.configurations[:default][:development][:port].should == 1234
|
10
|
+
A13g.teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow to select different location of config file" do
|
14
|
+
A13g.path.config = File.join(File.dirname(__FILE__), 'dconfig')
|
15
|
+
A13g.setup(:default, :development)
|
16
|
+
A13g.configurations[:default][:development].should be_kind_of Hash
|
17
|
+
A13g.configurations[:default][:development][:adapter].should == 'test'
|
18
|
+
A13g.configurations[:default][:development][:host].should == 'different.com'
|
19
|
+
A13g.configurations[:default][:development][:port].should == 1234
|
20
|
+
A13g.teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should properly setup connection using hash" do
|
24
|
+
A13g.setup(:default, :adapter => 'test', :host => 'mytest.com', :port => 3456)
|
25
|
+
A13g.configurations[:default][:development].should be_kind_of Hash
|
26
|
+
A13g.configurations[:default][:development][:host].should == 'mytest.com'
|
27
|
+
A13g.configurations[:default][:development][:port].should == 3456
|
28
|
+
A13g.teardown
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should allow to specify own logger" do
|
32
|
+
A13g.logger = Logger.new(out = StringIO.new)
|
33
|
+
A13g.logger.debug('Test')
|
34
|
+
out.rewind
|
35
|
+
out.gets.should == "Test\n"
|
36
|
+
A13g.teardown
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should allow to set environment" do
|
40
|
+
A13g.environment = :production
|
41
|
+
A13g.environment.should == :production
|
42
|
+
A13g.teardown
|
43
|
+
end
|
44
|
+
|
45
|
+
context "after successfully setup" do
|
46
|
+
it "should change self state" do
|
47
|
+
A13g.setup(:default)
|
48
|
+
A13g.ready?.should == true
|
49
|
+
A13g.teardown
|
50
|
+
A13g.ready?.should == false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should store context information" do
|
54
|
+
A13g.setup(:default)
|
55
|
+
A13g.contexts.values.size.should == 1
|
56
|
+
A13g.contexts.should have_key :default
|
57
|
+
A13g.teardown
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should fill in relations between context and consumer when multiple connections are established" do
|
61
|
+
A13g.setup(:default, :adapter => 'test', :host => 'first.com')
|
62
|
+
A13g.setup(:second, :adapter => 'test', :host => 'second.com')
|
63
|
+
myconsumer = Class.new(A13g::Consumer)
|
64
|
+
myconsumer.context(:second)
|
65
|
+
myconsumer.context.should_not be_nil
|
66
|
+
myconsumer.context.name.should == :second
|
67
|
+
myconsumer.context.connection.config[:host].should == 'second.com'
|
68
|
+
A13g::Base.context.should_not be_nil
|
69
|
+
A13g::Base.context.name.should == :default
|
70
|
+
A13g::Base.context.connection.config[:host].should == 'first.com'
|
71
|
+
A13g.teardown
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'a13g'
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/autorun'
|
7
|
+
|
8
|
+
#APP_ENV = 'test'
|
9
|
+
APP_LOGGER = Logger.new('/dev/null')
|
10
|
+
APP_ROOT = File.dirname(__FILE__)
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
# nothing...
|
14
|
+
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.1.0.
|
9
|
+
- beta4
|
10
|
+
version: 0.1.0.beta4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kriss Kowalik
|
@@ -72,8 +72,47 @@ extra_rdoc_files:
|
|
72
72
|
- LICENSE
|
73
73
|
- README.rdoc
|
74
74
|
files:
|
75
|
+
- .document
|
76
|
+
- .gitignore
|
75
77
|
- LICENSE
|
76
78
|
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- a13g-0.1.0.beta3.gem
|
81
|
+
- a13g.gemspec
|
82
|
+
- examples/consumer.rb
|
83
|
+
- examples/multiple_connections.rb
|
84
|
+
- examples/producer.rb
|
85
|
+
- examples/simple_project/README
|
86
|
+
- examples/simple_project/Rakefile
|
87
|
+
- examples/simple_project/config/broker.yml
|
88
|
+
- examples/simple_project/lib/consumers/first_consumer.rb
|
89
|
+
- examples/simple_project/lib/consumers/second_consumer.rb
|
90
|
+
- examples/simple_project/lib/simple_project.rb
|
91
|
+
- lib/a13g.rb
|
92
|
+
- lib/a13g/adapters.rb
|
93
|
+
- lib/a13g/adapters/abstract_adapter.rb
|
94
|
+
- lib/a13g/adapters/stomp_adapter.rb
|
95
|
+
- lib/a13g/adapters/test_adapter.rb
|
96
|
+
- lib/a13g/base.rb
|
97
|
+
- lib/a13g/command.rb
|
98
|
+
- lib/a13g/consumer.rb
|
99
|
+
- lib/a13g/destination.rb
|
100
|
+
- lib/a13g/errors.rb
|
101
|
+
- lib/a13g/listener.rb
|
102
|
+
- lib/a13g/message.rb
|
103
|
+
- lib/a13g/producer.rb
|
104
|
+
- lib/a13g/railtie.rb
|
105
|
+
- lib/a13g/recipes.rb
|
106
|
+
- lib/a13g/subscription.rb
|
107
|
+
- lib/a13g/support/logger.rb
|
108
|
+
- lib/a13g/support/utils.rb
|
109
|
+
- lib/a13g/utils.rb
|
110
|
+
- lib/a13g/version.rb
|
111
|
+
- spec/a13g_spec.rb
|
112
|
+
- spec/config/broker.yml
|
113
|
+
- spec/dconfig/broker.yml
|
114
|
+
- spec/spec.opts
|
115
|
+
- spec/spec_helper.rb
|
77
116
|
has_rdoc: true
|
78
117
|
homepage: http://github.com/kriss/a13g
|
79
118
|
licenses: []
|
@@ -106,5 +145,12 @@ rubygems_version: 1.3.6
|
|
106
145
|
signing_key:
|
107
146
|
specification_version: 3
|
108
147
|
summary: Event-driven architecture for your applications
|
109
|
-
test_files:
|
110
|
-
|
148
|
+
test_files:
|
149
|
+
- spec/a13g_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- examples/consumer.rb
|
152
|
+
- examples/multiple_connections.rb
|
153
|
+
- examples/simple_project/lib/consumers/second_consumer.rb
|
154
|
+
- examples/simple_project/lib/consumers/first_consumer.rb
|
155
|
+
- examples/simple_project/lib/simple_project.rb
|
156
|
+
- examples/producer.rb
|