sorceror_poseidon_cluster 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ac4eb0c0f6888a859f4f012f47752acb205d505
4
+ data.tar.gz: 42f48d6f7a371bd13f4314ae07a264e3e2ed98eb
5
+ SHA512:
6
+ metadata.gz: 696a4c9c05a130fbefa0cee2d16e4342eceaba6c8b831cbf152ee5b7fe23be50ecd4d518c0b4192976344ba75fd2d60308d849cbe1e59a38beaef795cca198a8
7
+ data.tar.gz: 102108f9c8a696c3d9e71064459261ce7a08d829211b5518ad41424cffa948589d1ee2bd7348a89df4dbc91e47a15b8180f914dbf87f89cdb8d824ecb65b5e9f
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ logs/
2
+ kafka*/
3
+ doc/
4
+ .yardoc/
5
+ .bundle/
6
+ pkg/
7
+ coverage/
8
+ *.log
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ script: bundle exec rake spec:coveralls scenario
6
+ matrix:
7
+ fast_finish: true
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'pry'
6
+
7
+ platform :jruby do
8
+ gem 'slyphon-log4j', '= 1.2.15'
9
+ gem 'slyphon-zookeeper_jar', '= 3.3.5'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ poseidon_cluster (0.3.0)
5
+ poseidon (>= 0.0.5.pre1)
6
+ zk
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.0)
12
+ coveralls (0.7.0)
13
+ multi_json (~> 1.3)
14
+ rest-client
15
+ simplecov (>= 0.7)
16
+ term-ansicolor
17
+ thor
18
+ diff-lcs (1.2.5)
19
+ docile (1.1.3)
20
+ little-plugger (1.1.3)
21
+ logging (1.8.2)
22
+ little-plugger (>= 1.1.3)
23
+ multi_json (>= 1.8.4)
24
+ method_source (0.8.2)
25
+ mime-types (2.3)
26
+ multi_json (1.10.1)
27
+ poseidon (0.0.5.pre1)
28
+ pry (0.10.1)
29
+ coderay (~> 1.1.0)
30
+ method_source (~> 0.8.1)
31
+ slop (~> 3.4)
32
+ rake (10.3.2)
33
+ rest-client (1.6.7)
34
+ mime-types (>= 1.16)
35
+ rspec (3.0.0)
36
+ rspec-core (~> 3.0.0)
37
+ rspec-expectations (~> 3.0.0)
38
+ rspec-mocks (~> 3.0.0)
39
+ rspec-core (3.0.0)
40
+ rspec-support (~> 3.0.0)
41
+ rspec-expectations (3.0.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.0.0)
44
+ rspec-its (1.0.1)
45
+ rspec-core (>= 2.99.0.beta1)
46
+ rspec-expectations (>= 2.99.0.beta1)
47
+ rspec-mocks (3.0.0)
48
+ rspec-support (~> 3.0.0)
49
+ rspec-support (3.0.0)
50
+ simplecov (0.8.2)
51
+ docile (~> 1.1.0)
52
+ multi_json
53
+ simplecov-html (~> 0.8.0)
54
+ simplecov-html (0.8.0)
55
+ slop (3.6.0)
56
+ slyphon-log4j (1.2.15)
57
+ slyphon-zookeeper_jar (3.3.5-java)
58
+ term-ansicolor (1.3.0)
59
+ tins (~> 1.0)
60
+ thor (0.19.1)
61
+ tins (1.3.0)
62
+ yard (0.8.7.4)
63
+ zk (1.9.4)
64
+ logging (~> 1.8.2)
65
+ zookeeper (~> 1.4.0)
66
+ zookeeper (1.4.9)
67
+ zookeeper (1.4.9-java)
68
+ slyphon-log4j (= 1.2.15)
69
+ slyphon-zookeeper_jar (= 3.3.5)
70
+
71
+ PLATFORMS
72
+ java
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler
77
+ coveralls
78
+ poseidon_cluster!
79
+ pry
80
+ rake
81
+ rspec
82
+ rspec-its
83
+ slyphon-log4j (= 1.2.15)
84
+ slyphon-zookeeper_jar (= 3.3.5)
85
+ yard
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Poseidon Cluster [![Build Status](https://travis-ci.org/bsm/poseidon_cluster.png?branch=master)](https://travis-ci.org/bsm/poseidon_cluster) [![Coverage Status](https://coveralls.io/repos/bsm/poseidon_cluster/badge.png?branch=master)](https://coveralls.io/r/bsm/poseidon_cluster?branch=master)
2
+
3
+ Poseidon Cluster is a cluster extension of the excellent [Poseidon](http://github.com/bpot/poseidon) Ruby client for Kafka 0.8+. It implements the distribution concept of self-rebalancing *Consumer Groups* and supports the consumption of a single topic from multiple instances.
4
+
5
+ Consumer group instances share a common group name, and each message published to a topic is delivered to one instance within each subscribing consumer group. Consumer instances can be in separate processes or on separate machines.
6
+
7
+ ## Usage
8
+
9
+ Launch a consumer group:
10
+
11
+ ```ruby
12
+ require 'poseidon_cluster'
13
+
14
+ consumer = Poseidon::ConsumerGroup.new(
15
+ "my-group", # Group name
16
+ ["kafka1.host:9092", "kafka2.host:9092"], # Kafka brokers
17
+ ["kafka1.host:2181", "kafka2.host:2181"], # Zookeepers hosts
18
+ "my-topic") # Topic name
19
+
20
+ consumer.partitions # => [0, 1, 2, 3] - all partitions of 'my-topic'
21
+ consumer.claimed # => [0, 1] - partitions this instance has claimed
22
+ ```
23
+
24
+ Fetch a bulk of messages, auto-commit the offset:
25
+
26
+ ```ruby
27
+ consumer.fetch do |partition, bulk|
28
+ bulk.each do |m|
29
+ puts "Fetched '#{m.value}' at #{m.offset} from #{partition}"
30
+ end
31
+ end
32
+ ```
33
+
34
+ Get the offset for a partition:
35
+
36
+ ```ruby
37
+ consumer.offset(0) # => 320 - current offset from partition 0
38
+ ```
39
+
40
+ Fetch more messages, commit manually:
41
+
42
+ ```ruby
43
+ consumer.fetch commit: false do |partition, bulk|
44
+ bulk.each do |m|
45
+ puts "Fetched '#{m.value}' at #{m.offset} from #{partition}"
46
+ end
47
+
48
+ consumer.commit partition, bulk.last.offset+1 unless bulk.empty?
49
+ end
50
+ ```
51
+
52
+ Initiate a fetch-loop, consume indefinitely:
53
+
54
+ ```ruby
55
+ consumer.fetch_loop do |partition, bulk|
56
+ bulk.each do |m|
57
+ puts "Fetched '#{m.value}' at #{m.offset} from #{partition}"
58
+ end
59
+ end
60
+ ```
61
+
62
+ For more details and information, please see the [Poseidon::ConsumerGroup](http://rubydoc.info/github/bsm/poseidon_cluster/Poseidon/ConsumerGroup) documentation and the [Examples](https://github.com/bsm/poseidon_cluster/tree/master/examples).
63
+
64
+ ## Running Tests
65
+
66
+ The test suite will automatically download, configure and run Kafka locally, you only need a JRE. Run the suite via:
67
+
68
+ ```bash
69
+ bundle exec rake spec
70
+ ```
71
+
72
+ ## Licence
73
+
74
+ ```
75
+ Copyright (c) 2014 Black Square Media
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining
78
+ a copy of this software and associated documentation files (the
79
+ "Software"), to deal in the Software without restriction, including
80
+ without limitation the rights to use, copy, modify, merge, publish,
81
+ distribute, sublicense, and/or sell copies of the Software, and to
82
+ permit persons to whom the Software is furnished to do so, subject to
83
+ the following conditions:
84
+
85
+ The above copyright notice and this permission notice shall be
86
+ included in all copies or substantial portions of the Software.
87
+
88
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
91
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
92
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
93
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
94
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
95
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'yard'
7
+ require 'yard/rake/yardoc_task'
8
+ YARD::Rake::YardocTask.new
9
+
10
+ require 'coveralls/rake/task'
11
+ Coveralls::RakeTask.new
12
+ namespace :spec do
13
+ task coveralls: [:spec, 'coveralls:push']
14
+ end
15
+
16
+ desc "Run full integration test scenario"
17
+ task :scenario do
18
+ load File.expand_path("../scenario/run.rb", __FILE__)
19
+ end
20
+
21
+ task default: :spec
@@ -0,0 +1,33 @@
1
+ =begin
2
+
3
+ PLEASE NOTE
4
+
5
+ This example uses threads, but you could equally use fork or run your
6
+ consumer groups from completely separate process and from multiple machines.
7
+
8
+ =end
9
+ require 'poseidon_cluster'
10
+
11
+ # Create a consumer group
12
+ group1 = Poseidon::ConsumerGroup.new "my-group", ["host1:9092", "host2:9092"], ["host1:2181", "host2:2181"], "my-topic"
13
+
14
+ # Start consuming "my-topic" in a background thread
15
+ thread1 = Thread.new do
16
+ group1.fetch_loop do |partition, messages|
17
+ puts "Consumer #1 fetched #{messages.size} from #{partition}"
18
+ end
19
+ end
20
+
21
+ # Create a second consumer group
22
+ group2 = Poseidon::ConsumerGroup.new "my-group", ["host1:9092", "host2:9092"], ["host1:2181", "host2:2181"], "my-topic"
23
+
24
+ # Now consuming all partitions of "my-topic" in parallel
25
+ thread2 = Thread.new do
26
+ group2.fetch_loop do |partition, messages|
27
+ puts "Consumer #2 fetched #{messages.size} from #{partition}"
28
+ end
29
+ end
30
+
31
+ # Join threads, loop forever
32
+ [thread1, thread2].each(&:join)
33
+
@@ -0,0 +1,28 @@
1
+ require 'socket'
2
+ require 'timeout'
3
+ require 'zk'
4
+ require 'poseidon'
5
+ require 'thread'
6
+
7
+ module Poseidon::Cluster
8
+ MAX_INT32 = 0x7fffffff
9
+ @@sem = Mutex.new
10
+ @@inc = 0
11
+
12
+ # @return [Integer] an incremented number
13
+ # @api private
14
+ def self.inc!
15
+ @@sem.synchronize { @@inc += 1; @@inc = 1 if @@inc > MAX_INT32; @@inc }
16
+ end
17
+
18
+ # @return [String] an globally unique identifier
19
+ # @api private
20
+ def self.guid
21
+ [::Socket.gethostname, ::Process.pid, ::Time.now.to_i, inc!].join("-")
22
+ end
23
+
24
+ end
25
+
26
+ %w|consumer_group|.each do |name|
27
+ require "poseidon/#{name}"
28
+ end