ruby_rabbitmq_janus 2.0.0 → 2.1.0.pre.128
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/Rakefile +98 -0
- data/config/default.md +6 -3
- data/config/default.yml +7 -1
- data/lib/generators/ruby_rabbitmq_janus/install_generator.rb +3 -0
- data/lib/generators/ruby_rabbitmq_janus/migration_generator.rb +30 -0
- data/lib/generators/ruby_rabbitmq_janus/templates/migration.rb +14 -0
- data/lib/rrj/admin.rb +2 -0
- data/lib/rrj/errors/base/admin.rb +24 -0
- data/lib/rrj/errors/base/base.rb +5 -0
- data/lib/rrj/errors/base/init.rb +46 -0
- data/lib/rrj/errors/base/task.rb +32 -0
- data/lib/rrj/errors/error.rb +4 -3
- data/lib/rrj/errors/janus/janus.rb +20 -7
- data/lib/rrj/errors/janus/messages/admin.rb +33 -0
- data/lib/rrj/errors/janus/messages/message.rb +51 -0
- data/lib/rrj/errors/janus/messages/standard.rb +33 -0
- data/lib/rrj/errors/janus/processus/concurency.rb +23 -0
- data/lib/rrj/errors/janus/processus/event.rb +30 -0
- data/lib/rrj/errors/janus/processus/keepalive.rb +33 -0
- data/lib/rrj/errors/janus/responses/admin.rb +39 -0
- data/lib/rrj/errors/janus/responses/event.rb +46 -0
- data/lib/rrj/errors/janus/responses/response.rb +44 -0
- data/lib/rrj/errors/janus/responses/standard.rb +58 -0
- data/lib/rrj/errors/janus/transactions/admin.rb +37 -0
- data/lib/rrj/errors/janus/transactions/handle.rb +52 -0
- data/lib/rrj/errors/janus/transactions/session.rb +38 -0
- data/lib/rrj/errors/janus/transactions/transaction.rb +23 -0
- data/lib/rrj/errors/rabbit/connect.rb +58 -0
- data/lib/rrj/errors/rabbit/propertie.rb +37 -0
- data/lib/rrj/errors/rabbit/publish/admin.rb +30 -0
- data/lib/rrj/errors/rabbit/publish/base_publisher.rb +23 -0
- data/lib/rrj/errors/rabbit/publish/exclusive.rb +31 -0
- data/lib/rrj/errors/rabbit/publish/listener.rb +30 -0
- data/lib/rrj/errors/rabbit/publish/non_exclusive.rb +31 -0
- data/lib/rrj/errors/rabbit/publish/publisher.rb +30 -0
- data/lib/rrj/errors/rabbit/rabbit.rb +14 -23
- data/lib/rrj/errors/tools/gem/cluster.rb +44 -0
- data/lib/rrj/errors/tools/gem/config.rb +89 -0
- data/lib/rrj/errors/tools/gem/log.rb +86 -0
- data/lib/rrj/errors/tools/gem/option.rb +37 -0
- data/lib/rrj/errors/tools/gem/request.rb +23 -0
- data/lib/rrj/errors/tools/replaces/replace.rb +30 -0
- data/lib/rrj/errors/tools/replaces/type.rb +30 -0
- data/lib/rrj/errors/tools/tools.rb +21 -1
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/init.rb +22 -4
- data/lib/rrj/janus/messages/admin.rb +9 -4
- data/lib/rrj/janus/messages/message.rb +20 -9
- data/lib/rrj/janus/messages/standard.rb +8 -2
- data/lib/rrj/janus/processus/concurrency.rb +2 -0
- data/lib/rrj/janus/processus/event.rb +8 -0
- data/lib/rrj/janus/processus/keepalive.rb +15 -23
- data/lib/rrj/janus/responses/admin.rb +6 -0
- data/lib/rrj/janus/responses/event.rb +8 -0
- data/lib/rrj/janus/responses/response.rb +8 -11
- data/lib/rrj/janus/responses/standard.rb +12 -0
- data/lib/rrj/janus/transactions/admin.rb +6 -0
- data/lib/rrj/janus/transactions/handle.rb +25 -3
- data/lib/rrj/janus/transactions/session.rb +6 -0
- data/lib/rrj/janus/transactions/transaction.rb +3 -9
- data/lib/rrj/models/active_record.rb +14 -0
- data/lib/rrj/models/concerns/janus_instance_concern.rb +47 -0
- data/lib/rrj/models/mongoid.rb +19 -0
- data/lib/rrj/rabbit/connect.rb +12 -8
- data/lib/rrj/rabbit/propertie.rb +23 -6
- data/lib/rrj/rabbit/publish/admin.rb +4 -0
- data/lib/rrj/rabbit/publish/base_publisher.rb +2 -1
- data/lib/rrj/rabbit/publish/exclusive.rb +4 -0
- data/lib/rrj/rabbit/publish/listener.rb +6 -0
- data/lib/rrj/rabbit/publish/non_exclusive.rb +4 -0
- data/lib/rrj/rabbit/publish/publisher.rb +4 -4
- data/lib/rrj/railtie.rb +15 -0
- data/lib/rrj/task.rb +51 -0
- data/lib/rrj/tools/gem/cluster.rb +65 -0
- data/lib/rrj/tools/gem/config.rb +38 -6
- data/lib/rrj/tools/gem/log.rb +24 -4
- data/lib/rrj/tools/gem/option.rb +21 -17
- data/lib/rrj/tools/gem/requests.rb +11 -7
- data/lib/rrj/tools/replaces/replace.rb +4 -0
- data/lib/rrj/tools/replaces/type.rb +4 -0
- data/lib/rrj/tools/tools.rb +1 -0
- data/lib/ruby_rabbitmq_janus.rb +3 -0
- data/lib/tasks/delete_all_instance.rake +12 -0
- data/spec/request/admin/request_handle_info_spec.rb +4 -3
- data/spec/request/admin/request_handles_spec.rb +4 -3
- data/spec/request/peer/request_trickle_spec.rb +1 -1
- data/spec/rrj/rabbit/propertie_spec.rb +37 -2
- data/spec/rrj/tools/gem/rrj_cluster_spec.rb +26 -0
- data/spec/rrj/tools/gem/rrj_config_spec.rb +78 -0
- data/spec/rrj/tools/gem/rrj_log_spec.rb +55 -0
- data/spec/rrj/tools/{replace_admin_spec.rb → replace/replace_admin_spec.rb} +0 -0
- data/spec/rrj/tools/{replace_handle_spec.rb → replace/replace_handle_spec.rb} +0 -0
- data/spec/rrj/tools/{replace_session_spec.rb → replace/replace_session_spec.rb} +0 -0
- data/spec/rrj/tools/{replace_spec.rb → replace/replace_spec.rb} +0 -0
- data/spec/rrj/tools/{type_spec.rb → replace/type_spec.rb} +0 -0
- data/spec/spec_helper.rb +33 -2
- data/spec/support/examples_config.rb +10 -0
- data/spec/support/examples_message.rb +0 -2
- data/spec/support/examples_request.rb +4 -4
- data/spec/support/schemas/config/config.json +4 -2
- data/spec/support/schemas/config/rabbit_options.json +1 -1
- data/spec/support/schemas/config/rabbit_options2.json +13 -0
- data/spec/support/schemas/config/rabbit_options_admin.json +1 -1
- data/spec/support/schemas/config/rabbit_options_admin2.json +13 -0
- metadata +98 -17
- data/lib/rrj/errors/init.rb +0 -69
- data/lib/rrj/errors/janus/janus_message.rb +0 -53
- data/lib/rrj/errors/janus/janus_processus_keepalive.rb +0 -48
- data/lib/rrj/errors/janus/janus_response.rb +0 -89
- data/lib/rrj/errors/janus/janus_transaction.rb +0 -29
- data/lib/rrj/errors/tools/config.rb +0 -43
- data/spec/rrj/rrj_config_spec.rb +0 -67
- data/spec/rrj/rrj_log_spec.rb +0 -16
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Models
|
5
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
|
+
#
|
7
|
+
# Store instance information for MongoID database
|
8
|
+
class JanusInstance
|
9
|
+
include Mongoid::Document
|
10
|
+
include RubyRabbitmqJanus::Models::JanusInstanceConcern
|
11
|
+
|
12
|
+
field :instance, type: Integer
|
13
|
+
field :session, type: Integer
|
14
|
+
field :enable, type: Boolean
|
15
|
+
|
16
|
+
set_callback(:destroy, :before) { destroy_before_action }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rrj/rabbit/connect.rb
CHANGED
@@ -8,8 +8,9 @@ module RubyRabbitmqJanus
|
|
8
8
|
class Connect
|
9
9
|
# Initialize connection to server RabbitMQ
|
10
10
|
def initialize
|
11
|
-
Tools::Log.instance.debug 'Initialize connection with RabbitMQ'
|
12
11
|
@rabbit = Bunny.new(read_options_server.merge!(option_log_rabbit))
|
12
|
+
rescue
|
13
|
+
raise Errors::Rabbit::Connect::Initialize
|
13
14
|
end
|
14
15
|
|
15
16
|
# Create an transaction with rabbitmq and close after response is received
|
@@ -17,34 +18,37 @@ module RubyRabbitmqJanus
|
|
17
18
|
response = transaction_long { yield }
|
18
19
|
close
|
19
20
|
response
|
21
|
+
rescue
|
22
|
+
raise Errors::Rabbit::Connect::TransactionShort
|
20
23
|
end
|
21
24
|
|
22
25
|
# Create an transaction with rabbitmq and not close
|
23
26
|
def transaction_long
|
24
27
|
start
|
25
28
|
yield
|
29
|
+
rescue
|
30
|
+
raise Errors::Rabbit::Connect::TransactionLong
|
26
31
|
end
|
27
32
|
|
28
33
|
# Openning a connection with Rabbitmq
|
29
34
|
def start
|
30
|
-
Tools::Log.instance.debug 'Connection to rabbitmq START'
|
31
35
|
@rabbit.start
|
32
|
-
rescue
|
33
|
-
raise Errors::
|
36
|
+
rescue
|
37
|
+
raise Errors::Rabbit::Start
|
34
38
|
end
|
35
39
|
|
36
40
|
# Close connection to server RabbitMQ
|
37
41
|
def close
|
38
|
-
Tools::Log.instance.debug 'Connection to rabbitmq STOP'
|
39
42
|
@rabbit.close
|
40
43
|
rescue
|
41
|
-
raise
|
44
|
+
raise Errors::Rabbit::Close
|
42
45
|
end
|
43
46
|
|
44
47
|
# Create an channel
|
45
48
|
def channel
|
46
|
-
Tools::Log.instance.debug 'Create an channel'
|
47
49
|
@rabbit.create_channel
|
50
|
+
rescue
|
51
|
+
raise Errors::Rabbit::Channel
|
48
52
|
end
|
49
53
|
|
50
54
|
private
|
@@ -52,7 +56,7 @@ module RubyRabbitmqJanus
|
|
52
56
|
def read_options_server
|
53
57
|
cfg = Tools::Config.instance.options['rabbit']
|
54
58
|
opts = {}
|
55
|
-
%w
|
59
|
+
%w[host port pass user vhost].each do |val|
|
56
60
|
opts.merge!(val.to_sym => cfg[val])
|
57
61
|
end
|
58
62
|
opts
|
data/lib/rrj/rabbit/propertie.rb
CHANGED
@@ -12,29 +12,46 @@ module RubyRabbitmqJanus
|
|
12
12
|
attr_reader :correlation
|
13
13
|
|
14
14
|
# Initialize a message sending to rabbitmq
|
15
|
-
def initialize
|
15
|
+
def initialize(instance = 1)
|
16
16
|
Tools::Log.instance.debug 'initalize a propertie to message'
|
17
17
|
@correlation = SecureRandom.uuid
|
18
|
+
@instance = instance
|
19
|
+
rescue
|
20
|
+
raise Errors::Rabbit::Propertie::Initialize
|
18
21
|
end
|
19
22
|
|
20
23
|
# Define options sending to rabbitmq
|
21
24
|
def options
|
22
|
-
Tools::Log.instance.debug 'Add options to propertie to message'
|
23
25
|
{
|
24
|
-
routing_key: Tools::
|
26
|
+
routing_key: Tools::Cluster.instance.queue_to(@instance),
|
25
27
|
correlation_id: @correlation,
|
26
28
|
content_type: 'application/json'
|
27
29
|
}
|
30
|
+
rescue
|
31
|
+
raise Errors::Rabbit::Propertie::Options
|
28
32
|
end
|
29
33
|
|
30
34
|
# Define option sending to rabbitmq for janus admin message
|
31
|
-
def options_admin
|
32
|
-
Tools::Log.instance.debug 'Add options to propertie to message'
|
35
|
+
def options_admin(type_request)
|
33
36
|
{
|
34
|
-
routing_key:
|
37
|
+
routing_key: determine_routing_key(type_request),
|
35
38
|
correlation_id: @correlation,
|
36
39
|
content_type: 'application/json'
|
37
40
|
}
|
41
|
+
rescue
|
42
|
+
raise Errors::Rabbit::Propertie::Options_admin
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def determine_routing_key(type_request)
|
48
|
+
cluster = Tools::Cluster.instance
|
49
|
+
|
50
|
+
if type_request.include?('admin')
|
51
|
+
cluster.queue_admin_to(@instance)
|
52
|
+
else
|
53
|
+
cluster.queue_to(@instance)
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
40
57
|
end
|
@@ -13,6 +13,8 @@ module RubyRabbitmqJanus
|
|
13
13
|
@reply = exchange.queue(Tools::Config.instance.queue_admin_from)
|
14
14
|
super(exchange)
|
15
15
|
subscribe_to_queue
|
16
|
+
rescue
|
17
|
+
raise Errors::Rabbit::PublisherAdmin::Initialize
|
16
18
|
end
|
17
19
|
|
18
20
|
# Send an message to queue and waiting a response
|
@@ -24,6 +26,8 @@ module RubyRabbitmqJanus
|
|
24
26
|
def publish(request)
|
25
27
|
super(request)
|
26
28
|
return_response
|
29
|
+
rescue
|
30
|
+
raise Errors::Rabbit::PublisherAdmin::Pusblish
|
27
31
|
end
|
28
32
|
|
29
33
|
private
|
@@ -21,10 +21,11 @@ module RubyRabbitmqJanus
|
|
21
21
|
|
22
22
|
# Define a base publisher
|
23
23
|
def initialize
|
24
|
-
Tools::Log.instance.debug 'Create an publisher'
|
25
24
|
@responses = []
|
26
25
|
@semaphore = Semaphore.new
|
27
26
|
@lock = Mutex.new
|
27
|
+
rescue
|
28
|
+
raise Errors::Rabbit::BasePublisher::Initialize
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
@@ -18,6 +18,8 @@ module RubyRabbitmqJanus
|
|
18
18
|
@reply = exchange.queue(name_queue, exclusive: true)
|
19
19
|
super(exchange)
|
20
20
|
subscribe_to_queue
|
21
|
+
rescue
|
22
|
+
raise Errors::Rabbit::PublishExclusive::Initialize
|
21
23
|
end
|
22
24
|
|
23
25
|
# Send an message to queue and waiting a response
|
@@ -29,6 +31,8 @@ module RubyRabbitmqJanus
|
|
29
31
|
def publish(request)
|
30
32
|
super(request)
|
31
33
|
return_response
|
34
|
+
rescue
|
35
|
+
raise Errors::Rabbit::PublishExclusive::Publish
|
32
36
|
end
|
33
37
|
|
34
38
|
private
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :reek:TooManyStatements
|
4
|
+
|
3
5
|
module RubyRabbitmqJanus
|
4
6
|
module Rabbit
|
5
7
|
module Publisher
|
@@ -17,6 +19,8 @@ module RubyRabbitmqJanus
|
|
17
19
|
@responses = []
|
18
20
|
@rabbit = rabbit.channel
|
19
21
|
subscribe_queue
|
22
|
+
rescue
|
23
|
+
raise Errors::Rabbit::Listener::Initialize
|
20
24
|
end
|
21
25
|
|
22
26
|
# Listen a queue and return a body response
|
@@ -27,6 +31,8 @@ module RubyRabbitmqJanus
|
|
27
31
|
response = @responses.shift
|
28
32
|
end
|
29
33
|
yield response.event, response
|
34
|
+
rescue
|
35
|
+
raise Errors::Rabbit::Listener::ListenEvents
|
30
36
|
end
|
31
37
|
|
32
38
|
private
|
@@ -12,6 +12,8 @@ module RubyRabbitmqJanus
|
|
12
12
|
def initialize(exchange)
|
13
13
|
@reply = exchange.queue(Tools::Config.instance.queue_from)
|
14
14
|
super(exchange)
|
15
|
+
rescue
|
16
|
+
raise Errors::Rabbit::PublishNonExclusive::Initialize
|
15
17
|
end
|
16
18
|
|
17
19
|
# Send an message to queue
|
@@ -19,6 +21,8 @@ module RubyRabbitmqJanus
|
|
19
21
|
# @param [String] request JSON request sending to rabbitmq queue
|
20
22
|
def publish(request)
|
21
23
|
super(request)
|
24
|
+
rescue
|
25
|
+
raise Errors::Rabbit::PublishNonExclusive::Publish
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
@@ -15,7 +15,8 @@ module RubyRabbitmqJanus
|
|
15
15
|
super()
|
16
16
|
@exchange = exchange.default_exchange
|
17
17
|
@message = nil
|
18
|
-
|
18
|
+
rescue
|
19
|
+
raise Errors::Rabbit::Publish::Initialize
|
19
20
|
end
|
20
21
|
|
21
22
|
# Publish an message in queue
|
@@ -25,12 +26,11 @@ module RubyRabbitmqJanus
|
|
25
26
|
# @raise [Errors::RabbitPublishMessage] If request is false the
|
26
27
|
# execption is calling
|
27
28
|
def publish(request)
|
28
|
-
Tools::Log.instance.info "Send request type : #{request.type}"
|
29
29
|
@message = request
|
30
30
|
@exchange.publish(@message.to_json,
|
31
31
|
request.options.merge!(reply_to: reply.name))
|
32
|
-
rescue
|
33
|
-
raise Errors::
|
32
|
+
rescue
|
33
|
+
raise Errors::Rabbit::Publish::Publish
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
data/lib/rrj/railtie.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
# # Rake Action
|
5
|
+
#
|
6
|
+
# Create an action for rails apps
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
railtie_name :rrj
|
9
|
+
|
10
|
+
rake_tasks do
|
11
|
+
tasks = File.join(File.dirname(__FILE__), '../tasks', '*.rake')
|
12
|
+
Dir[tasks].each { |file_task| load file_task }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/rrj/task.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :reek:TooManyStatements
|
4
|
+
|
5
|
+
module RubyRabbitmqJanus
|
6
|
+
# @author VAILLANT jeremy <jeremy.vaillant@dazl.tv>
|
7
|
+
|
8
|
+
# # RubyRabbitmqJanus - Task
|
9
|
+
#
|
10
|
+
# This class is used with rake task.
|
11
|
+
class RRJTask < RRJ
|
12
|
+
def initialize
|
13
|
+
Tools::Log.instance
|
14
|
+
Tools::Config.instance
|
15
|
+
Tools::Requests.instance
|
16
|
+
rescue
|
17
|
+
raise Errors::RRJTask::Initialize
|
18
|
+
end
|
19
|
+
|
20
|
+
# Start a transaction with Janus. Request use session_id information.
|
21
|
+
#
|
22
|
+
# @param [Hash] options
|
23
|
+
# Give a session number for use another session in Janus
|
24
|
+
#
|
25
|
+
# @example Get Janus information
|
26
|
+
# @rrj.start_transaction do |transaction|
|
27
|
+
# response = transaction.publish_message('base::info').to_hash
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# @since 2.1.0
|
31
|
+
def start_transaction(options = {})
|
32
|
+
transaction = Janus::Transactions::Session.new(true,
|
33
|
+
options['session_id'])
|
34
|
+
transaction.connect { yield(transaction) }
|
35
|
+
rescue
|
36
|
+
raise Errors::RRJ::StartTransaction.new(true, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create a transaction betwwen apps and janus with a handle
|
40
|
+
#
|
41
|
+
# @since 2.1.0
|
42
|
+
def start_transaction_handle(exclusive = true, options = {})
|
43
|
+
session = Models::JanusInstance.find_by(options['instance']).session
|
44
|
+
handle = 0 # Create always a new handle
|
45
|
+
transaction = Janus::Transactions::Handle.new(exclusive, session, handle)
|
46
|
+
transaction.connect { yield(transaction) }
|
47
|
+
rescue
|
48
|
+
raise Errors::RRJTask::StartTransactionHandle, exclusive, options
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Tools
|
5
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
|
+
|
7
|
+
# # Manage Janus instance
|
8
|
+
class Cluster
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
attr_reader :number, :enable
|
12
|
+
|
13
|
+
# Initalize object for managing each instance to Janus
|
14
|
+
def initialize
|
15
|
+
@current_instance = nil
|
16
|
+
config = Config.instance
|
17
|
+
@enable = config.cluster
|
18
|
+
@number = config.number_of_instance
|
19
|
+
@sessions = []
|
20
|
+
rescue
|
21
|
+
raise Errors::Tools::Cluster::Initializer
|
22
|
+
end
|
23
|
+
|
24
|
+
# Create all session. One by instance
|
25
|
+
def create_sessions
|
26
|
+
(1..@number).each do |janus_instance|
|
27
|
+
@current_instance = janus_instance
|
28
|
+
@sessions.push create_session_instance
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
raise Errors::Tools::Cluster::CreateSessions
|
32
|
+
end
|
33
|
+
|
34
|
+
# Specify a name to queue
|
35
|
+
def queue_to(instance = nil)
|
36
|
+
Tools::Config.instance.options['queues']['standard']['to'] + \
|
37
|
+
"-#{instance.blank? ? @current_instance : instance}"
|
38
|
+
rescue
|
39
|
+
raise Errors::Tools::Cluster::QueueTo
|
40
|
+
end
|
41
|
+
|
42
|
+
# Specify a name to admin queue
|
43
|
+
def queue_admin_to(instance = nil)
|
44
|
+
Tools::Config.instance.options['queues']['admin']['to'] + \
|
45
|
+
"-#{instance.blank? ? @current_instance : instance}"
|
46
|
+
rescue
|
47
|
+
raise Errors::Tools::Cluster::QueueAdminTo
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Create a thread for manage a session/keepalive with Janus
|
53
|
+
def initialize_session
|
54
|
+
Janus::Concurrencies::Keepalive.new(@current_instance).session
|
55
|
+
end
|
56
|
+
|
57
|
+
# create a new instance in database
|
58
|
+
def create_session_instance
|
59
|
+
Models::JanusInstance.create(instance: @current_instance,
|
60
|
+
session: initialize_session,
|
61
|
+
enable: true)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/rrj/tools/gem/config.rb
CHANGED
@@ -35,51 +35,85 @@ module RubyRabbitmqJanus
|
|
35
35
|
loading_configuration_customize
|
36
36
|
loading_configuration_default
|
37
37
|
Tools::Log.instance.save_level(log_level)
|
38
|
+
rescue
|
39
|
+
raise Errors::Tools::Config::Initialize
|
38
40
|
end
|
39
41
|
|
42
|
+
# Get to name queue_from (pattern)
|
43
|
+
#
|
40
44
|
# @return [String] read configuration for queue `from`
|
41
45
|
def queue_from
|
42
46
|
@options['queues']['standard']['from'].to_s
|
47
|
+
rescue
|
48
|
+
raise Errors::Tools::Config::QueueFrom
|
43
49
|
end
|
44
50
|
|
51
|
+
# Get to name queue_to (pattern)
|
52
|
+
#
|
45
53
|
# @return [String] read configuration for queue `to`
|
46
54
|
def queue_to
|
47
55
|
@options['queues']['standard']['to'].to_s
|
56
|
+
rescue
|
57
|
+
raise Errors::Tools::Config::QueueTo
|
48
58
|
end
|
49
59
|
|
60
|
+
# Get to name queue_admin_from (pattern)
|
61
|
+
#
|
50
62
|
# @return [String] read configuration for queue admin `from`
|
51
63
|
def queue_admin_from
|
52
64
|
@options['queues']['admin']['from'].to_s
|
65
|
+
rescue
|
66
|
+
raise Errors::Tools::Config::QueueAdminFrom
|
53
67
|
end
|
54
68
|
|
69
|
+
# Get to name queue_admin_from (pattern)
|
70
|
+
#
|
55
71
|
# @return [String] read configuration for queue admin `to`
|
56
72
|
def queue_admin_to
|
57
73
|
@options['queues']['admin']['to'].to_s
|
74
|
+
rescue
|
75
|
+
raise Errors::Tools::Config::QueueAdminTo
|
58
76
|
end
|
59
77
|
|
60
78
|
# @return [Symbol] read configuration for log level used in this gem
|
61
79
|
def log_level
|
62
80
|
@options['gem']['log']['level'].upcase.to_sym
|
63
81
|
rescue
|
64
|
-
raise Errors::LevelNotDefine
|
82
|
+
raise Errors::Tools::Config::LevelNotDefine
|
65
83
|
end
|
66
84
|
|
67
85
|
# @return [Integer]
|
68
86
|
# read configuration for janus time to live for keepalive messages
|
69
87
|
def time_to_live
|
70
|
-
@options['janus']['session']['keepalive'].to_i
|
88
|
+
@options['janus']['session']['keepalive'].to_i || 50
|
71
89
|
rescue
|
72
|
-
raise Errors::TTLNotFound
|
90
|
+
raise Errors::Tools::Config::TTLNotFound
|
73
91
|
end
|
74
92
|
|
93
|
+
alias ttl time_to_live
|
94
|
+
|
75
95
|
# @param [Fixnum] index determine what field is readint in array plugins
|
76
96
|
# in configuration file
|
77
97
|
# @return [String] read configuration for plugin with index
|
78
98
|
def plugin_at(index = 0)
|
79
99
|
@options['janus']['plugins'][index].to_s
|
100
|
+
rescue
|
101
|
+
raise Errors::Tools::Config::PluginAt, index
|
80
102
|
end
|
81
103
|
|
82
|
-
|
104
|
+
# @return [Boolean] Read option file for a janus cluster section
|
105
|
+
def cluster
|
106
|
+
@options['janus']['cluster']['enabled'].to_s.eql?('true') ? true : false
|
107
|
+
rescue
|
108
|
+
raise Errors::Tools::Config::Cluster
|
109
|
+
end
|
110
|
+
|
111
|
+
# Count number of Janus instances
|
112
|
+
def number_of_instance
|
113
|
+
@options['janus']['cluster']['count'].to_i || 1
|
114
|
+
rescue
|
115
|
+
raise Errors::Tools::Config::NumberOfInstance
|
116
|
+
end
|
83
117
|
|
84
118
|
private
|
85
119
|
|
@@ -87,8 +121,6 @@ module RubyRabbitmqJanus
|
|
87
121
|
log_message = "Loading configuration file : #{@configuration}"
|
88
122
|
Tools::Log.instance.info(log_message)
|
89
123
|
YAML.safe_load(ERB.new(File.read(@configuration)).result)
|
90
|
-
rescue
|
91
|
-
raise Errors::FileNotFound, @configuration
|
92
124
|
end
|
93
125
|
|
94
126
|
def loading_configuration_customize
|