visfleet-pipeline_toolkit 0.1.0 → 0.2.0

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/README.rdoc CHANGED
@@ -1,7 +1,54 @@
1
- = pipeline_toolkit
1
+ Pipeline Toolkit
2
2
 
3
- Description goes here.
3
+ Command line tools for processing messages by constructing a pipeline of workers. AMQP and Unix pipes are used to construct the pipeline. Messages are simple Hashs (serialized as YAML) so they can hold any values and change throughout the processing.
4
+
5
+ Provides:
6
+ - Processing acknowledgments, ensuring the a message is only disposed of once it has been successful processed
7
+ - Performance. Messages are moved through the pipeline fast
8
+ - Command line tools for:
9
+ - Subscribing to messages from an AMQP queue
10
+ - Pushing messages back onto an AMQP exchange
11
+ - Monitoring performance (see msg_probe)
12
+ - A base module (MessageCommand) to include into your own classes to quickly make workers.
13
+
14
+ == Install
15
+
16
+ > gem sources -a http://gems.github.com
17
+ > sudo gem install visfleet-pipeline_toolkit
18
+
19
+ === Dependancies
20
+
21
+ It is assumed that you have:
22
+ - An AMQP msg server to pop and push messages to (e.g. http://www.rabbitmq.com/)
23
+ - A *nix system, such as Linux or Mac OS X.
24
+
25
+ == Usage
26
+
27
+ 1. Create your worker
28
+
29
+ class MyWorker
30
+ include MessageCommand
31
+
32
+ def process_message(msg)
33
+ # do stuff here
34
+ msg
35
+ end
36
+ end
37
+
38
+ MyWorker.new.start
39
+
40
+ 2. Hook it up to the main pipe (i.e. the AMQP server)
41
+
42
+ > msg_subscribe.rb -q source | my_worker.rb | msg_push.rb -x dest
43
+
44
+ You can learn more about the command line tools and what options are available by using their help command.
45
+
46
+ > msg_subscriber --help
47
+ > msg_push --help
48
+ > msg_sink --help
49
+ > msg_probe --help
50
+
51
+
52
+
4
53
 
5
- == Copyright
6
54
 
7
- Copyright (c) 2009 Aisha Fenton. See LICENSE for details.
data/Rakefile CHANGED
@@ -9,7 +9,12 @@ begin
9
9
  gem.email = "labs@visfleet.com"
10
10
  gem.homepage = "http://github.com/visfleet/pipeline_toolkit"
11
11
  gem.authors = ["Aisha Fenton"]
12
- gem.executables = ["msg_probe.rb", "msg_subscribe.rb", "msg_push.rb", "msg_pop.rb", "msg_sink.rb"]
12
+ gem.executables = ["msg_probe.rb", "msg_subscribe.rb", "msg_push.rb", "msg_sink.rb"]
13
+ gem.add_runtime_dependency('tmm1-amqp')
14
+ gem.add_runtime_dependency('trollop')
15
+ gem.add_runtime_dependency('eventmachine')
16
+ # FIXME. Want to remove dependency on this for public version
17
+ gem.add_runtime_dependency('visfleet-default_logging')
13
18
  end
14
19
 
15
20
  rescue LoadError
@@ -36,7 +41,6 @@ rescue LoadError
36
41
  end
37
42
  end
38
43
 
39
-
40
44
  task :default => :test
41
45
 
42
46
  require 'rake/rdoctask'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,4 +1,4 @@
1
- require "pipeline_toolkit/central_logger"
1
+ require "default_logging"
2
2
  require "pipeline_toolkit/message_coder"
3
3
  require "pipeline_toolkit/message_command"
4
4
  require "pipeline_toolkit/message_probe"
@@ -23,7 +23,7 @@ class MessagePusher
23
23
  @exchanges = []
24
24
  @exchange_names.each do |name, type|
25
25
  type ||= :fanout
26
- @exchanges << MQ::Exchange.new(@msg_server, type.to_sym, name)
26
+ @exchanges << MQ::Exchange.new(@msg_server, type.to_sym, name, :durable => true, :passive => false)
27
27
  end
28
28
  end
29
29
 
@@ -32,9 +32,9 @@ class MessagePusher
32
32
  self.extend eval(classify(key_file.gsub(".rb", "")))
33
33
  end
34
34
 
35
- # Stolen from rails.
35
+ # Turn path Class or Module name (i.e. strip directories and turn into camel-case)
36
36
  def classify(str)
37
- str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
37
+ str.gsub(/^.*\//, '').gsub(".rb","").gsub(/(?:^|_)(.)/) { $1.upcase }
38
38
  end
39
39
 
40
40
  # is overriden by included fork_file if specified
@@ -45,8 +45,8 @@ class MessagePusher
45
45
  def process_message(msg)
46
46
  @exchanges.each do |exchange|
47
47
  key = route_key(msg)
48
- exchange.publish(MessageCoder.encode(msg), :routing_key => key)
49
- # exchange.publish(msg.to_yaml, :routing_key => key)
48
+ exchange.publish(msg.to_yaml, :routing_key => key)
49
+ # OPTIMIZE. Using MessageCoder.encode(msg) instead of to_yaml is 2x faster. But won't be easy to debug. Worth it?
50
50
  end
51
51
  :ack
52
52
  end
@@ -9,7 +9,7 @@ class MessageSubscriber
9
9
  PIPE_PATH = "/tmp"
10
10
 
11
11
  def initialize(opts)
12
- @exchange_name = opts[:exchange]
12
+ @exchange_name, @exchange_type = opts[:exchange].split(":")
13
13
  @queue_name = opts[:queue]
14
14
  @use_ack = opts[:ack]
15
15
  @topic = opts[:topic]
@@ -56,12 +56,16 @@ class MessageSubscriber
56
56
  @queue = @queue_name ? MQ.queue(@queue_name, :durable => true) :
57
57
  self.generate_temporary_queue
58
58
  if @exchange_name
59
- log.info("Binding to exchange:#{@exchange_name} #{@topic ? "using topic:" + @topic : ""}")
60
- # OPTIMIZE. Should we be setting up the exchange just incase it hasn't been created yet?
61
- @queue.bind(@exchange_name, :key => @topic)
59
+ create_exchange(@exchange_name, (@exchange_type || :fanout))
60
+ log.info("Binding to exchange:#{@exchange_str} #{@topic ? "using topic:" + @topic : ""}")
61
+ @queue.bind(@exchange_str, :key => @topic)
62
62
  end
63
63
  end
64
64
 
65
+ def create_exchange(name, type)
66
+ MQ::Exchange.new(MQ.default, type.to_sym, @exchange_name, :durable => true, :passive => false)
67
+ end
68
+
65
69
  def create_sys_pipe
66
70
  log.debug("creating sys-pipe")
67
71
  name = File.join(PIPE_PATH, "sys_pipe_#{self.generate_guid}")
@@ -2,25 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pipeline_toolkit}
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aisha Fenton"]
9
- s.date = %q{2009-09-23}
9
+ s.date = %q{2009-09-26}
10
10
  s.email = %q{labs@visfleet.com}
11
- s.executables = ["msg_probe.rb", "msg_subscribe.rb", "msg_push.rb", "msg_pop.rb", "msg_sink.rb"]
11
+ s.executables = ["msg_probe.rb", "msg_subscribe.rb", "msg_push.rb", "msg_sink.rb"]
12
12
  s.extra_rdoc_files = [
13
- "LICENSE",
14
- "README.rdoc"
13
+ "README.rdoc"
15
14
  ]
16
15
  s.files = [
17
16
  ".document",
18
17
  ".gitignore",
19
- "LICENSE",
20
18
  "README.rdoc",
21
19
  "Rakefile",
22
20
  "VERSION",
23
- "bin/msg_pop.rb",
24
21
  "bin/msg_probe.rb",
25
22
  "bin/msg_push.rb",
26
23
  "bin/msg_sink.rb",
@@ -28,7 +25,6 @@ Gem::Specification.new do |s|
28
25
  "lib/pipeline_toolkit.rb",
29
26
  "lib/pipeline_toolkit/message_coder.rb",
30
27
  "lib/pipeline_toolkit/message_command.rb",
31
- "lib/pipeline_toolkit/message_popper.rb",
32
28
  "lib/pipeline_toolkit/message_probe.rb",
33
29
  "lib/pipeline_toolkit/message_pusher.rb",
34
30
  "lib/pipeline_toolkit/message_sink.rb",
@@ -50,8 +46,20 @@ Gem::Specification.new do |s|
50
46
  s.specification_version = 3
51
47
 
52
48
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<tmm1-amqp>, [">= 0"])
50
+ s.add_runtime_dependency(%q<trollop>, [">= 0"])
51
+ s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
52
+ s.add_runtime_dependency(%q<visfleet-default_logging>, [">= 0"])
53
53
  else
54
+ s.add_dependency(%q<tmm1-amqp>, [">= 0"])
55
+ s.add_dependency(%q<trollop>, [">= 0"])
56
+ s.add_dependency(%q<eventmachine>, [">= 0"])
57
+ s.add_dependency(%q<visfleet-default_logging>, [">= 0"])
54
58
  end
55
59
  else
60
+ s.add_dependency(%q<tmm1-amqp>, [">= 0"])
61
+ s.add_dependency(%q<trollop>, [">= 0"])
62
+ s.add_dependency(%q<eventmachine>, [">= 0"])
63
+ s.add_dependency(%q<visfleet-default_logging>, [">= 0"])
56
64
  end
57
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visfleet-pipeline_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aisha Fenton
@@ -9,31 +9,66 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-23 00:00:00 -07:00
12
+ date: 2009-09-26 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: tmm1-amqp
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: trollop
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: eventmachine
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: visfleet-default_logging
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
16
55
  description:
17
56
  email: labs@visfleet.com
18
57
  executables:
19
58
  - msg_probe.rb
20
59
  - msg_subscribe.rb
21
60
  - msg_push.rb
22
- - msg_pop.rb
23
61
  - msg_sink.rb
24
62
  extensions: []
25
63
 
26
64
  extra_rdoc_files:
27
- - LICENSE
28
65
  - README.rdoc
29
66
  files:
30
67
  - .document
31
68
  - .gitignore
32
- - LICENSE
33
69
  - README.rdoc
34
70
  - Rakefile
35
71
  - VERSION
36
- - bin/msg_pop.rb
37
72
  - bin/msg_probe.rb
38
73
  - bin/msg_push.rb
39
74
  - bin/msg_sink.rb
@@ -41,7 +76,6 @@ files:
41
76
  - lib/pipeline_toolkit.rb
42
77
  - lib/pipeline_toolkit/message_coder.rb
43
78
  - lib/pipeline_toolkit/message_command.rb
44
- - lib/pipeline_toolkit/message_popper.rb
45
79
  - lib/pipeline_toolkit/message_probe.rb
46
80
  - lib/pipeline_toolkit/message_pusher.rb
47
81
  - lib/pipeline_toolkit/message_sink.rb
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Aisha Fenton
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/msg_pop.rb DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'trollop'
5
- require 'pipeline_toolkit'
6
- require "pp"
7
-
8
- opts = Trollop::options do
9
- opt :sources, "Sources", :short => "s", :type => :strings
10
- opt :cycle, "Seconds between polls", :default => 1
11
- opt :ack, "Switch that requires that messages are successfully processed before continuing with the next message", :short => "a"
12
-
13
- # Msg server
14
- opt :host, "The AMQP message server host", :default => "localhost"
15
- opt :port, "The AMQP message server port", :default => "5672"
16
- opt :user, "The AMQP message server username", :default => "guest"
17
- opt :pass, "The AMQP message server username", :default => "guest", :short => "w"
18
- opt :vhost, "The AMQP message server vhost", :default => "/"
19
- end
20
-
21
- MessagePopper.new(opts).start
@@ -1,87 +0,0 @@
1
- require "eventmachine"
2
- require "bunny"
3
- require "time"
4
-
5
- class MessagePopper
6
- include DefaultLogging
7
-
8
- PIPE_PATH = "/tmp"
9
-
10
- def initialize(opts)
11
- @cycle = opts[:cycle]
12
- @msg_server = Bunny.new({:spec => '08'}.merge!(opts.select_keys(:host, :port, :user, :pass, :vhost)))
13
- @msg_server.start
14
- @sources = opts[:sources]
15
- @use_ack = opts[:ack]
16
- end
17
-
18
- def start
19
- self.create_sys_pipe
20
- EM.run do
21
- EM.add_periodic_timer(@cycle) { self.tick }
22
- end
23
- self.destroy_sys_pipe
24
- end
25
-
26
- def create_sys_pipe
27
- log.debug("creating sys-pipe")
28
- name = File.join(PIPE_PATH, "sys_pipe_#{self.generate_guid}")
29
- `mkfifo #{name}`
30
- @sys_pipe = File.new(name, "r+")
31
- sleep(2)
32
- $stdout.puts(MessageCoder.encode({:msg_type => :system, :sys_pipe => name, :use_ack => @use_ack}))
33
- $stdout.flush
34
- end
35
-
36
- def destroy_sys_pipe
37
- `rm #{@sys_pipe}`
38
- end
39
-
40
- def generate_guid
41
- # TODO maybe better way to do guid
42
- "#{Time.now.iso8601}_#{rand(99999)}_#{rand(99999)}_#{rand(99999)}"
43
- end
44
-
45
- def tick
46
- log.debug("draining queue")
47
- loop do
48
- q_empty = true
49
- @sources.each do |source|
50
- # FIXME. @queue for each source, or not needed
51
- @queue ||= @msg_server.queue(source)
52
- result = @queue.pop(:ack => @use_ack)
53
- next if result == :queue_empty
54
- # msg = YAML.load(result)
55
- q_empty = false
56
- # @use_ack ? verify(msg, source) { write_msg(msg) } : write_msg(msg)
57
-
58
- @count ||= 0
59
- @count += 1
60
- @prev_time ||= Time.now
61
- if @count > 100
62
- t = Time.now
63
- log.debug("per sec #{@count / (t - @prev_time)}")
64
- @prev_time = t
65
- @count = 0
66
- end
67
-
68
- end
69
- break if q_empty
70
- end
71
- end
72
-
73
- def write_msg(msg)
74
- $stdout.puts(MessageCoder.encode(msg))
75
- $stdout.flush
76
- end
77
-
78
- def verify(msg, source)
79
- msg.ack_id = generate_guid
80
- yield
81
- $stdout.flush
82
- ack_id = @sys_pipe.gets.chomp!
83
- raise Exception.new("ACK failed with msg #{msg.to_yaml}") unless msg.ack_id == ack_id
84
- @msg_server.queue(source).ack
85
- end
86
-
87
- end