klomp 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order rand
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ SimpleCov.start do
4
+ add_filter '/vendor/'
5
+
6
+ add_group "Loldance", "lib"
7
+ add_group "Specs", "spec"
8
+ end
@@ -1,6 +1,16 @@
1
- Changes
1
+ Klomp Changes
2
2
  --------------------------------------------------------------------------------
3
3
 
4
+ 1.0.0 (2012/10/3)
5
+ ================================================================================
6
+
7
+ - BREAKING CHANGES from previous release. You will need to revisit and change
8
+ all code that depends on Klomp 0.0.x
9
+ - ground-up rewrite to eliminate onstomp dependency
10
+ - Klomp::Client => Klomp
11
+ - preserves similar API but with fewer bells and whistles
12
+ - read latest README.md for details
13
+
4
14
  0.0.8 (2012/8/15)
5
15
  ================================================================================
6
16
 
data/Gemfile CHANGED
@@ -1,12 +1,18 @@
1
- source "http://rubygems.org"
2
-
3
- gem "onstomp", "~> 1.0.7"
4
- # gem 'onstomp', :path => '../onstomp'
5
- gem "json"
6
- gem "uuid", "~> 2.3.5"
7
-
8
- group :development do
9
- gem "foreman"
10
- gem "rake"
11
- gem "ZenTest"
12
- end
1
+ # -*- ruby -*-
2
+
3
+ # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
+
5
+ source :gemcutter
6
+
7
+
8
+ gem "rdoc", "~>3.10", :group => [:development, :test]
9
+ gem "hoe-bundler", "~>1.1.0", :group => [:development, :test]
10
+ gem "hoe-gemspec", "~>1.0.0", :group => [:development, :test]
11
+ gem "hoe-git", "~>1.5.0", :group => [:development, :test]
12
+ gem "rspec", "~>2.11.0", :group => [:development, :test]
13
+ gem "ZenTest", "~>4.8.0", :group => [:development, :test]
14
+ gem "rspec-given", "~>1.0", :group => [:development, :test]
15
+ gem "simplecov", "~>0.6.0", :group => [:development, :test]
16
+ gem "hoe", "~>3.0", :group => [:development, :test]
17
+
18
+ # vim: syntax=ruby
@@ -2,25 +2,45 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  ZenTest (4.8.0)
5
- foreman (0.46.0)
6
- thor (>= 0.13.6)
7
- json (1.7.1)
8
- macaddr (1.6.1)
9
- systemu (~> 2.5.0)
10
- onstomp (1.0.7)
5
+ diff-lcs (1.1.3)
6
+ hoe (3.0.3)
7
+ rake (~> 0.8)
8
+ hoe-bundler (1.1.0)
9
+ hoe (>= 2.2.0)
10
+ hoe-gemspec (1.0.0)
11
+ hoe (>= 2.2.0)
12
+ hoe-git (1.5.0)
13
+ hoe (>= 2.2.0)
14
+ json (1.6.6)
15
+ multi_json (1.3.6)
11
16
  rake (0.9.2.2)
12
- systemu (2.5.1)
13
- thor (0.15.2)
14
- uuid (2.3.5)
15
- macaddr (~> 1.0)
17
+ rdoc (3.12)
18
+ json (~> 1.4)
19
+ rspec (2.11.0)
20
+ rspec-core (~> 2.11.0)
21
+ rspec-expectations (~> 2.11.0)
22
+ rspec-mocks (~> 2.11.0)
23
+ rspec-core (2.11.1)
24
+ rspec-expectations (2.11.3)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-given (1.5.0)
27
+ rspec (> 1.2.8)
28
+ rspec-mocks (2.11.3)
29
+ simplecov (0.6.4)
30
+ multi_json (~> 1.0)
31
+ simplecov-html (~> 0.5.3)
32
+ simplecov-html (0.5.3)
16
33
 
17
34
  PLATFORMS
18
35
  ruby
19
36
 
20
37
  DEPENDENCIES
