Class: PipelineToolkit::CLI::MsgPushCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pipeline_toolkit/cli/msg_push_cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pipeline_toolkit/cli/msg_push_cli.rb', line 8

def self.execute(stdout, arguments=[])

  opts = Trollop::options do
    banner <<-EOL
Message Publisher
------------------
  Publish to a Message Queue server, the received message from the 
  last worker in the pipeline.

  Usage:
  msg_push [options]

Examples:
  msg_push --exchange holding_tank
  msg_push --exchange holding_tank --type topic \\
      --queues us_stocks:stock.us.*, dax:stock.de.dax

Options:
      EOL

    banner <<-EOL

  Queue/exchange:
EOL
    opt :exchange, "Exchange name", :type => :string, :required => true, :short => :x
    opt :type, "Exchange type (direct, fanout, topic)", :default => "fanout", :short => :t
    opt :passive, "If true, the exchange will not be created if it does not already exist.", :default => false, :short => :s
    opt :durable, "If true, the exchange will be marked as durable.", :default => false, :short => :d
    opt :queues, "Destination queue(s) (e.g. queue1:routing_key, queue2:routing_key). Routing keys will be ignored if exchange type is not topic.", :type => :strings, :required => false, :short => :q
    
    banner <<-EOL

  AMQP server:
EOL
    opt :host, "AMQP message server host", :default => "localhost", :short => :h
    opt :port, "AMQP message server port", :default => 5672, :short => :p
    opt :user, "AMQP message server username", :default => "guest", :short => :u
    opt :pass, "AMQP message server password", :default => "guest", :short => :w
    opt :vhost, "AMQP message server vhost", :default => "/", :short => :v

    banner <<-EOL

  Misc:
EOL
    opt :env, "Environment (development, production)", :default => "development", :short => :e
    opt :log_conf, "YML file to configure logging", :short => :l, :type => :string, :required => false
  end
          
  # Change ['queue1:routing_key', ...] to [['queue1','routing_key'], ...]
  queues = []
  opts.delete(:queues).each do |queue| # trollop gives an array of strings
    queues << queue.strip.split(":")
  end
  opts[:queues] = queues
  
  MessagePusher.new(opts).start
end