ruby_rabbitmq_janus 2.6.0.pre.247 → 2.6.0.pre.258
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ruby_rabbitmq_janus +6 -2
- data/config/default.md +5 -0
- data/config/default.yml +19 -0
- data/lib/rrj/binary.rb +1 -7
- data/lib/rrj/errors/error.rb +5 -9
- data/lib/rrj/errors/tools/gem/config.rb +30 -0
- data/lib/rrj/errors/tools/tools.rb +0 -1
- data/lib/rrj/init.rb +5 -0
- data/lib/rrj/janus/messages/message.rb +2 -2
- data/lib/rrj/janus/processus/concurrency.rb +2 -2
- data/lib/rrj/janus/processus/keepalive/keepalive_thread.rb +17 -12
- data/lib/rrj/janus/transactions/handle.rb +1 -1
- data/lib/rrj/janus/transactions/transaction.rb +3 -3
- data/lib/rrj/models/concerns/janus_instance_callbacks.rb +4 -4
- data/lib/rrj/rabbit/connect.rb +4 -48
- data/lib/rrj/rabbit/connect_fake.rb +68 -0
- data/lib/rrj/rabbit/listener/base.rb +4 -4
- data/lib/rrj/rabbit/propertie.rb +1 -1
- data/lib/rrj/rabbit/rabbit.rb +2 -0
- data/lib/rrj/rails.rb +2 -2
- data/lib/rrj/task.rb +0 -1
- data/lib/rrj/tools/bin/config.rb +3 -2
- data/lib/rrj/tools/bin/init.rb +2 -29
- data/lib/rrj/tools/bin/model.rb +8 -3
- data/lib/rrj/tools/gem/config/gem.rb +74 -0
- data/lib/rrj/tools/gem/config/janus.rb +31 -0
- data/lib/rrj/tools/gem/config/queues.rb +47 -0
- data/lib/rrj/tools/gem/config/rabbit.rb +45 -0
- data/lib/rrj/tools/gem/config.rb +13 -106
- data/lib/rrj/tools/gem/log.rb +48 -122
- data/lib/rrj/tools/gem/option.rb +5 -2
- data/lib/rrj/tools/gem/requests.rb +1 -1
- data/lib/rrj/tools/replaces/admin.rb +2 -2
- data/lib/rrj/tools/replaces/handle.rb +3 -3
- data/lib/rrj/tools/replaces/replace.rb +3 -3
- data/lib/rrj/tools/replaces/session.rb +2 -2
- data/lib/rrj/tools/tools.rb +0 -1
- data/spec/ruby_rabbitmq_janus/tools/{log_spec.rb → logger_spec.rb} +2 -1
- data/spec/spec_helper.rb +7 -1
- metadata +9 -6
- data/lib/rrj/tools/bin/arguments.rb +0 -21
- data/lib/rrj/tools/bin/environment.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c2c4198c70eb700d253b4ff3f8177d170c0dfb7739596d28996080d128152d4
|
4
|
+
data.tar.gz: 6865ae1fc691f3cb88ebe03a59401b8193bf43754b9fc61230564ced574033d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4dd95300f9b59baed2319cd4b4048c51909308e50d0c345287a9f986b7c96d29b3d70535fbe3545c42c6236f4aa7782c6523059f7aae5add543a345a8a09641
|
7
|
+
data.tar.gz: 107548935cfdf99305aa34af5c941ee6996b51773ef9e2f3d8ee9cc9e62ba8390c2a8a5d3cb266c3f4040aeb7f09de5c6b06372d238d59d23d163f3898c5e947
|
data/bin/ruby_rabbitmq_janus
CHANGED
@@ -12,8 +12,12 @@
|
|
12
12
|
# Use `Log` variable in ActionEvents class
|
13
13
|
# for writing in another logger instead rails logs.
|
14
14
|
|
15
|
-
require 'rrj/tools/bin/environment'
|
16
|
-
require 'rrj/tools/bin/arguments'
|
17
15
|
require 'rrj/tools/bin/config'
|
16
|
+
require 'rrj/tools/gem/log'
|
17
|
+
|
18
|
+
Log = RubyRabbitmqJanus::Tools::Logger.create
|
19
|
+
RubyRabbitmqJanus::Tools::Logger.start
|
20
|
+
|
18
21
|
require 'rrj/tools/bin/model'
|
22
|
+
require 'ruby_rabbitmq_janus'
|
19
23
|
require 'rrj/tools/bin/init'
|
data/config/default.md
CHANGED
data/config/default.yml
CHANGED
@@ -58,7 +58,26 @@ gem:
|
|
58
58
|
# Define level to log
|
59
59
|
# UNKNOW, FATAL, ERROR, WARN, INFO, DEBUG
|
60
60
|
level: debug
|
61
|
+
# Precise type logger
|
62
|
+
# stdout : Output standard.
|
63
|
+
# file : Create log file in path 'log/ruby-rabbitmq-janus.log'.
|
64
|
+
# rails : Use logger rails.
|
65
|
+
# remote : Use RemoteSyslogLogger (for papertrail)
|
66
|
+
type: file
|
67
|
+
# Used with type. Complete missing data :
|
68
|
+
# stdout : no option
|
69
|
+
# file : filename used
|
70
|
+
# rails : no option
|
71
|
+
# remote : data output (logs.papertrail.com:4685@program_rrj:backend_host)
|
72
|
+
option: ''
|
61
73
|
# Options for listener thread
|
62
74
|
listener:
|
63
75
|
# Represent path to action_events class in project who use this gem
|
64
76
|
path: 'app/ruby_rabbitmq_janus'
|
77
|
+
# Environment to application
|
78
|
+
environment : 'development'
|
79
|
+
# Precise ORM used :
|
80
|
+
# mongoid or active_record
|
81
|
+
orm: 'mongoid'
|
82
|
+
# Define program name
|
83
|
+
program_name: 'ruby_rabbitmq_janus'
|
data/lib/rrj/binary.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
action_event_path = "#{Dir.pwd}/#{LISTENER_PATH}"
|
4
|
-
Log.debug "Load action events to path : #{action_event_path}"
|
5
|
-
require action_event_path
|
6
|
-
require 'rrj/tools/gem/config'
|
7
3
|
require 'rrj/models/concerns/janus_instance_callbacks'
|
8
4
|
require 'rrj/models/concerns/janus_instance_methods'
|
9
5
|
require 'rrj/models/concerns/janus_instance_validations'
|
10
|
-
require "rrj/models/#{
|
6
|
+
require "rrj/models/#{RubyRabbitmqJanus::Tools::Config.instance.orm}"
|
11
7
|
|
12
8
|
module RubyRabbitmqJanus
|
13
9
|
# :reek:InstanceVariableAssumption
|
@@ -22,8 +18,6 @@ module RubyRabbitmqJanus
|
|
22
18
|
# if enable become true a new session with janus is created
|
23
19
|
class Binary
|
24
20
|
def initialize
|
25
|
-
RubyRabbitmqJanus::Tools::Config.instance
|
26
|
-
|
27
21
|
start_instances
|
28
22
|
end
|
29
23
|
|
data/lib/rrj/errors/error.rb
CHANGED
@@ -18,16 +18,12 @@ module RubyRabbitmqJanus
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def log
|
22
|
-
RubyRabbitmqJanus::Tools::Log
|
23
|
-
end
|
24
|
-
|
25
|
-
def logger
|
26
|
-
log.instance
|
27
|
-
end
|
28
|
-
|
29
21
|
def write_error(message, level)
|
30
|
-
|
22
|
+
if defined?(::Log)
|
23
|
+
::Log.add(level, message)
|
24
|
+
else
|
25
|
+
p "#{level}, #{message}"
|
26
|
+
end
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -85,6 +85,36 @@ module RubyRabbitmqJanus
|
|
85
85
|
super "[Cluster] Cluster parameter is missing, with parameter #{parameter}", :warn
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
89
|
+
class LogType < RubyRabbitmqJanus::Errors::Tools::BaseConfig
|
90
|
+
def initialize
|
91
|
+
super '[LogType] Error with Log Type', :fatal
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class LogOption < RubyRabbitmqJanus::Errors::Tools::BaseConfig
|
96
|
+
def initialize
|
97
|
+
super '[LogOption] Error with Log Option', :fatal
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Environment < RubyRabbitmqJanus::Errors::Tools::BaseConfig
|
102
|
+
def initialize
|
103
|
+
super '[Environment] Error with environment option', :fatal
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class ORM < RubyRabbitmqJanus::Errors::Tools::BaseConfig
|
108
|
+
def initialize
|
109
|
+
super '[ORM] Error with Object Relational Mapping option', :fatal
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class ProgramName < RubyRabbitmqJanus::Errors::Tools::BaseConfig
|
114
|
+
def initialize
|
115
|
+
super '[ProgramName] Error with ProgramName option', :fatal
|
116
|
+
end
|
117
|
+
end
|
88
118
|
end
|
89
119
|
end
|
90
120
|
end
|
data/lib/rrj/init.rb
CHANGED
@@ -9,6 +9,11 @@ require 'logger'
|
|
9
9
|
require 'key_path'
|
10
10
|
require 'active_support'
|
11
11
|
require 'erb'
|
12
|
+
require 'rrj/tools/bin/config'
|
13
|
+
require 'rrj/tools/gem/log'
|
14
|
+
|
15
|
+
Log = RubyRabbitmqJanus::Tools::Logger.create unless defined?(Log)
|
16
|
+
RubyRabbitmqJanus::Tools::Logger.start
|
12
17
|
|
13
18
|
# :reek:TooManyStatements
|
14
19
|
|
@@ -93,11 +93,11 @@ module RubyRabbitmqJanus
|
|
93
93
|
|
94
94
|
def load_request_file
|
95
95
|
@request = request_instance
|
96
|
-
|
96
|
+
::Log.debug "Opening request : #{to_json}"
|
97
97
|
end
|
98
98
|
|
99
99
|
def prepare_request(_options)
|
100
|
-
|
100
|
+
::Log.debug "Prepare request for janus : #{to_json}"
|
101
101
|
end
|
102
102
|
|
103
103
|
def request_instance
|
@@ -13,7 +13,7 @@ module RubyRabbitmqJanus
|
|
13
13
|
class Concurrency
|
14
14
|
# Initialize class with elements for thread communication
|
15
15
|
def initialize
|
16
|
-
|
16
|
+
::Log.info info_thread
|
17
17
|
@rabbit = RubyRabbitmqJanus::Rabbit::Connect.new
|
18
18
|
@lock = Mutex.new
|
19
19
|
@condition = ConditionVariable.new
|
@@ -26,7 +26,7 @@ module RubyRabbitmqJanus
|
|
26
26
|
def initialize_thread
|
27
27
|
@rabbit.transaction_long { transaction_running }
|
28
28
|
rescue Interrupt
|
29
|
-
|
29
|
+
::Log.info "Stop transaction #{self.class.name}"
|
30
30
|
@rabbit.close
|
31
31
|
end
|
32
32
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# :reek:TooManyInstanceVariables
|
7
7
|
# :reek:TooManyStatements
|
8
8
|
# :reek:UncommunicativeVariableName
|
9
|
+
# :reek:TooManyMethods
|
9
10
|
|
10
11
|
module RubyRabbitmqJanus
|
11
12
|
module Janus
|
@@ -23,7 +24,7 @@ module RubyRabbitmqJanus
|
|
23
24
|
@timer = KeepaliveTimer.new
|
24
25
|
@message = KeepaliveMessage.new(instance)
|
25
26
|
instance.set(thread: __id__)
|
26
|
-
|
27
|
+
::Log.info "Keepalive thread id is #{__id__}"
|
27
28
|
super(&block)
|
28
29
|
rescue
|
29
30
|
raise Errors::Janus::KeepaliveThread::Initializer
|
@@ -41,13 +42,13 @@ module RubyRabbitmqJanus
|
|
41
42
|
# Restart session
|
42
43
|
# :reek:TooManyStatements
|
43
44
|
def restart_session
|
44
|
-
|
45
|
+
::Log.warn 'Restart session ...'
|
45
46
|
janus = find_model
|
46
47
|
if janus.present?
|
47
48
|
send_messages_restart
|
48
49
|
janus.set(session: @session)
|
49
50
|
else
|
50
|
-
|
51
|
+
::Log.error 'Janus Instance Model is gone, giving up'
|
51
52
|
end
|
52
53
|
rescue
|
53
54
|
raise Errors::Janus::KeepaliveThread::RestartSession
|
@@ -59,16 +60,16 @@ module RubyRabbitmqJanus
|
|
59
60
|
def start
|
60
61
|
@timer.loop_keepalive do
|
61
62
|
if detached?(find_model)
|
62
|
-
|
63
|
+
::Log.info \
|
63
64
|
"Thread #{__id__} no longer attached to Janus Instance, " \
|
64
65
|
'exiting...'
|
65
66
|
@timer.stop_timer
|
66
67
|
cleanup
|
67
68
|
exit
|
68
69
|
else
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
::Log.info msg_send_ttl(__id__,
|
71
|
+
@message.instance,
|
72
|
+
@timer.time_to_live)
|
72
73
|
response_keepalive
|
73
74
|
end
|
74
75
|
end
|
@@ -90,12 +91,12 @@ module RubyRabbitmqJanus
|
|
90
91
|
janus = find_model
|
91
92
|
@session = @message = nil
|
92
93
|
if detached?(janus)
|
93
|
-
|
94
|
+
::Log.error\
|
94
95
|
"Thread [#{__id__}] no longer attached to Janus Instance " \
|
95
96
|
'(should be dead).'
|
96
97
|
else
|
97
98
|
janus.set(enable: false).unset(%I[thread session])
|
98
|
-
|
99
|
+
::Log.fatal \
|
99
100
|
"Janus Instance [#{janus.instance}] is down, " \
|
100
101
|
"thread [#{__id__}] will die."
|
101
102
|
end
|
@@ -121,13 +122,13 @@ module RubyRabbitmqJanus
|
|
121
122
|
if @message.present?
|
122
123
|
Models::JanusInstance.find(@message.instance)
|
123
124
|
else
|
124
|
-
|
125
|
+
::Log.warn \
|
125
126
|
"Lookup Janus Instance model by session [#{@session}]"
|
126
127
|
Models::JanusInstance.find_by_session(@session)
|
127
128
|
end
|
128
129
|
rescue StandardError => exception
|
129
|
-
|
130
|
-
|
130
|
+
::Log.debug exception
|
131
|
+
::Log.warn \
|
131
132
|
"find_model: rescuing from error #{e.message}"
|
132
133
|
nil
|
133
134
|
end
|
@@ -158,6 +159,10 @@ module RubyRabbitmqJanus
|
|
158
159
|
def publish(message)
|
159
160
|
@publisher.publish(message)
|
160
161
|
end
|
162
|
+
|
163
|
+
def msg_send_ttl(id, inst, ttl)
|
164
|
+
"Thread #{id} sending keepalive to instance #{inst} with TTL #{ttl}"
|
165
|
+
end
|
161
166
|
end
|
162
167
|
end
|
163
168
|
end
|
@@ -56,7 +56,7 @@ module RubyRabbitmqJanus
|
|
56
56
|
# Send a message detach
|
57
57
|
def detach
|
58
58
|
options = opts.merge('instance' => @instance)
|
59
|
-
|
59
|
+
::Log.debug "Detach handle #{options}"
|
60
60
|
publisher.publish(Janus::Messages::Standard.new('base::detach',
|
61
61
|
options))
|
62
62
|
rescue
|
@@ -30,18 +30,18 @@ module RubyRabbitmqJanus
|
|
30
30
|
def choose_queue
|
31
31
|
chan = @rabbit.channel
|
32
32
|
@publisher = if @exclusive
|
33
|
-
|
33
|
+
::Log.debug \
|
34
34
|
'Choose an queue Exclusive : ampq.gen-xxx'
|
35
35
|
Rabbit::Publisher::Exclusive.new(chan, '')
|
36
36
|
else
|
37
|
-
|
37
|
+
::Log.debug \
|
38
38
|
'Choose an queue non Exclusive : to-janus'
|
39
39
|
Rabbit::Publisher::NonExclusive.new(chan)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def send_a_message
|
44
|
-
|
44
|
+
::Log.info 'Publish a message ...'
|
45
45
|
response = read_response(@publisher.publish(yield))
|
46
46
|
Janus::Responses::Standard.new(response)
|
47
47
|
end
|
@@ -9,14 +9,14 @@ module RubyRabbitmqJanus
|
|
9
9
|
|
10
10
|
# Create a session in Janus Instance
|
11
11
|
def callback_create_after
|
12
|
-
|
12
|
+
::Log.debug 'Callback AFTER_VALIDATION'
|
13
13
|
create_a_session_in_janus_instance if enable
|
14
14
|
end
|
15
15
|
|
16
16
|
# Update a keepalive transaction in Janus Instance
|
17
17
|
# Enable or Disable transaction
|
18
18
|
def callback_update_after
|
19
|
-
|
19
|
+
::Log.debug 'Callback AFTER_UPDATE'
|
20
20
|
if enable && enable_changed?
|
21
21
|
create_a_session_in_janus_instance
|
22
22
|
elsif !enable && enable_changed?
|
@@ -27,7 +27,7 @@ module RubyRabbitmqJanus
|
|
27
27
|
# Destroy a session in Janus Instance
|
28
28
|
# :reek:UtilityFunction
|
29
29
|
def callback_destroy_after
|
30
|
-
|
30
|
+
::Log.debug 'Callback AFTER_DESTROY'
|
31
31
|
# LCO: nothing to do, thread will close session and die
|
32
32
|
end
|
33
33
|
|
@@ -54,7 +54,7 @@ module RubyRabbitmqJanus
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def info_instance(text)
|
57
|
-
|
57
|
+
::Log.debug "#{text} in Janus Instance [##{instance}]"
|
58
58
|
end
|
59
59
|
|
60
60
|
def message
|
data/lib/rrj/rabbit/connect.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# :reek:TooManyStatements
|
4
|
-
# :reek:FeatureEnvy
|
5
|
-
# :reek:RepeatedConditional
|
6
|
-
|
7
3
|
module RubyRabbitmqJanus
|
8
4
|
module Rabbit
|
9
5
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
@@ -12,23 +8,14 @@ module RubyRabbitmqJanus
|
|
12
8
|
class Connect
|
13
9
|
# Initialize connection to server RabbitMQ
|
14
10
|
def initialize
|
15
|
-
@rabbit =
|
16
|
-
require 'bunny-mock'
|
17
|
-
BunnyMock.new.start
|
18
|
-
else
|
19
|
-
Bunny.new(read_options_server.merge!(option_log_rabbit))
|
20
|
-
end
|
11
|
+
@rabbit = Bunny.new(Tools::Config.instance.server_settings)
|
21
12
|
rescue => exception
|
22
13
|
raise Errors::Rabbit::Connect::Initialize, exception
|
23
14
|
end
|
24
15
|
|
25
16
|
# Create an transaction with rabbitmq and close after response is received
|
26
17
|
def transaction_short
|
27
|
-
response =
|
28
|
-
fake_transaction
|
29
|
-
else
|
30
|
-
transaction_long { yield }
|
31
|
-
end
|
18
|
+
response = transaction_long { yield }
|
32
19
|
close
|
33
20
|
response
|
34
21
|
rescue => exception
|
@@ -38,11 +25,7 @@ module RubyRabbitmqJanus
|
|
38
25
|
# Create an transaction with rabbitmq and not close
|
39
26
|
def transaction_long
|
40
27
|
start
|
41
|
-
|
42
|
-
@rabbit.channel.queue.pop[:message]
|
43
|
-
else
|
44
|
-
yield
|
45
|
-
end
|
28
|
+
yield
|
46
29
|
rescue => exception
|
47
30
|
raise Errors::Rabbit::Connect::TransactionLong, exception
|
48
31
|
end
|
@@ -63,37 +46,10 @@ module RubyRabbitmqJanus
|
|
63
46
|
|
64
47
|
# Create an channel
|
65
48
|
def channel
|
66
|
-
|
67
|
-
@rabbit.channel
|
68
|
-
else
|
69
|
-
@rabbit.create_channel
|
70
|
-
end
|
49
|
+
@rabbit.create_channel
|
71
50
|
rescue => exception
|
72
51
|
raise Errors::Rabbit::Connect::Channel, exception
|
73
52
|
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def fake_transaction
|
78
|
-
channel = @rabbit.channel
|
79
|
-
queue = channel.queue 'janus-queue-test'
|
80
|
-
queue.publish 'RSpec testing message'
|
81
|
-
queue.pop
|
82
|
-
end
|
83
|
-
|
84
|
-
def read_options_server
|
85
|
-
conn = %w[host port pass user vhost]
|
86
|
-
cfg = Tools::Config.instance.options['rabbit']
|
87
|
-
Hash[conn.map { |value| [value.to_sym, cfg[value]] }]
|
88
|
-
end
|
89
|
-
|
90
|
-
def option_log_rabbit
|
91
|
-
lvl = Tools::Config.instance.log_level_rabbit.upcase.to_sym
|
92
|
-
{
|
93
|
-
log_level: Tools::Log::LEVELS[lvl],
|
94
|
-
log_file: Tools::Log.instance.logdev
|
95
|
-
}
|
96
|
-
end
|
97
53
|
end
|
98
54
|
end
|
99
55
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bunny-mock'
|
4
|
+
|
5
|
+
# :reek:FeatureEnvy
|
6
|
+
|
7
|
+
module RubyRabbitmqJanus
|
8
|
+
module Rabbit
|
9
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
10
|
+
#
|
11
|
+
# Override class connect with a Faker connection with rabbitmq
|
12
|
+
class ConnectFake
|
13
|
+
# Initialize connection to server RabbitMQ
|
14
|
+
def initialize
|
15
|
+
@rabbit = BunnyMock.new.start
|
16
|
+
rescue => exception
|
17
|
+
raise Errors::Rabbit::Connect::Initialize, exception
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create an transaction with rabbitmq and close after response is received
|
21
|
+
def transaction_short
|
22
|
+
response = fake_transaction
|
23
|
+
close
|
24
|
+
response
|
25
|
+
rescue => exception
|
26
|
+
raise Errors::Rabbit::Connect::TransactionShort, exception
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create an transaction with rabbitmq and not close
|
30
|
+
def transaction_long
|
31
|
+
start
|
32
|
+
@rabbit.channel.queue.pop[:message]
|
33
|
+
rescue => exception
|
34
|
+
raise Errors::Rabbit::Connect::TransactionLong, exception
|
35
|
+
end
|
36
|
+
|
37
|
+
# Opening a connection with RabbitMQ
|
38
|
+
def start
|
39
|
+
@rabbit.start
|
40
|
+
rescue => exception
|
41
|
+
raise Errors::Rabbit::Connect::Start, exception
|
42
|
+
end
|
43
|
+
|
44
|
+
# Close connection to server RabbitMQ
|
45
|
+
def close
|
46
|
+
@rabbit.close
|
47
|
+
rescue => exception
|
48
|
+
raise Errors::Rabbit::Connect::Close, exception
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create an channel
|
52
|
+
def channel
|
53
|
+
@rabbit.channel
|
54
|
+
rescue => exception
|
55
|
+
raise Errors::Rabbit::Connect::Channel, exception
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def fake_transaction
|
61
|
+
channel = @rabbit.channel
|
62
|
+
queue = channel.queue 'janus-queue-test'
|
63
|
+
queue.publish 'RSpec testing message'
|
64
|
+
queue.pop
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -46,14 +46,14 @@ module RubyRabbitmqJanus
|
|
46
46
|
# Counts transmitted messages
|
47
47
|
def log_message_id(propertie)
|
48
48
|
message_id = propertie.message_id
|
49
|
-
|
49
|
+
::Log.info "[X] Message reading with ID #{message_id}"
|
50
50
|
end
|
51
51
|
|
52
52
|
def info_subscribe(info, prop, payload)
|
53
|
-
|
54
|
-
|
53
|
+
::Log.debug info
|
54
|
+
::Log.info \
|
55
55
|
"[X] Message reading ##{prop['correlation_id']}"
|
56
|
-
|
56
|
+
::Log.debug payload
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/rrj/rabbit/propertie.rb
CHANGED
@@ -13,7 +13,7 @@ module RubyRabbitmqJanus
|
|
13
13
|
|
14
14
|
# Initialize a message sending to rabbitmq
|
15
15
|
def initialize(instance = 1)
|
16
|
-
|
16
|
+
::Log.debug 'initalize a propertie to message'
|
17
17
|
@correlation = SecureRandom.uuid
|
18
18
|
@instance = instance
|
19
19
|
rescue
|
data/lib/rrj/rabbit/rabbit.rb
CHANGED
data/lib/rrj/rails.rb
CHANGED
@@ -13,8 +13,8 @@ module RubyRabbitmqJanus
|
|
13
13
|
class Rails < ::Rails::Engine
|
14
14
|
config.after_initialize do
|
15
15
|
Log.debug '[RRJ] After initializer'
|
16
|
-
|
17
|
-
|
16
|
+
require File.join(Dir.pwd,
|
17
|
+
RubyRabbitmqJanus::Tools::Config.instance.listener_path)
|
18
18
|
|
19
19
|
Log.info 'Listen public queue in thread'
|
20
20
|
actions = RubyRabbitmqJanus::ActionEvents.new.actions
|
data/lib/rrj/task.rb
CHANGED
data/lib/rrj/tools/bin/config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Load gem
|
3
|
+
# Load gem Config if present
|
4
|
+
# @see https://rubygems.org/gems/config
|
4
5
|
|
5
6
|
begin
|
6
7
|
require 'config'
|
@@ -8,7 +9,7 @@ begin
|
|
8
9
|
if defined?(Config)
|
9
10
|
config_conf = [
|
10
11
|
File.join(Dir.pwd, 'config', 'settings.yml'),
|
11
|
-
File.join(Dir.pwd, 'config', 'settings', "#{
|
12
|
+
File.join(Dir.pwd, 'config', 'settings', "#{ENV['RAILS_ENV']}.yml")
|
12
13
|
]
|
13
14
|
Config.load_and_set_settings(config_conf)
|
14
15
|
end
|
data/lib/rrj/tools/bin/init.rb
CHANGED
@@ -3,39 +3,12 @@
|
|
3
3
|
# Loads files RRJ and write first message in log,
|
4
4
|
# then initialize binary
|
5
5
|
|
6
|
-
|
7
|
-
require '
|
8
|
-
|
9
|
-
# rubocop:disable Naming/ConstantName
|
10
|
-
::Log = if @logger_default
|
11
|
-
RubyRabbitmqJanus::Tools::Log.instance
|
12
|
-
else
|
13
|
-
require_relative @logger_path
|
14
|
-
@logger_class.constantize.instance
|
15
|
-
end
|
16
|
-
# rubocop:enable Naming/ConstantName
|
17
|
-
|
18
|
-
Log.info "RRJ Version : #{RubyRabbitmqJanus::VERSION}"
|
19
|
-
Log.info "\r\n#{RubyRabbitmqJanus::BANNER}"
|
20
|
-
|
6
|
+
p "Has rails engine ?? #{defined?(Rails)} -- #{defined?(::Rails::Engine)}"
|
7
|
+
require 'rrj/rails' # defined?(::Rails::Engine)
|
21
8
|
require File.join(File.dirname(__FILE__), '..', '..', 'binary')
|
22
9
|
|
23
10
|
begin
|
24
|
-
Log.info 'Load events public queue classes'
|
25
11
|
bin = RubyRabbitmqJanus::Binary.new
|
26
|
-
Log.info "Load file : #{File.join(Dir.pwd, LISTENER_PATH)}"
|
27
|
-
require File.join(Dir.pwd, LISTENER_PATH)
|
28
|
-
|
29
|
-
Log.info 'Listen public queue in thread'
|
30
|
-
actions = RubyRabbitmqJanus::ActionEvents.new.actions
|
31
|
-
RubyRabbitmqJanus::Janus::Concurrencies::Event.instance.run(&actions)
|
32
|
-
rescue => exception
|
33
|
-
Log.fatal '!! Fail to start RRJ Thread listen public queue !!'
|
34
|
-
Log.fatal exception
|
35
|
-
exit 1
|
36
|
-
end
|
37
|
-
|
38
|
-
begin
|
39
12
|
Log.info \
|
40
13
|
'Prepare to listen events in queue : ' + \
|
41
14
|
RubyRabbitmqJanus::Tools::Config.instance.queue_janus_instance
|
data/lib/rrj/tools/bin/model.rb
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
# Select ORM between Mongoid and ActiveRecord
|
4
4
|
|
5
|
-
require
|
6
|
-
|
7
|
-
|
5
|
+
require 'rrj/errors/error'
|
6
|
+
require RubyRabbitmqJanus::Tools::Config.instance.orm
|
7
|
+
|
8
|
+
# For mongoid gem
|
9
|
+
if RubyRabbitmqJanus::Tools::Config.instance.orm.eql?('mongoid')
|
10
|
+
Mongoid.load!(File.join(Dir.pwd, 'config', 'mongoid.yml'),
|
11
|
+
RubyRabbitmqJanus::Tools::Config.instance.env.to_sym)
|
12
|
+
end
|