21
- ZenTest
22
- foreman
23
- json
24
- onstomp (~> 1.0.7)
25
- rake
26
- uuid (~> 2.3.5)
38
+ ZenTest (~> 4.8.0)
39
+ hoe (~> 3.0)
40
+ hoe-bundler (~> 1.1.0)
41
+ hoe-gemspec (~> 1.0.0)
42
+ hoe-git (~> 1.5.0)
43
+ rdoc (~> 3.10)
44
+ rspec (~> 2.11.0)
45
+ rspec-given (~> 1.0)
46
+ simplecov (~> 0.6.0)
@@ -0,0 +1,31 @@
1
+ .rspec
2
+ .simplecov
3
+ ChangeLog.md
4
+ Gemfile
5
+ Gemfile.lock
6
+ Manifest.txt
7
+ README.md
8
+ Rakefile
9
+ klomp.gemspec
10
+ lib/klomp.rb
11
+ lib/klomp/connection.rb
12
+ lib/klomp/frames.rb
13
+ lib/klomp/sentinel.rb
14
+ spec/acceptance/acceptance_spec.rb
15
+ spec/frames/auth_error.txt
16
+ spec/frames/connect.txt
17
+ spec/frames/connect_vhost.txt
18
+ spec/frames/connected.txt
19
+ spec/frames/disconnect.txt
20
+ spec/frames/error.txt
21
+ spec/frames/greeting.txt
22
+ spec/frames/message.txt
23
+ spec/frames/receipt.txt
24
+ spec/frames/subscribe.txt
25
+ spec/frames/unsubscribe.txt
26
+ spec/klomp/connection_spec.rb
27
+ spec/klomp/frames_spec.rb
28
+ spec/klomp/sentinel_spec.rb
29
+ spec/klomp_spec.rb
30
+ spec/spec_helper.rb
31
+ spec/support/have_received.rb
data/README.md CHANGED
@@ -1,115 +1,137 @@
1
- # Klomp
2
-
3
- Klomp is a simple wrapper around the [OnStomp](https://github.com/meadvillerb/onstomp/)
4
- library with some additional HA and usability features:
5
-
6
- * When initialized with multiple broker URIs, Klomp will publish messages to
7
- one broker at a time, but will consume from all brokers simultaneously. This is
8
- a slight improvement over the regular [OnStomp::Failover::Client](http://mdvlrb.com/onstomp/OnStomp/Failover/Client.html)
9
- which handles all publishing and subscribing through a single "active" broker.
10
- This traditional one-broker-at-a-time technique can lead to a split-brain
11
- scenario in which messages are only received by a subset of your STOMP clients.
12
- By consuming from all brokers simultaneously, Klomp ensures that no message is
13
- left behind.
14
-
15
- * Where applicable, message bodies are automatically translated between native
16
- Ruby and JSON objects.
17
-
18
- * If a reply-to header is found in a message, a response is automatically
19
- sent to the reply-to destination. The response will be the return value of the
20
- subscribe block.
21
-
22
- ## Installation
23
-
24
- gem install klomp
25
-
26
- ## Example usage
27
-
28
- The goal is that you should be able to use most (if not all) of the standard
29
- OnStomp API (see [OnStomp's UserNarrative](https://github.com/meadvillerb/onstomp/blob/master/extra_doc/UserNarrative.md))
30
- via a `Klomp::Client`:
31
-
32
- client = Klomp::Client.new([ ... ])
33
-
34
- However, there will be some differences in the API due to how `Klomp::Client`
35
- manages connections. For example, while the `connected?` method normally
36
- returns a boolean value, Klomp's `connected?` will return an array of booleans
37
- (i.e. one result for each broker).
38
-
39
- ### Fibonacci back-off retry behavior
40
-
41
- The OnStomp failover client takes `:retry_attempts` and `:retry_delay` options,
42
- and Klomp supports these too. However, if you do not specify either of these
43
- values, Klomp's default behavior will be to try to reconnect indefinitely, but
44
- use a fibonacci backoff approach, i.e., it will wait `fib(N)` seconds before
45
- trying to reconnect on the Nth attempt.
46
-
47
- ### Message IDs
48
-
49
- Klomp uses the `uuid` gem to generate per-message unique identifiers. To disable
50
- generated message IDs, pass `:uuid => false` in the options hash. To customize
51
- to use your own generator, simply pass `:uuid => object` where the object you
52
- pass implements a `#generate` method that returns a string ID.
53
-
54
- ### Additional options for Klomp::Client
55
-
56
- <table>
57
- <tr>
58
- <th>Key</th>
59
- <th>Default value</th>
60
- <th>Description</th>
61
- </tr>
62
- <tr>
63
- <td>:translate_json</td>
64
- <td>true</td>
65
- <td>Translate message bodies between native Ruby and JSON objects?</td>
66
- </tr>
67
- <tr>
68
- <td>:auto_reply_to</td>
69
- <td>true</td>
70
- <td>Automatically send response to reply-to destination?</td>
71
- </tr>
72
- <tr>
73
- <td>:logger</td>
74
- <td>false</td>
75
- <td>Logger object</td>
76
- </tr>
77
- <tr>
78
- <td>:uuid</td>
79
- <td>UUID.new</td>
80
- <td>UUID generator object, responds to :generate and returns an ID</td>
81
- </tr>
82
- <tr>
83
- <td>:vhost</td>
84
- <td>nil</td>
85
- <td>override Apollo virtual host</td>
86
- </tr>
87
- </table>
88
-
89
- ## Developers
90
-
91
- Set up the environment using `bundle install`. Note that the tests currently
92
- assume a specific Apollo configuration which can be created on OSX using the
93
- following commands:
94
-
95
- brew install apollo
96
- apollo create /usr/local/var/apollo-primary
97
- apollo create /usr/local/var/apollo-secondary
98
- sed -i -e 's/616/626/' /usr/local/var/apollo-secondary/etc/apollo.xml
99
-
100
- Once Apollo is configured, the brokers can be started via `foreman start`. Now
101
- you can run the test suite via `rake test` or `autotest`.
102
-
103
- In addition to the regular test suite, there is a rake task called
104
- "test_failover" that will start an infinite publish/subscribe loop. Once this
105
- task is running, you can randomly kill Apollo brokers to test STOMP client
106
- failover.
107
-
108
- ## Change Log
109
-
110
- See the [ChangeLog file](/livingsocial/klomp/blob/master/ChangeLog.md).
111
-
112
- ## License
1
+ # klomp
2
+
3
+ * http://github.com/livingsocial/klomp
4
+
5
+ ## DESCRIPTION:
6
+
7
+ Klomp is a simple [Stomp] messaging client that keeps your sanity intact.
8
+
9
+ The purpose of Klomp is to be the simplest possible Stomp client. No in-memory
10
+ buffering of outgoing messages, no fanout subscriptions in-process, no
11
+ transactions, no complicated messaging patterns. Code simple enough so that when
12
+ something goes wrong, the problem is obvious.
13
+
14
+ [Stomp]: http://stomp.github.com/
15
+
16
+ ## FEATURES:
17
+
18
+ The API surface area is minimal. `Klomp#publish` and `Klomp#subscribe` are your
19
+ main endpoints.
20
+
21
+ ```ruby
22
+ klomp = Klomp.new(["127.0.0.1:61613"], "login" => "mylogin", "passcode" => "mypassword")
23
+
24
+ klomp.publish("/queue/klomp", "sanity")
25
+
26
+ # subscribe with a block that gets invoked for each message
27
+ klomp.subscribe("/queue/klomp") do |msg|
28
+ puts msg.body # => sanity
29
+ end
30
+
31
+ # subscribe with an object that gets #call'd
32
+ class Klompen
33
+ def call(msg)
34
+ puts msg.body
35
+ end
36
+ end
37
+ # replaces previous subscribe block above
38
+ klomp.subscribe("/queue/klomp", Klompen.new)
39
+ klomp.unsubscribe("/queue/klomp")
40
+
41
+ klomp.disconnect
42
+ ```
43
+
44
+ ### Connecting
45
+
46
+ Connections are established when a `Klomp` object is constructed. Connections
47
+ can be established in several ways.
48
+
49
+ ```ruby
50
+ # Pass a single string containing host:port
51
+ klomp = Klomp.new "localhost:61613"
52
+
53
+ # Authentication with 'login' and 'passcode'
54
+ klomp = Klomp.new "localhost:61613", "login" => "bob", "passcode" => "farmville"
55
+
56
+ # With a stomp:// URL
57
+ klomp = Klomp.new "stomp://bob:farmville@localhost:61613"
58
+ ```
59
+
60
+ #### Load-balancing
61
+
62
+ Klomp can be used to load-balance and maintain connections to multiple broker
63
+ hosts, such that if one broker goes down, the remaining broker(s) will be used.
64
+ Each broker is expected to provide an identical list of queues. To ensure
65
+ delivery, all Stomp clients should be connected to all brokers in the
66
+ load-balancing scenario.
67
+
68
+ Publish semantics are slightly different than those for subscribe:
69
+
70
+ - *Publish*: Klomp will publish each message on a randomly-selected broker.
71
+ - *Subscribe*: each Klomp object subscribes to the provided queues on all hosts.
72
+
73
+ Load-balanced connections are achieved with an array of servers.
74
+
75
+ ```ruby
76
+ klomp = Klomp.new ["broker-001:61613", "broker-002:61613"]
77
+ klomp = Klomp.new ["broker-001:61613", "broker-002:61613"], "login" => "bob", "passcode" => "farmville"
78
+ klomp = Klomp.new ["stomp://bob:farmville@broker-001:61613", "stomp://bob:farmville@broker-002:61613"]
79
+ ```
80
+
81
+ #### Virtual hosts
82
+
83
+ Klomp can use the Stomp 1.1 "virtual host" feature in several ways.
84
+
85
+ ```ruby
86
+ # additional name in colon-separated triple
87
+ klomp = Klomp.new "virtual-host:localhost:61613"
88
+ # host option in constructor
89
+ klomp = Klomp.new "localhost:61613", "host" => "virtual-host"
90
+ # host query parameter in stomp:// url
91
+ klomp = Klomp.new "stomp://bob:farmville@localhost:61613?host=virtual-host"
92
+ ```
93
+
94
+ #### Automatic reconnect
95
+
96
+ If a Klomp connection experiences errors reading from or writing to its socket,
97
+ the connection will go into an "offline" state. A sentinel thread will be
98
+ started that attempts to reconnect periodically at Fibonacci back-off intervals.
99
+
100
+ #### Logging
101
+
102
+ Klomp accepts a `Logger` object in the constructor options hash.
103
+
104
+ ```ruby
105
+ klomp = Klomp.new "localhost:61613", "logger" => Logger.new($stdout)
106
+ ```
107
+
108
+ Background exceptions that occur in the subscriber thread as well as offline and
109
+ reconnect events will be logged at the `warn` level, while individual sent and
110
+ received message frames will be logged at the `debug` level.
111
+
112
+ ## REQUIREMENTS / LIMITATIONS:
113
+
114
+ - Only supports [Stomp 1.1](http://stomp.github.com/stomp-specification-1.1.html)
115
+ - Only one subscription per queue per Klomp
116
+ - Only one handler object/block per queue. If you want to multi-dispatch a
117
+ message, write your own dispatcher.
118
+ - Only supports the following frames:
119
+ - CONNECT/CONNECTED (initial handshake)
120
+ - SEND
121
+ - SUBSCRIBE
122
+ - UNSUBSCRIBE
123
+ - DISCONNECT
124
+ - MESSAGE
125
+ - ERROR
126
+ - Not supported:
127
+ - ACK/NACK
128
+ - BEGIN/COMMIT/ABORT
129
+ - RECEIPT
130
+ - ack/receipt headers
131
+
132
+ ## LICENSE:
133
+
134
+ The MIT License
113
135
 
114
136
  Copyright (C) 2012 LivingSocial
115
137
 
@@ -130,7 +152,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130
152
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131
153
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
132
154
  SOFTWARE.
133
-
134
- ## Credits
135
-
136
- * [Michael Paul Thomas Conigliaro](http://conigliaro.org): Original author
data/Rakefile CHANGED
@@ -1,8 +1,21 @@
1
1
  require 'bundler/setup'
2
- require 'bundler/gem_tasks'
3
- require 'rake/testtask'
2
+ require 'hoe'
4
3
 
5
- Dir.glob('tasks/*.rake').each { |r| import r }
4
+ Hoe.plugin :bundler, :git, :gemspec, :gemcutter
6
5
 
7
- Rake::TestTask.new
8
- task :default => :test
6
+ Hoe.spec 'klomp' do
7
+ developer 'Nick Sieger', 'nick.sieger@livingsocial.com'
8
+
9
+ ### Use markdown for changelog and readme
10
+ self.history_file = 'CHANGELOG.md'
11
+ self.readme_file = 'README.md'
12
+
13
+ ### dependencies!
14
+ self.extra_dev_deps << [ 'hoe-bundler', '~> 1.1.0' ]
15
+ self.extra_dev_deps << [ 'hoe-gemspec', '~> 1.0.0' ]
16
+ self.extra_dev_deps << [ 'hoe-git', '~> 1.5.0' ]
17
+ self.extra_dev_deps << [ 'rspec', '~> 2.11.0' ]
18
+ self.extra_dev_deps << [ 'ZenTest', '~> 4.8.0' ]
19
+ self.extra_dev_deps << [ 'rspec-given', '~> 1.0' ]
20
+ self.extra_dev_deps << [ 'simplecov', '~> 0.6.0' ]
21
+ end
@@ -1,21 +1,56 @@
1
- $:.push File.expand_path(File.join(File.dirname(__FILE__), "lib"))
2
- require 'klomp'
1
+ # -*- encoding: utf-8 -*-
3
2
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["LivingSocial"]
6
- gem.email = ["dev.happiness@livingsocial.com"]
7
- gem.description = "A simple wrapper around the OnStomp library with additional features"
8
- gem.summary = "A simple wrapper around the OnStomp library with additional features"
9
- gem.homepage = "https://github.com/livingsocial/klomp"
3
+ Gem::Specification.new do |s|
4
+ s.name = "klomp"
5
+ s.version = "1.0.0"
10
6
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "klomp"
15
- gem.require_paths = ["lib"]
16
- gem.version = Klomp::VERSION
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Nick Sieger"]
9
+ s.date = "2012-10-03"
10
+ s.description = "Klomp is a simple [Stomp] messaging client that keeps your sanity intact.\n\nThe purpose of Klomp is to be the simplest possible Stomp client. No in-memory\nbuffering of outgoing messages, no fanout subscriptions in-process, no\ntransactions, no complicated messaging patterns. Code simple enough so that when\nsomething goes wrong, the problem is obvious.\n\n[Stomp]: http://stomp.github.com/"
11
+ s.email = ["nick.sieger@livingsocial.com"]
12
+ s.extra_rdoc_files = ["Manifest.txt"]
13
+ s.files = [".rspec", ".simplecov", "ChangeLog.md", "Gemfile", "Gemfile.lock", "Manifest.txt", "README.md", "Rakefile", "klomp.gemspec", "lib/klomp.rb", "lib/klomp/connection.rb", "lib/klomp/frames.rb", "lib/klomp/sentinel.rb", "spec/acceptance/acceptance_spec.rb", "spec/frames/auth_error.txt", "spec/frames/connect.txt", "spec/frames/connect_vhost.txt", "spec/frames/connected.txt", "spec/frames/disconnect.txt", "spec/frames/error.txt", "spec/frames/greeting.txt", "spec/frames/message.txt", "spec/frames/receipt.txt", "spec/frames/subscribe.txt", "spec/frames/unsubscribe.txt", "spec/klomp/connection_spec.rb", "spec/klomp/frames_spec.rb", "spec/klomp/sentinel_spec.rb", "spec/klomp_spec.rb", "spec/spec_helper.rb", "spec/support/have_received.rb", ".gemtest"]
14
+ s.homepage = "http://github.com/livingsocial/klomp"
15
+ s.rdoc_options = ["--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "klomp"
18
+ s.rubygems_version = "1.8.24"
19
+ s.summary = "Klomp is a simple [Stomp] messaging client that keeps your sanity intact"
17
20
 
18
- gem.add_dependency("onstomp", "~> 1.0.7")
19
- gem.add_dependency("json")
20
- gem.add_dependency("uuid", "~> 2.3.5")
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
26
+ s.add_development_dependency(%q<hoe-bundler>, ["~> 1.1.0"])
27
+ s.add_development_dependency(%q<hoe-gemspec>, ["~> 1.0.0"])
28
+ s.add_development_dependency(%q<hoe-git>, ["~> 1.5.0"])
29
+ s.add_development_dependency(%q<rspec>, ["~> 2.11.0"])
30
+ s.add_development_dependency(%q<ZenTest>, ["~> 4.8.0"])
31
+ s.add_development_dependency(%q<rspec-given>, ["~> 1.0"])
32
+ s.add_development_dependency(%q<simplecov>, ["~> 0.6.0"])
33
+ s.add_development_dependency(%q<hoe>, ["~> 3.0"])
34
+ else
35
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
36
+ s.add_dependency(%q<hoe-bundler>, ["~> 1.1.0"])
37
+ s.add_dependency(%q<hoe-gemspec>, ["~> 1.0.0"])
38
+ s.add_dependency(%q<hoe-git>, ["~> 1.5.0"])
39
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
40
+ s.add_dependency(%q<ZenTest>, ["~> 4.8.0"])
41
+ s.add_dependency(%q<rspec-given>, ["~> 1.0"])
42
+ s.add_dependency(%q<simplecov>, ["~> 0.6.0"])
43
+ s.add_dependency(%q<hoe>, ["~> 3.0"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
47
+ s.add_dependency(%q<hoe-bundler>, ["~> 1.1.0"])
48
+ s.add_dependency(%q<hoe-gemspec>, ["~> 1.0.0"])
49
+ s.add_dependency(%q<hoe-git>, ["~> 1.5.0"])
50
+ s.add_dependency(%q<rspec>, ["~> 2.11.0"])
51
+ s.add_dependency(%q<ZenTest>, ["~> 4.8.0"])
52
+ s.add_dependency(%q<rspec-given>, ["~> 1.0"])
53
+ s.add_dependency(%q<simplecov>, ["~> 0.6.0"])
54
+ s.add_dependency(%q<hoe>, ["~> 3.0"])
55
+ end
21
56
  end