ruby_rabbitmq_janus 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rrj/info.rb +1 -1
- data/lib/rrj/rabbit/publish/base_publisher.rb +10 -6
- data/lib/rrj/rabbit/publish/listener.rb +12 -8
- data/lib/rrj/rabbit/publish/publisher.rb +8 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e7097b3084bdf28a6ca3d98594bf42b6ec88a11
|
4
|
+
data.tar.gz: 12039167df87de0454f6b47f81764392e0b5cb92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 515d7007165d7a1e53485b27bb75265aa5522ebf876655c07945c789efef28cd3ec99071543d8c7062df8c62fe4611d2aa30107ccbd66bf84e74f0b5e7c341da
|
7
|
+
data.tar.gz: 58611d01139e576079557531897b65c24b80e275cce625e519358c263c91432d09cfbd45d6acac4542cd8e862ba96fe6c6c42356e4a25192d60a483e67e92efb
|
data/lib/rrj/info.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'semaphore'
|
2
3
|
|
3
4
|
module RubyRabbitmqJanus
|
4
5
|
module Rabbit
|
@@ -15,13 +16,13 @@ module RubyRabbitmqJanus
|
|
15
16
|
#
|
16
17
|
# @abstract Publish message in RabbitMQ
|
17
18
|
class BasePublisher
|
18
|
-
attr_reader :
|
19
|
+
attr_reader :responses
|
19
20
|
|
20
21
|
# Define a base publisher
|
21
22
|
def initialize
|
22
23
|
Tools::Log.instance.debug 'Create an publisher'
|
23
|
-
@
|
24
|
-
@
|
24
|
+
@responses = []
|
25
|
+
@semaphore= Semaphore.new
|
25
26
|
@lock = Mutex.new
|
26
27
|
end
|
27
28
|
|
@@ -31,11 +32,14 @@ module RubyRabbitmqJanus
|
|
31
32
|
|
32
33
|
# return an response when signal is trigger
|
33
34
|
def return_response
|
35
|
+
Tools::Log.instance.debug 'Waiting response...'
|
36
|
+
@semaphore.wait
|
37
|
+
Tools::Log.instance.debug 'Response received'
|
38
|
+
response = nil
|
34
39
|
@lock.synchronize do
|
35
|
-
|
36
|
-
@condition.wait(@lock)
|
37
|
-
@response
|
40
|
+
response = @responses.shift
|
38
41
|
end
|
42
|
+
response
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -13,18 +13,21 @@ module RubyRabbitmqJanus
|
|
13
13
|
# @param [String] rabbit Information connection to rabbitmq server
|
14
14
|
def initialize(rabbit)
|
15
15
|
super()
|
16
|
+
@responses = []
|
16
17
|
@rabbit = rabbit.channel
|
17
|
-
@response = nil
|
18
18
|
subscribe_queue
|
19
19
|
end
|
20
20
|
|
21
21
|
# Listen a queue and return a body response
|
22
22
|
def listen_events
|
23
|
+
Tools::Log.instance.debug 'Waiting event...'
|
24
|
+
@semaphore.wait
|
25
|
+
Tools::Log.instance.info 'Janus event received .. treatment ..'
|
26
|
+
response = nil
|
23
27
|
lock.synchronize do
|
24
|
-
|
25
|
-
Tools::Log.instance.info 'Janus event received .. treatment ..'
|
26
|
-
yield @response.event, @response
|
28
|
+
response = @responses.shift
|
27
29
|
end
|
30
|
+
yield response.event, response
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
@@ -56,15 +59,16 @@ module RubyRabbitmqJanus
|
|
56
59
|
# Counts transmitted messages
|
57
60
|
def log_message_id(propertie)
|
58
61
|
message_id = propertie.message_id
|
59
|
-
Tools::Log.instance.info "[X] Message reading with ID
|
62
|
+
Tools::Log.instance.info "[X] Message reading with ID #{message_id}"
|
60
63
|
end
|
61
64
|
|
62
65
|
# Sending an signal when an response is reading in queue
|
63
66
|
def synchronize_response(info, payload)
|
64
|
-
|
65
|
-
|
67
|
+
lock.synchronize do
|
68
|
+
@responses.push(Janus::Responses::Event.new(JSON.parse(payload)))
|
69
|
+
end
|
66
70
|
@rabbit.acknowledge(info.delivery_tag, false)
|
67
|
-
|
71
|
+
@semaphore.signal
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
@@ -39,8 +39,14 @@ module RubyRabbitmqJanus
|
|
39
39
|
def subscribe_to_queue
|
40
40
|
reply.subscribe do |_delivery_info, propertie, payload|
|
41
41
|
if @message.correlation.eql?(propertie.correlation_id)
|
42
|
-
|
43
|
-
lock.synchronize
|
42
|
+
Tools::Log.instance.debug "Parsing response payload......"
|
43
|
+
lock.synchronize do
|
44
|
+
@responses.push(JSON.parse payload)
|
45
|
+
end
|
46
|
+
Tools::Log.instance.debug "Response payload is: #{payload}"
|
47
|
+
@semaphore.signal
|
48
|
+
else
|
49
|
+
Tools::Log.instance.error "Response correlation ID mismatch (#{@message.correlation}!=#{propertie.correlation_id})"
|
44
50
|
end
|
45
51
|
end
|
46
52
|
end
|
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.2.
|
4
|
+
version: 1.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- VAILLANT Jeremy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -278,6 +278,20 @@ dependencies:
|
|
278
278
|
- - "~>"
|
279
279
|
- !ruby/object:Gem::Version
|
280
280
|
version: 0.2.2
|
281
|
+
- !ruby/object:Gem::Dependency
|
282
|
+
name: semaphore
|
283
|
+
requirement: !ruby/object:Gem::Requirement
|
284
|
+
requirements:
|
285
|
+
- - "~>"
|
286
|
+
- !ruby/object:Gem::Version
|
287
|
+
version: 0.0.1
|
288
|
+
type: :runtime
|
289
|
+
prerelease: false
|
290
|
+
version_requirements: !ruby/object:Gem::Requirement
|
291
|
+
requirements:
|
292
|
+
- - "~>"
|
293
|
+
- !ruby/object:Gem::Version
|
294
|
+
version: 0.0.1
|
281
295
|
description: |
|
282
296
|
This gem is used to communicate to a server Janus through RabbitMQ software
|
283
297
|
(Message-oriented middleware). It waiting a messages to Rails API who send to
|