Class: ReliableMsg::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/reliable-msg/cli.rb

Overview

:nodoc:

Defined Under Namespace

Classes: InvalidUsage

Constant Summary collapse

USAGE =
"usage:  queues command [args] [options]\n\nTo see list of available commands and options\n  queues help\n"
HELP =
"usage:  queues command [args] [options]\n\nReliable messaging queue manager, version \#{VERSION}\n\nAvailable commands:\n\n  help\n    Display this help message.\n\n  manager start\n    Start the queue manager as a standalone server\n\n  manager stop\n    Stop a running queue manager.\n\n  install disk [<path>]\n    Configure queue manager to use disk-based message store\n    using the specified directory. Uses 'queues' by default.\n\n  install mysql <host> <username> <password> <database> [options]\n                [--port <port>] [--socket <socket>] [--prefix <prefix>]\n    Configure queue manager to use MySQL for message store,\n    using the specified connection properties. Updates database\n    schema.\n\n  --port  Port to connect to\n  --socket  Socket to connect to\n  --prefix  Prefix for table names\n\n\nAvailable options:\n\n  -v --version\n    Show version number.\n\n  -c --config <path>\n    Points to the queue manager configuration file.\n\n"

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



74
75
# File 'lib/reliable-msg/cli.rb', line 74

def initialize
end

Instance Method Details

#queue_manager(config_file) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/reliable-msg/cli.rb', line 160

def queue_manager config_file
    if config_file
        config = Config.new config_file, nil
        unless config.load_no_create || config_file.nil?
            puts "Could not find configuration file #{config.path}"
            exit
        end
        drb = Config::DEFAULT_DRB
        drb.merge(config.drb) if config.drb
        drb_uri = "druby://localhost:#{drb['port']}"
    else
        drb_uri = Queue::DEFAULT_DRB_URI
    end
    DRbObject.new(nil, drb_uri)
end

#runObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/reliable-msg/cli.rb', line 77

def run
    begin
        config_file = nil
        opts = OptionParser.new
        opts.on("-c FILE", "--config FILE", String) { |value| config_file = value }
        opts.on("-v", "--version") do
            puts "Reliable messaging queue manager, version #{VERSION}"
            exit
        end
        opts.on("-h", "--help") do
            puts HELP
            exit
        end

        args = opts.parse(ARGV)

        raise InvalidUsage if args.length < 1
        case args[0]
        when 'help'
            puts HELP

        when 'manager'
            case args[1]
            when 'start', nil
                manager = QueueManager.new({:config=>config_file})
                manager.start
                begin
                    while manager.alive?
                        sleep 3
                    end
                rescue Interrupt
                    manager.stop
                end
            when 'stop'
                begin
                    queue_manager(config_file).stop
                rescue DRb::DRbConnError =>error
                    puts "Cannot access queue manager: is it running?"
                end
            else
                raise InvalidUsage
            end

        when 'install'
            config = Config.new config_file, nil
            case args[1]
            when 'disk'
                store = MessageStore::Disk.new({}, nil)
                config.store = store.configuration
                if config.create_if_none
                    store.setup
                    puts "Created queues configuration file: #{config.path}"
                else
                    puts "Found existing queues configuration file: #{config.path}"
                    puts "No changes made"
                end
            when 'mysql'
                host, username, password, database = args[2], args[3], args[4], args[5]
                raise InvalidUsage unless host && database && username && password
                conn = { "host"=>host, "username"=>username, "password"=>password, "database"=>database }
                store = MessageStore::MySQL.new(conn, nil)
                config.store = store.configuration
                if config.create_if_none
                    puts "Created queues configuration file: #{config.path}"
                    if store.setup
                        puts "Created queue manager tables in database '#{database}'"
                    end
                else
                    puts "Found existing queues configuration file: #{config.path}"
                    puts "No changes made"
                end
            else
                raise InvalidUsage
            end

        else
            raise InvalidUsage
    end
    rescue InvalidUsage
        puts USAGE
    end
end