Class: AppAmqp2Sql

Inherits:
Thor::Application show all
Defined in:
app/amqp2sql.rb

Instance Attribute Summary

Attributes inherited from Thor::Application

#request_exit

Instance Method Summary collapse

Methods inherited from Thor::Application

#amqp_handle_failure, #amqp_loop, #amqp_start, #amqp_stop, #run

Constructor Details

#initialize(opts = {}) ⇒ AppAmqp2Sql

Returns a new instance of AppAmqp2Sql.



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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/amqp2sql.rb', line 21

def initialize(opts = {})
	super(opts)
			
	# AMQP options
	options[:amqp] = {}
	options[:amqp][:host] = "localhost"
	options[:amqp][:port] = 8467
	options[:amqp][:user] = "guest"
	options[:amqp][:password] = "guest"
	options[:amqp][:vhost] = "/"
	
	options[:sql] = {}
	options[:sql][:host] = "localhost"
	options[:sql][:port] = 5432
	options[:sql][:user] = "guest"
	options[:sql][:password] = "guest"

	initialize_optparser { |opts|	
		# AMQP Host
		opts.on( '--amqp-host STRING', "AMQP Server hostname [default: #{options[:amqp][:host]}]") do |host|
			options[:amqp][:host] = host
		end

		# AMQP Port
		opts.on('--amqp-port NUM', "AMQP Server port number [default: #{options[:amqp][:port]}]") do |port|
			options[:amqp][:port] = port
		end

		# AMQP Username
		opts.on('--amqp-user STRING', "AMQP Username [default: #{options[:amqp][:user]}]") do |user|
			options[:amqp][:user] = user
		end

		# AMQP Password
		opts.on('--amqp-password STRING', "AMQP Password [default: #{options[:amqp][:password]}]") do |password|
			options[:amqp][:password] = password
		end

		# AMQP Vhost
		opts.on('--amqp-vhost STRING', "AMQP Virtual Host [default: #{options[:amqp][:vhost]}]") do |vhost|
			options[:amqp][:vhost] = vhost
		end

		# SQL Host
		opts.on( '--sql-host STRING', "PostgreSQL Server hostname [default: #{options[:sql][:host]}]") do |host|
			options[:sql][:host] = host
		end

		# SQL Port
		opts.on('--sql-port NUM', "PostgreSQL Server port number [default: #{options[:sql][:port]}]") do |port|
			options[:sql][:port] = port
		end

		# SQL Username
		opts.on('--sql-user STRING', "PostgreSQL Username [default: #{options[:sql][:user]}]") do |user|
			options[:sql][:user] = user
		end

		# SQL Password
		opts.on('--sql-password STRING', "PostgreSQL Password [default: #{options[:sql][:password]}]") do |password|
			options[:sql][:password] = password
		end
	}
end

Instance Method Details

#mainObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/amqp2sql.rb', line 86

def main
	super()

	# Run loop while exit is not requested
	while(request_exit == false)
		begin
			amqp_start()
		rescue SystemExit, Interrupt
			Bsl::Logger::Log "Received interrupt, quitting!"
			@request_exit = true
			amqp_stop()
		rescue Exception => e
			amqp_handle_failure(e)
		end
		puts "."
	end
end