ruby_rabbitmq_janus 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rrj/errors/janus_response.rb +2 -2
- data/lib/rrj/errors/janus_transaction.rb +1 -1
- data/lib/rrj/info.rb +2 -2
- data/lib/rrj/init.rb +26 -27
- data/lib/rrj/janus/janus.rb +2 -5
- data/lib/rrj/janus/threads/event.rb +49 -0
- data/lib/rrj/janus/{keepalive.rb → threads/keepalive.rb} +13 -16
- data/lib/rrj/janus/threads/thread.rb +27 -0
- data/lib/rrj/janus/{transaction_admin.rb → transactions/admin.rb} +2 -1
- data/lib/rrj/janus/{transaction_handle.rb → transactions/handle.rb} +0 -0
- data/lib/rrj/janus/{transaction_session.rb → transactions/session.rb} +0 -0
- data/lib/rrj/janus/{transaction.rb → transactions/transaction.rb} +8 -2
- data/lib/rrj/rabbit/publish/admin.rb +26 -0
- data/lib/rrj/rabbit/publish/base_publisher.rb +37 -0
- data/lib/rrj/rabbit/publish/exclusive.rb +21 -0
- data/lib/rrj/rabbit/publish/listener.rb +40 -0
- data/lib/rrj/rabbit/publish/non_exclusive.rb +27 -0
- data/lib/rrj/rabbit/publish/publisher.rb +52 -0
- data/lib/rrj/rabbit/rabbit.rb +1 -1
- data/lib/rrj/tools/env.rb +1 -0
- data/lib/rrj/tools/log.rb +1 -0
- data/lib/rrj/tools/replaces.rb +1 -0
- data/lib/rrj/tools/replaces_admin.rb +2 -0
- metadata +16 -9
- data/lib/rrj/rabbit/publish.rb +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c75cd0c7c7d224f8c5f3386e7eb847de7ffcecbc
|
4
|
+
data.tar.gz: 17fe7cc7dfb933f50fe6293fbd9015f209bae0d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07d48d6283589d3adfd76be6820de3bb3508cf565a0e22af174e1704b8eeefdfb8bffca6d7d3afeb904627e92d71ac0af391545a58abe18d3985fae0d8b4ee36
|
7
|
+
data.tar.gz: b6704497ca1ed9f0bace2e8f024e6da2a2e4998948a64371a662572aecab6c00a941699e9bbd0a3bc8a16d6f01de39eaa8889e60345df2af3edb3fd8e700377c
|
@@ -14,7 +14,7 @@ module RubyRabbitmqJanus
|
|
14
14
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
15
15
|
# Define an error for response initalize
|
16
16
|
class JanusResponseInit < JanusResponse
|
17
|
-
def
|
17
|
+
def initialize(message)
|
18
18
|
super "Error create object : #{message}"
|
19
19
|
end
|
20
20
|
end
|
@@ -70,7 +70,7 @@ module RubyRabbitmqJanus
|
|
70
70
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
71
71
|
# Define an error for response data
|
72
72
|
class JanusResponseDataId < JanusResponse
|
73
|
-
def
|
73
|
+
def initialize(message)
|
74
74
|
super "Error Data : #{message}"
|
75
75
|
end
|
76
76
|
end
|
@@ -15,7 +15,7 @@ module RubyRabbitmqJanus
|
|
15
15
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
16
16
|
# Define an exception for running_handle
|
17
17
|
class JanusTransactionHandle
|
18
|
-
def
|
18
|
+
def initialize(message)
|
19
19
|
super "[Transaction] Error handle #{message}"
|
20
20
|
end
|
21
21
|
end
|
data/lib/rrj/info.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Define constant to gem.
|
4
4
|
module RubyRabbitmqJanus
|
5
5
|
# Define version to gem
|
6
|
-
VERSION = '1.0.
|
6
|
+
VERSION = '1.0.2'
|
7
7
|
|
8
8
|
# Define a summary description to gem
|
9
9
|
SUMMARY = 'Ruby RabbitMQ Janus'
|
@@ -21,7 +21,7 @@ module RubyRabbitmqJanus
|
|
21
21
|
# Define a post install message
|
22
22
|
POST_INSTALL = \
|
23
23
|
"# ====================================================== #\n" \
|
24
|
-
"# Thanks for installing!
|
24
|
+
"# Thanks for installing RRJ ! #\n" \
|
25
25
|
"# #{HOMEPAGE}. #\n" \
|
26
26
|
"# ;;;;;;;;;;;:. #\n" \
|
27
27
|
"# ;;;;;;;;;;;;;;;;;; #\n" \
|
data/lib/rrj/init.rb
CHANGED
@@ -17,17 +17,13 @@ module RubyRabbitmqJanus
|
|
17
17
|
# @!attribute [r] session
|
18
18
|
# :reek:BooleanParameter
|
19
19
|
class RRJ
|
20
|
-
attr_reader :session
|
20
|
+
attr_reader :session, :event
|
21
21
|
|
22
22
|
# Returns a new instance of RubyRabbitmqJanus
|
23
|
-
def initialize
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Tools::Requests.instance
|
28
|
-
|
29
|
-
@session = Janus::Keepalive.new.session
|
30
|
-
|
23
|
+
def initialize(listen_queue_classic = true)
|
24
|
+
start_instances_tools
|
25
|
+
@session = Janus::Keepalive.instance.session
|
26
|
+
Janus::Event.instance if listen_queue_classic
|
31
27
|
@transaction = nil
|
32
28
|
rescue => error
|
33
29
|
raise Errors::RRJErrorInit, error
|
@@ -38,7 +34,7 @@ module RubyRabbitmqJanus
|
|
38
34
|
# Given a type to request. JSON request writing in 'config/requests/'
|
39
35
|
# @param [Bollean] exclusive
|
40
36
|
# Use an exclusive queue or not
|
41
|
-
# @
|
37
|
+
# @example Sending an message info
|
42
38
|
# RubyRabbitmqJanus::RRJ.new.message_simple('base::info')
|
43
39
|
# #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... }
|
44
40
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
@@ -54,7 +50,7 @@ module RubyRabbitmqJanus
|
|
54
50
|
# @param [Hash] options Options update in request
|
55
51
|
# @param [Bollean] exclusive
|
56
52
|
# Use an exclusive queue or not
|
57
|
-
# @
|
53
|
+
# @example Sending an message create
|
58
54
|
# RubyRabbitmqJanus::RRJ.new.message_session('base::create')
|
59
55
|
# #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... }
|
60
56
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
@@ -70,7 +66,7 @@ module RubyRabbitmqJanus
|
|
70
66
|
# @param [String] type
|
71
67
|
# Given a type to request. JSON request writing in 'config/requests/'
|
72
68
|
# @param [Hash] options Options update in request
|
73
|
-
# @
|
69
|
+
# @example Sending an message create
|
74
70
|
# RubyRabbitmqJanus::RRJ.new.message_admin('admin::sessions')
|
75
71
|
# #=> {"janus":"success","sessions": [12345, 8786567465465, ...] }
|
76
72
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
@@ -83,35 +79,28 @@ module RubyRabbitmqJanus
|
|
83
79
|
# Send an message in handle session in current session.
|
84
80
|
# @param [String] type
|
85
81
|
# Given a type to request. JSON request writing in 'config/requests/'
|
86
|
-
# @param [Hash]
|
87
|
-
# @param [
|
88
|
-
#
|
89
|
-
# @exemple Sending an message create
|
82
|
+
# @param [Hash] replace Options update in request
|
83
|
+
# @param [Hash] add Elements adding to request
|
84
|
+
# @example Sending an message create
|
90
85
|
# RubyRabbitmqJanus::RRJ.new.message_session('base::create')
|
91
86
|
# #=> {"janus":"server_info","name":"Janus WebRTC Gateway" ... }
|
92
87
|
# @return [RubyRabbitmqJanus::Janus::Response] Give an object response to janus server
|
93
88
|
def message_handle(type, replace = {}, add = {})
|
94
89
|
options = { 'replace' => replace, 'add' => add }
|
95
|
-
Tools::Log.instance.debug "Transaction : #{@transaction}"
|
96
90
|
@transaction.publish_message_handle(type, options)
|
97
91
|
end
|
98
92
|
|
99
|
-
#
|
100
|
-
# def transaction_simple(type, replace = {}, add = {})
|
101
|
-
# options = { 'replace' => replace, 'add' => add }
|
102
|
-
# Janus::Transaction.new(@session).handle_running_simple(type, options)
|
103
|
-
# end
|
104
|
-
|
105
|
-
# Define an handle and establish connection with janus
|
93
|
+
# Define an handle transaction and establish connection with janus
|
106
94
|
def start_handle(exclusive = false)
|
107
|
-
@transaction
|
95
|
+
@transaction ||= Janus::TransactionHandle.new(@session)
|
108
96
|
@transaction.handle_connect(exclusive) { yield }
|
109
97
|
rescue => error
|
110
98
|
raise Errors::RRJErrorHandle, error
|
111
99
|
end
|
112
100
|
|
101
|
+
# Define an handle admin transaction and establish connection with janus
|
113
102
|
def start_handle_admin
|
114
|
-
@transaction
|
103
|
+
@transaction ||= Janus::TransactionAdmin.new(@session)
|
115
104
|
@transaction.handle_connect { yield }
|
116
105
|
rescue => error
|
117
106
|
raise Errors::RRJErrorHandle, error
|
@@ -124,7 +113,7 @@ module RubyRabbitmqJanus
|
|
124
113
|
|
125
114
|
# Start an short transaction, this queue is not exclusive
|
126
115
|
def handle_message_simple(type, replace = {}, add = {})
|
127
|
-
@transaction
|
116
|
+
@transaction ||= Janus::TransactionHandle.new(@session)
|
128
117
|
@transaction.handle_connect_and_stop(false) do
|
129
118
|
message_handle(type, replace, add).for_plugin
|
130
119
|
end
|
@@ -134,6 +123,16 @@ module RubyRabbitmqJanus
|
|
134
123
|
|
135
124
|
private
|
136
125
|
|
126
|
+
attr_accessor :transaction
|
127
|
+
|
128
|
+
# Start singleton instances
|
129
|
+
def start_instances_tools
|
130
|
+
Tools::Env.instance
|
131
|
+
Tools::Log.instance
|
132
|
+
Tools::Config.instance
|
133
|
+
Tools::Requests.instance
|
134
|
+
end
|
135
|
+
|
137
136
|
# Return a current session if not specified
|
138
137
|
def use_current_session?(option)
|
139
138
|
{ 'session_id' => @session } unless option.key?('session_id')
|
data/lib/rrj/janus/janus.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rrj/janus/
|
3
|
+
require 'rrj/janus/threads/thread'
|
4
4
|
require 'rrj/janus/message'
|
5
5
|
require 'rrj/janus/admin'
|
6
6
|
require 'rrj/janus/response'
|
7
|
-
require 'rrj/janus/transaction'
|
8
|
-
require 'rrj/janus/transaction_session'
|
9
|
-
require 'rrj/janus/transaction_handle'
|
10
|
-
require 'rrj/janus/transaction_admin'
|
7
|
+
require 'rrj/janus/transactions/transaction'
|
11
8
|
|
12
9
|
module RubyRabbitmqJanus
|
13
10
|
# Module interaction with Janus
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
5
|
+
module Janus
|
6
|
+
# For listen standard queue ("from-janus" by default)
|
7
|
+
class Event < OneThread
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
# Initialize Event object. Is used for listen an standard out queue to Janus
|
11
|
+
def initialize
|
12
|
+
Tools::Log.instance.debug 'Start listen events in from-janus queue'
|
13
|
+
@response = nil
|
14
|
+
super
|
15
|
+
listen_live
|
16
|
+
end
|
17
|
+
|
18
|
+
# Start listen queue and return each message
|
19
|
+
def listen
|
20
|
+
lock.synchronize { condition.wait(lock) }
|
21
|
+
@response
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Listen q queue "from-janus"
|
27
|
+
def listen_live
|
28
|
+
start_thread
|
29
|
+
end
|
30
|
+
|
31
|
+
# Intialize an listen to queue
|
32
|
+
def initialize_thread
|
33
|
+
start_transaction
|
34
|
+
rescue Interrupt
|
35
|
+
Tools::Log.instance.info 'Stop to listen standard queue'
|
36
|
+
rabbit.close
|
37
|
+
end
|
38
|
+
|
39
|
+
# Start a transaction with Rabbit an Janus
|
40
|
+
def start_transaction
|
41
|
+
rabbit.transaction_long do
|
42
|
+
publisher = Rabbit::Publisher::Listener.new(rabbit)
|
43
|
+
@response = publisher.listen_events
|
44
|
+
lock.synchronize { condition.signal }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -4,20 +4,20 @@ module RubyRabbitmqJanus
|
|
4
4
|
module Janus
|
5
5
|
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
6
|
# Manage sending keepalive message
|
7
|
-
|
8
|
-
|
7
|
+
class Keepalive < OneThread
|
8
|
+
include Singleton
|
9
|
+
|
9
10
|
# Initalize a keepalive message
|
10
11
|
def initialize
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
@condition = ConditionVariable.new
|
12
|
+
Tools::Log.instance.debug 'Create an session for keepalive'
|
13
|
+
super
|
14
|
+
@publish = @response = nil
|
15
15
|
session_live
|
16
16
|
end
|
17
17
|
|
18
18
|
# Return an number session created
|
19
19
|
def session
|
20
|
-
|
20
|
+
lock.synchronize { condition.wait(lock) }
|
21
21
|
@response.session
|
22
22
|
end
|
23
23
|
|
@@ -25,26 +25,23 @@ module RubyRabbitmqJanus
|
|
25
25
|
|
26
26
|
# Send to regular interval a message keepalive
|
27
27
|
def session_live
|
28
|
-
|
29
|
-
Tools::Log.instance.debug 'Create an session for keepalive'
|
30
|
-
initialize_thread
|
31
|
-
end
|
28
|
+
start_thread
|
32
29
|
end
|
33
30
|
|
34
31
|
# Initialize an session with janus and start a keepalive transaction
|
35
32
|
def initialize_thread
|
36
|
-
|
33
|
+
rabbit.start
|
37
34
|
@response = session_start
|
38
|
-
|
35
|
+
lock.synchronize { condition.signal }
|
39
36
|
session_keepalive(ttl)
|
40
|
-
|
37
|
+
rabbit.close
|
41
38
|
end
|
42
39
|
|
43
40
|
# Star an session janus
|
44
41
|
def session_start
|
45
42
|
msg_create = Janus::Message.new 'base::create'
|
46
|
-
@publish = Rabbit::PublishExclusive.new(
|
47
|
-
Janus::Response.new
|
43
|
+
@publish = Rabbit::Publisher::PublishExclusive.new(rabbit.channel, '')
|
44
|
+
@response = Janus::Response.new(@publish.send_a_message(msg_create))
|
48
45
|
end
|
49
46
|
|
50
47
|
# Create an loop for sending a keepalive message
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Janus
|
5
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
6
|
+
# Abstract class for janus Event and Keepalive
|
7
|
+
class OneThread
|
8
|
+
# Initialize class with elements for thread communication
|
9
|
+
def initialize
|
10
|
+
@rabbit = Rabbit::Connect.new
|
11
|
+
@lock = Mutex.new
|
12
|
+
@condition = ConditionVariable.new
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def start_thread
|
18
|
+
Thread.new { initialize_thread }
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :rabbit, :lock, :condition
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rrj/janus/threads/keepalive'
|
27
|
+
require 'rrj/janus/threads/event'
|
@@ -13,6 +13,7 @@ module RubyRabbitmqJanus
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
# Choose queue, create an handle, connect to rabbitmq server and send messages
|
16
17
|
def handle_connect
|
17
18
|
rabbit.transaction_long do
|
18
19
|
choose_queue
|
@@ -36,7 +37,7 @@ module RubyRabbitmqJanus
|
|
36
37
|
|
37
38
|
# Define queue used for admin message
|
38
39
|
def choose_queue
|
39
|
-
@publish = Rabbit::
|
40
|
+
@publish = Rabbit::PublisherPublishAdmin.new(rabbit.channel)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
File without changes
|
File without changes
|
@@ -32,9 +32,11 @@ module RubyRabbitmqJanus
|
|
32
32
|
def choose_queue(exclusive = false)
|
33
33
|
chan = @rabbit.channel
|
34
34
|
@publish = if exclusive
|
35
|
-
|
35
|
+
Tools::Log.instance.debug 'Choose an queue non Exclusive : to-janus'
|
36
|
+
Rabbit::Publisher::PublishNonExclusive.new(chan)
|
36
37
|
else
|
37
|
-
|
38
|
+
Tools::Log.instance.debug 'Choose an queue Exclusive : ampq.gen-xxx'
|
39
|
+
Rabbit::Publisher::PublishExclusive.new(chan, '')
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
@@ -51,3 +53,7 @@ module RubyRabbitmqJanus
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
56
|
+
|
57
|
+
require 'rrj/janus/transactions/session'
|
58
|
+
require 'rrj/janus/transactions/handle'
|
59
|
+
require 'rrj/janus/transactions/admin'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Rabbit
|
5
|
+
module Publisher
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# This publisher send and read an message in admin queues
|
8
|
+
class PublisherAdmin < Publisher
|
9
|
+
# Intialize an queue non eclusive for admin/monitor API with Janus
|
10
|
+
def initialize(exchange)
|
11
|
+
super(exchange)
|
12
|
+
@reply = exchange.queue(queue_from)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :reply
|
18
|
+
|
19
|
+
# Define queue used for posting a message to API admin
|
20
|
+
def queue_from
|
21
|
+
Tools::Config.instance.options['queues']['admin']['queue_from']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Rabbit
|
5
|
+
module Publisher
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# @abstract Publish message in RabbitMQ
|
8
|
+
class BasePublisher
|
9
|
+
attr_reader :response
|
10
|
+
|
11
|
+
# Define a base publisher
|
12
|
+
def initialize
|
13
|
+
Tools::Log.instance.debug 'Create an publisher'
|
14
|
+
@response = nil
|
15
|
+
@condition = ConditionVariable.new
|
16
|
+
@lock = Mutex.new
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_accessor :condition, :lock
|
22
|
+
|
23
|
+
# return an response when signal is trigger
|
24
|
+
def return_response
|
25
|
+
Tools::Log.instance.debug 'Waiting an response ...'
|
26
|
+
@lock.synchronize do
|
27
|
+
@condition.wait(@lock)
|
28
|
+
response
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rrj/rabbit/publish/publisher'
|
37
|
+
require 'rrj/rabbit/publish/listener'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Rabbit
|
5
|
+
module Publisher
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
class PublishExclusive < Publisher
|
8
|
+
# Initialize an queue exclusive and generated automaticaly by bunny
|
9
|
+
def initialize(exchange, name_queue)
|
10
|
+
@reply = exchange.queue(name_queue, exclusive: true)
|
11
|
+
super(exchange)
|
12
|
+
Tools::Log.instance.debug 'Create/Connect to queue exclusive'
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :reply
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Rabbit
|
5
|
+
module Publisher
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# This publisher don't post message. Is listen just an standard queue to Janus.
|
8
|
+
# By default is "from-janus". It's a parameter in config to this gem.
|
9
|
+
class Listener < BasePublisher
|
10
|
+
# Define an publisher
|
11
|
+
def initialize(rabbit)
|
12
|
+
super()
|
13
|
+
@count = 1
|
14
|
+
@rabbit = rabbit.channel
|
15
|
+
@reply = @rabbit.queue(Tools::Config.instance.options['queues']['queue_from'])
|
16
|
+
Tools::Log.instance.debug "Waiting message from queue : #{@reply.name}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Listen a queue and return a body response
|
20
|
+
def listen_events
|
21
|
+
@reply.subscribe do |_info_delivery, _propertie, payload|
|
22
|
+
synchronize_response(payload)
|
23
|
+
end
|
24
|
+
return_response
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Sending an signal when an response is reading in queue
|
30
|
+
def synchronize_response(payload)
|
31
|
+
@response = JSON.parse payload
|
32
|
+
Tools::Log.instance.debug \
|
33
|
+
"[X] Message number reading : #{@count} -- type : #{response['janus']}"
|
34
|
+
@count += 1
|
35
|
+
lock.synchronize { condition.signal }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Rabbit
|
5
|
+
module Publisher
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# Publish message in queue non exclusive. By default "to-janus".
|
8
|
+
# This an option in config to this gem.
|
9
|
+
class PublishNonExclusive < Publisher
|
10
|
+
def initialize(exchange)
|
11
|
+
@reply = exchange.queue(queue_from)
|
12
|
+
super(exchange)
|
13
|
+
Tools::Log.instance.debug 'Create/Connect to queue non exclusive'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :reply
|
19
|
+
|
20
|
+
# Define queue used for posting a message to API public
|
21
|
+
def queue_from
|
22
|
+
Tools::Config.instance.options['queues']['queue_from']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyRabbitmqJanus
|
4
|
+
module Rabbit
|
5
|
+
module Publisher
|
6
|
+
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
+
# This publisher send and read an message in queues
|
8
|
+
class Publisher < BasePublisher
|
9
|
+
# Intialize a publisher for sending and reading a message
|
10
|
+
def initialize(exchange)
|
11
|
+
super()
|
12
|
+
@exchange = exchange.default_exchange
|
13
|
+
@message = nil
|
14
|
+
subscribe_to_queue
|
15
|
+
end
|
16
|
+
|
17
|
+
# Publish an message in queue
|
18
|
+
def send_a_message(request)
|
19
|
+
Tools::Log.instance.info "Send request type : #{request.type}"
|
20
|
+
@message = request
|
21
|
+
@exchange.publish(@message.to_json,
|
22
|
+
request.options.merge!(reply_to: queue_name))
|
23
|
+
return_response
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Subscribe to queue selectd with a message
|
29
|
+
def subscribe_to_queue
|
30
|
+
reply.subscribe do |_delivery_info, propertie, payload|
|
31
|
+
if @message.correlation.eql?(propertie.correlation_id)
|
32
|
+
@response = JSON.parse payload
|
33
|
+
lock.synchronize { condition.signal }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Name to queue used for this publisher
|
39
|
+
# @return [String] Name to queue used
|
40
|
+
def queue_name
|
41
|
+
reply.name
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_accessor :message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'rrj/rabbit/publish/admin'
|
51
|
+
require 'rrj/rabbit/publish/exclusive'
|
52
|
+
require 'rrj/rabbit/publish/non_exclusive'
|
data/lib/rrj/rabbit/rabbit.rb
CHANGED
data/lib/rrj/tools/env.rb
CHANGED
data/lib/rrj/tools/log.rb
CHANGED
data/lib/rrj/tools/replaces.rb
CHANGED
@@ -28,12 +28,14 @@ module RubyRabbitmqJanus
|
|
28
28
|
Tools::Log.instance.warn "Error replace admin_secret : #{message}"
|
29
29
|
end
|
30
30
|
|
31
|
+
# Replace level element
|
31
32
|
def replace_level
|
32
33
|
request['level'] = opts['level']
|
33
34
|
rescue => message
|
34
35
|
Tools::Log.instance.warn "Error replace level : #{message}"
|
35
36
|
end
|
36
37
|
|
38
|
+
# Replace debug element
|
37
39
|
def replace_debug
|
38
40
|
request['debug'] = opts['debug']
|
39
41
|
rescue => message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_rabbitmq_janus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VAILLANT Jeremy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -342,16 +342,23 @@ files:
|
|
342
342
|
- lib/rrj/init.rb
|
343
343
|
- lib/rrj/janus/admin.rb
|
344
344
|
- lib/rrj/janus/janus.rb
|
345
|
-
- lib/rrj/janus/keepalive.rb
|
346
345
|
- lib/rrj/janus/message.rb
|
347
346
|
- lib/rrj/janus/response.rb
|
348
|
-
- lib/rrj/janus/
|
349
|
-
- lib/rrj/janus/
|
350
|
-
- lib/rrj/janus/
|
351
|
-
- lib/rrj/janus/
|
347
|
+
- lib/rrj/janus/threads/event.rb
|
348
|
+
- lib/rrj/janus/threads/keepalive.rb
|
349
|
+
- lib/rrj/janus/threads/thread.rb
|
350
|
+
- lib/rrj/janus/transactions/admin.rb
|
351
|
+
- lib/rrj/janus/transactions/handle.rb
|
352
|
+
- lib/rrj/janus/transactions/session.rb
|
353
|
+
- lib/rrj/janus/transactions/transaction.rb
|
352
354
|
- lib/rrj/rabbit/connect.rb
|
353
355
|
- lib/rrj/rabbit/propertie.rb
|
354
|
-
- lib/rrj/rabbit/publish.rb
|
356
|
+
- lib/rrj/rabbit/publish/admin.rb
|
357
|
+
- lib/rrj/rabbit/publish/base_publisher.rb
|
358
|
+
- lib/rrj/rabbit/publish/exclusive.rb
|
359
|
+
- lib/rrj/rabbit/publish/listener.rb
|
360
|
+
- lib/rrj/rabbit/publish/non_exclusive.rb
|
361
|
+
- lib/rrj/rabbit/publish/publisher.rb
|
355
362
|
- lib/rrj/rabbit/rabbit.rb
|
356
363
|
- lib/rrj/tools/config.rb
|
357
364
|
- lib/rrj/tools/env.rb
|
@@ -368,7 +375,7 @@ licenses:
|
|
368
375
|
metadata: {}
|
369
376
|
post_install_message: |-
|
370
377
|
# ====================================================== #
|
371
|
-
# Thanks for installing!
|
378
|
+
# Thanks for installing RRJ ! #
|
372
379
|
# https://github.com/dazzl-tv/ruby-rabbitmq-janus. #
|
373
380
|
# ;;;;;;;;;;;:. #
|
374
381
|
# ;;;;;;;;;;;;;;;;;; #
|
data/lib/rrj/rabbit/publish.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# :reek:FeatureEnvy and :reek:InstanceVariableAssumption
|
4
|
-
module RubyRabbitmqJanus
|
5
|
-
module Rabbit
|
6
|
-
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
7
|
-
# @abstract Publish message in RabbitMQ
|
8
|
-
class Publish
|
9
|
-
# Define Exchange operation
|
10
|
-
def initialize(exchange)
|
11
|
-
Tools::Log.instance.debug 'Create/Connect to queue'
|
12
|
-
@exchange = exchange.default_exchange
|
13
|
-
@message = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
# Send a message in queue
|
17
|
-
def send_a_message(request)
|
18
|
-
Tools::Log.instance.info "Send request type : #{request.type}"
|
19
|
-
@message = request
|
20
|
-
@exchange.publish(@message.to_json, request.options)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
25
|
-
# @abstract Publish an message in RabbitMQ and waiting a response
|
26
|
-
class PublishReply < Publish
|
27
|
-
# Initialize a queue
|
28
|
-
def initialize(exchange)
|
29
|
-
@condition = ConditionVariable.new
|
30
|
-
@lock = Mutex.new
|
31
|
-
@response = nil
|
32
|
-
subscribe_to_queue
|
33
|
-
super
|
34
|
-
end
|
35
|
-
|
36
|
-
# Publish an message in rabbitmq
|
37
|
-
def send_a_message(request)
|
38
|
-
Tools::Log.instance.info "Send request type : #{request.type}"
|
39
|
-
@exchange.publish(read_message(request),
|
40
|
-
request.options.merge!(reply_to: @reply.name))
|
41
|
-
@lock.synchronize { @condition.wait(@lock) }
|
42
|
-
@response
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
# Read message and return to JSON format
|
48
|
-
def read_message(request)
|
49
|
-
@message = request
|
50
|
-
@message.to_json
|
51
|
-
end
|
52
|
-
|
53
|
-
# Subscribe to queue in Rabbitmq
|
54
|
-
def subscribe_to_queue
|
55
|
-
@reply.subscribe do |_delivery_info, properties, payload|
|
56
|
-
if @message.correlation.eql?(properties.correlation_id)
|
57
|
-
@response = JSON.parse payload
|
58
|
-
@lock.synchronize { @condition.signal }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
65
|
-
# Publish message in non exclusive queue
|
66
|
-
class PublishNonExclusive < PublishReply
|
67
|
-
# Initialize an queue non exclusive
|
68
|
-
def initialize(exchange)
|
69
|
-
@reply = exchange.queue(Tools::Config.instance.options['queues']['queue_from'])
|
70
|
-
super(exchange)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Publish for admin Janus
|
75
|
-
class PublishAdmin < PublishReply
|
76
|
-
# Initialize an queue non exclusive
|
77
|
-
def initialize(exchange)
|
78
|
-
name = Tools::Config.instance.options['queues']['admin']['queue_from']
|
79
|
-
@reply = exchange.queue(name)
|
80
|
-
super(exchange)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
|
85
|
-
# Publish message in exclusive queue
|
86
|
-
class PublishExclusive < PublishReply
|
87
|
-
# Initialize an queue exclusive
|
88
|
-
def initialize(exchange, name_queue = '')
|
89
|
-
@reply = exchange.queue(name_queue, exclusive: true)
|
90
|
-
super(exchange)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Name to queue
|
94
|
-
# @return [String] Name to queue used
|
95
|
-
def queue_name
|
96
|
-
@reply.name
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|