omf_common 6.2.0.pre.1 → 6.2.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/omf_common/comm.rb +1 -15
- data/lib/omf_common/comm/amqp/amqp_topic.rb +7 -5
- data/lib/omf_common/comm/topic.rb +12 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmU3MzM4YzI4ZDI3MmQ0OTIwZTk2NjYxYTcyMTkzNjkwYTJjOGJmZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTBjZDRlMzMxZGZhNDdlN2M4YzQ1ZDExNjZhODQxOWE3MWIxZDM5OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2RmM2VjNmU5MWNlMjI0ZjYzNTU2MzhhMWI4NzI5N2JlNjg2MzcwOWMxNTVi
|
10
|
+
YzdiMjJlMDM5YzBhYWY0YWMxYWE4Mzc4NDFlMTc0YTEwY2M1MDMyNDc4OWMz
|
11
|
+
ZjQzZmE0MWRlYjJjYWU4NWY1MzhkMGRiMDJlYmRiMThkYTY2MTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Nzg4NDc4NzdmMWE0YTkwM2RlYWY4MzRlOWMxMmM1YmQ4Mjg5NWNjY2E1ZTUy
|
14
|
+
NTM0YmIyNzMzN2Q0M2M2Mzc2MWRhNDZjYjcwZmMzZmYwZjhlMTQ0ODVlY2Qy
|
15
|
+
MzEyODA5ZDllNjZkMGI4NzdiMzExY2UxYTc4NTMwMmVmZWFlYTQ=
|
data/lib/omf_common/comm.rb
CHANGED
@@ -151,7 +151,7 @@ module OmfCommon
|
|
151
151
|
def subscribe(topic_name, opts = {}, &block)
|
152
152
|
tna = (topic_name.is_a? Array) ? topic_name : [topic_name]
|
153
153
|
ta = tna.collect do |tn|
|
154
|
-
t = create_topic(tn.to_s)
|
154
|
+
t = create_topic(tn.to_s, opts)
|
155
155
|
if block
|
156
156
|
t.on_subscribed do
|
157
157
|
block.call(t)
|
@@ -162,20 +162,6 @@ module OmfCommon
|
|
162
162
|
ta[0]
|
163
163
|
end
|
164
164
|
|
165
|
-
# Publish a message on a topic
|
166
|
-
#
|
167
|
-
# @param [String, Array] topic_name Pubsub topic name
|
168
|
-
# @param [OmfCoomon::Message] message
|
169
|
-
#
|
170
|
-
def publish(topic_name, message)
|
171
|
-
#puts "PUBLISH>>>>> #{topic_name}::#{message}"
|
172
|
-
tna = (topic_name.is_a? Array) ? topic_name : [topic_name]
|
173
|
-
ta = tna.collect do |tn|
|
174
|
-
t = create_topic(tn)
|
175
|
-
t.publish(message)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
165
|
# Return the options used to initiate this
|
180
166
|
# communicator.
|
181
167
|
#
|
@@ -49,6 +49,7 @@ module OmfCommon
|
|
49
49
|
@lock = Monitor.new
|
50
50
|
@subscribed = false
|
51
51
|
@on_subscribed_handlers = []
|
52
|
+
@routing_key = opts[:routing_key]
|
52
53
|
|
53
54
|
# @communicator.on_reconnect(self) do
|
54
55
|
# info "Resubscribe '#{self}'"
|
@@ -66,10 +67,11 @@ module OmfCommon
|
|
66
67
|
# end
|
67
68
|
channel.queue("", :exclusive => true, :auto_delete => true) do |queue|
|
68
69
|
#puts "QQ1(#{id}): #{queue}"
|
69
|
-
queue.bind(@exchange)
|
70
|
+
queue.bind(@exchange, routing_key: @routing_key)
|
71
|
+
|
70
72
|
queue.subscribe do |headers, payload|
|
71
73
|
#puts "===(#{id}) Incoming message '#{headers.content_type}'"
|
72
|
-
debug "Received message on #{@address}"
|
74
|
+
debug "Received message on #{@address} | #{@routing_key}"
|
73
75
|
MPReceived.inject(Time.now.to_f, @address, payload.to_s[/mid\":\"(.{36})/, 1]) if OmfCommon::Measure.enabled?
|
74
76
|
Message.parse(payload, headers.content_type) do |msg|
|
75
77
|
#puts "---(#{id}) Parsed message '#{msg}'"
|
@@ -88,12 +90,12 @@ module OmfCommon
|
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
|
-
def _send_message(msg, block = nil)
|
93
|
+
def _send_message(msg, opts = {}, block = nil)
|
92
94
|
super
|
93
95
|
content_type, content = msg.marshall(self)
|
94
|
-
debug "(#{id}) Send message (#{content_type}) #{msg.inspect}"
|
96
|
+
debug "(#{id}) Send message (#{content_type}) #{msg.inspect} TO #{opts[:routing_key]}"
|
95
97
|
if @exchange
|
96
|
-
@exchange.publish(content, content_type: content_type, message_id: msg.mid)
|
98
|
+
@exchange.publish(content, content_type: content_type, message_id: msg.mid, routing_key: opts[:routing_key])
|
97
99
|
MPPublished.inject(Time.now.to_f, @address, msg.mid) if OmfCommon::Measure.enabled?
|
98
100
|
else
|
99
101
|
warn "Unavailable AMQP channel. Dropping message '#{msg}'"
|
@@ -19,11 +19,11 @@ module OmfCommon
|
|
19
19
|
name = name.to_s.to_sym
|
20
20
|
@@lock.synchronize do
|
21
21
|
unless @@name2inst[name]
|
22
|
-
debug "New topic: #{name}"
|
22
|
+
debug "New topic: #{name} | #{opts[:routing_key]}"
|
23
23
|
#opts[:address] ||= address_for(name)
|
24
24
|
@@name2inst[name] = self.new(name, opts, &block)
|
25
25
|
else
|
26
|
-
debug "Existing topic: #{name}"
|
26
|
+
debug "Existing topic: #{name} | #{@@name2inst[name].routing_key}"
|
27
27
|
block.call(@@name2inst[name]) if block
|
28
28
|
end
|
29
29
|
@@name2inst[name]
|
@@ -34,7 +34,7 @@ module OmfCommon
|
|
34
34
|
@@name2inst[name]
|
35
35
|
end
|
36
36
|
|
37
|
-
attr_reader :id
|
37
|
+
attr_reader :id, :routing_key
|
38
38
|
|
39
39
|
# Request the creation of a new resource. Returns itself
|
40
40
|
#
|
@@ -59,7 +59,7 @@ module OmfCommon
|
|
59
59
|
def inform(type, props = {}, core_props = {}, &block)
|
60
60
|
core_props[:src] ||= OmfCommon.comm.local_address
|
61
61
|
msg = OmfCommon::Message.create(:inform, props, core_props.merge(itype: type))
|
62
|
-
publish(msg, &block)
|
62
|
+
publish(msg, { routing_key: "o.info" }, &block)
|
63
63
|
self
|
64
64
|
end
|
65
65
|
|
@@ -69,20 +69,23 @@ module OmfCommon
|
|
69
69
|
end
|
70
70
|
core_props[:src] ||= OmfCommon.comm.local_address
|
71
71
|
msg = OmfCommon::Message.create(:release, {}, core_props.merge(res_id: resource.id))
|
72
|
-
publish(msg, &block)
|
72
|
+
publish(msg, { routing_key: "o.op" }, &block)
|
73
73
|
self
|
74
74
|
end
|
75
75
|
|
76
|
+
# Only used for create, configure and request
|
76
77
|
def create_message_and_publish(type, props = {}, core_props = {}, block = nil)
|
77
78
|
debug "(#{id}) create_message_and_publish '#{type}': #{props.inspect}: #{core_props.inspect}"
|
78
79
|
core_props[:src] ||= OmfCommon.comm.local_address
|
79
80
|
msg = OmfCommon::Message.create(type, props, core_props)
|
80
|
-
publish(msg, &block)
|
81
|
+
publish(msg, { routing_key: "o.op" }, &block)
|
81
82
|
end
|
82
83
|
|
83
|
-
def publish(msg, &block)
|
84
|
+
def publish(msg, opts = {}, &block)
|
85
|
+
error "!!!" if opts[:routing_key].nil?
|
86
|
+
|
84
87
|
raise "Expected message but got '#{msg.class}" unless msg.is_a?(OmfCommon::Message)
|
85
|
-
_send_message(msg, block)
|
88
|
+
_send_message(msg, opts, block)
|
86
89
|
end
|
87
90
|
|
88
91
|
# TODO we should fix this long list related to INFORM messages
|
@@ -154,7 +157,7 @@ module OmfCommon
|
|
154
157
|
|
155
158
|
# _send_message will also register callbacks for reply messages by default
|
156
159
|
#
|
157
|
-
def _send_message(msg, block = nil)
|
160
|
+
def _send_message(msg, opts = {}, block = nil)
|
158
161
|
if (block)
|
159
162
|
# register callback for responses to 'mid'
|
160
163
|
debug "(#{id}) register callback for responses to 'mid: #{msg.mid}'"
|