messaging-adapter 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/messaging_adapter.rb +2 -1
- data/lib/messaging_adapter/adapters/rabbitmq.rb +13 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d50bf6bba3832495f12d2989f005b837a83bfc2
|
4
|
+
data.tar.gz: 99fbf914726b7fae02d6398fc639e37b1e01632b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0e96bb5f22c9472ead1a903f0c9289f7aa0830f3f24a2c9cc579e7669668b1f8a8ec407e03b1e72d4cda2f94ea55dd872f9a8e59aea296b5da6371cbfcaaa5
|
7
|
+
data.tar.gz: 52e2ee1e54f56c353b7bf85f1f3de160b42a242d8efd770e252807551875ecf6630b043944f3babbcac4c4a6b80a175556495889b5d3b50bef868a5617309534
|
data/lib/messaging_adapter.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# require the adapters
|
4
|
-
Dir[File.dirname(__FILE__) + '/messaging_adapter/adapters/*.rb']
|
4
|
+
Dir[File.dirname(__FILE__) + '/messaging_adapter/adapters/*.rb']
|
5
|
+
.each { |file| require file }
|
5
6
|
|
6
7
|
module MessagingAdapter
|
7
8
|
# MessageBroker class to create broker objects specifying the adapter type
|
@@ -29,19 +29,22 @@ module MessageBrokerAdapter
|
|
29
29
|
exchange.publish(payload.to_json)
|
30
30
|
end
|
31
31
|
|
32
|
-
puts
|
33
|
-
"#{topic} [#{payload}]"
|
32
|
+
puts "- RMQ: Published #{payload.to_json} on #{topic}" if debug_mode?
|
34
33
|
end
|
35
34
|
|
36
35
|
def self.subscribe(queue, options = {})
|
37
36
|
q = subscriber_channel.queue(queue, passive: true)
|
37
|
+
|
38
38
|
options[:block] ||= options[:block].nil? ? true : options[:block]
|
39
|
-
|
40
|
-
|
41
|
-
yield(payload)
|
39
|
+
q.subscribe(block: options[:block]) do |_del_info, _props, payload|
|
40
|
+
yield(JSON.parse(payload))
|
42
41
|
end
|
43
42
|
|
44
|
-
puts "- RMQ: Subscribed successfully to the topic #{queue}"
|
43
|
+
puts "- RMQ: Subscribed successfully to the topic #{queue}" if debug_mode?
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.debug_mode?
|
47
|
+
ENV['MessageBroker_Debug'] == 'true'
|
45
48
|
end
|
46
49
|
|
47
50
|
def self.connection_configs
|
@@ -72,7 +75,8 @@ module MessageBrokerAdapter
|
|
72
75
|
def self.publisher_channel
|
73
76
|
if Thread.current[:rmq_pub_channel].nil?
|
74
77
|
pub_channel_locker.synchronize do
|
75
|
-
Thread.current[:rmq_pub_channel] ||= publisher_connection
|
78
|
+
Thread.current[:rmq_pub_channel] ||= publisher_connection
|
79
|
+
.create_channel
|
76
80
|
end
|
77
81
|
else
|
78
82
|
Thread.current[:rmq_pub_channel]
|
@@ -93,7 +97,8 @@ module MessageBrokerAdapter
|
|
93
97
|
def self.subscriber_channel
|
94
98
|
if Thread.current[:rmq_sub_channel].nil?
|
95
99
|
sub_channel_locker.synchronize do
|
96
|
-
Thread.current[:rmq_sub_channel] ||= subscriber_connection
|
100
|
+
Thread.current[:rmq_sub_channel] ||= subscriber_connection
|
101
|
+
.create_channel
|
97
102
|
end
|
98
103
|
else
|
99
104
|
Thread.current[:rmq_sub_channel]
|