manageiq-messaging 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +25 -30
- data/.rubocop.yml +2 -3
- data/.rubocop_cc.yml +3 -4
- data/CHANGES +3 -0
- data/README.md +13 -0
- data/lib/manageiq/messaging.rb +1 -0
- data/lib/manageiq/messaging/client.rb +6 -4
- data/lib/manageiq/messaging/kafka/client.rb +13 -8
- data/lib/manageiq/messaging/kafka/common.rb +2 -5
- data/lib/manageiq/messaging/kafka/queue.rb +2 -2
- data/lib/manageiq/messaging/kafka/topic.rb +3 -2
- data/lib/manageiq/messaging/stomp/topic.rb +5 -1
- data/lib/manageiq/messaging/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64efdc1c23146264a24fb6464a2d72480cacd3db28ebc729394ac511d82dbec4
|
4
|
+
data.tar.gz: bb21c6264ee6c05c1d5ea6151f49fe81a156b2f2f9180682a2a14a5597047969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f8823df33b9cf386e2ff0188e6df0aa1a28bfb90b6b81b6e6112cc1249429cbc2548601ebf81e2970635535fb4c81b76559e203210b4a97d7a4c6513dad84a8
|
7
|
+
data.tar.gz: 93ec75aa96126b9938318f107e0b789aa5a02f557137668d563506abf24e3d78af333f334318ea114e2bfcc4e1ebdfe9a2659f5d81319a914b9c31a476ad87e4
|
data/.codeclimate.yml
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
-
|
4
|
-
|
5
|
-
-
|
6
|
-
|
7
|
-
-
|
8
|
-
|
9
|
-
-
|
10
|
-
|
1
|
+
prepare:
|
2
|
+
fetch:
|
3
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
|
4
|
+
path: ".rubocop_base.yml"
|
5
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
|
6
|
+
path: ".rubocop_cc_base.yml"
|
7
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
|
8
|
+
path: styles/base.yml
|
9
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
|
10
|
+
path: styles/cc_base.yml
|
11
|
+
plugins:
|
12
|
+
rubocop:
|
13
|
+
enabled: true
|
14
|
+
config: ".rubocop_cc.yml"
|
15
|
+
channel: rubocop-0-82
|
11
16
|
brakeman:
|
12
|
-
# very slow :sad_panda:
|
13
17
|
enabled: false
|
14
18
|
bundler-audit:
|
15
|
-
# requires Gemfile.lock
|
16
19
|
enabled: false
|
17
20
|
csslint:
|
18
21
|
enabled: false
|
@@ -24,25 +27,17 @@ engines:
|
|
24
27
|
- javascript
|
25
28
|
eslint:
|
26
29
|
enabled: false
|
27
|
-
channel:
|
30
|
+
channel: eslint-3
|
28
31
|
fixme:
|
29
|
-
# let's enable later
|
30
32
|
enabled: false
|
31
33
|
markdownlint:
|
32
|
-
# let's enable later
|
33
34
|
enabled: false
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
path: ".rubocop_cc_base.yml"
|
44
|
-
ratings:
|
45
|
-
paths:
|
46
|
-
- Gemfile.lock
|
47
|
-
- "**.rake"
|
48
|
-
- "**.rb"
|
35
|
+
exclude_patterns:
|
36
|
+
- ".git/"
|
37
|
+
- "**.xml"
|
38
|
+
- "**.yaml"
|
39
|
+
- "**.yml"
|
40
|
+
- locale/
|
41
|
+
- spec/
|
42
|
+
- tools/
|
43
|
+
version: '2'
|
data/.rubocop.yml
CHANGED
data/.rubocop_cc.yml
CHANGED
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -155,6 +155,19 @@ This is the one-to-many publish/subscribe pattern. Multiple subscribers can subs
|
|
155
155
|
|
156
156
|
By default, events are delivered to live subscribers only. Some messaging systems support persistence with options.
|
157
157
|
|
158
|
+
### Publish bulk messages to a topic
|
159
|
+
|
160
|
+
Often it is more efficient to publish messages in bulk rather than one-at-a-time. To do this you can pass an array of messages to the `publish_topic` API:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
client.publish_topic(
|
164
|
+
[
|
165
|
+
{:service => 'provider_events', :event => 'powered_off', :payload => {:ems_ref => 'uid987', :timestamp => '1501091391'}},
|
166
|
+
{:service => 'provider_events', :event => 'powered_on', :payload => {:ems_ref => 'uid987', :timestamp => '1501091429'}},
|
167
|
+
]
|
168
|
+
)
|
169
|
+
```
|
170
|
+
|
158
171
|
### Add your own headers to a message (Queue or Topic)
|
159
172
|
|
160
173
|
If you want you can add in your own headers to the send message
|
data/lib/manageiq/messaging.rb
CHANGED
@@ -161,7 +161,8 @@ module ManageIQ
|
|
161
161
|
end
|
162
162
|
|
163
163
|
# Publish a message as a topic. All subscribers will receive a copy of the message.
|
164
|
-
#
|
164
|
+
# +messages+ can be either a hash or an array of hashes.
|
165
|
+
# Expected keys are:
|
165
166
|
# * :service (service is used to determine the topic address)
|
166
167
|
# * :event (event name)
|
167
168
|
# * :payload (message body, a string or an user object that can be serialized)
|
@@ -169,10 +170,11 @@ module ManageIQ
|
|
169
170
|
# * :headers (optional, additional headers to add to the message)
|
170
171
|
# Other options are underlying messaging system specific.
|
171
172
|
#
|
172
|
-
def publish_topic(
|
173
|
-
|
173
|
+
def publish_topic(messages)
|
174
|
+
messages = Array.wrap(messages)
|
175
|
+
messages.each { |msg| assert_options(msg, [:event, :service]) }
|
174
176
|
|
175
|
-
publish_topic_impl(
|
177
|
+
publish_topic_impl(messages)
|
176
178
|
end
|
177
179
|
|
178
180
|
# Subscribe to receive topic type messages.
|
@@ -76,18 +76,23 @@ module ManageIQ
|
|
76
76
|
attr_reader :kafka_client
|
77
77
|
|
78
78
|
def initialize(options)
|
79
|
-
hosts = Array(options[:hosts] || options[:host])
|
80
|
-
hosts.collect! { |host| "#{host}:#{options[:port]}" }
|
81
|
-
|
82
79
|
@encoding = options[:encoding] || 'yaml'
|
83
80
|
require "json" if @encoding == "json"
|
84
81
|
|
85
|
-
connection_opts = {:"bootstrap.servers" => hosts.join(',')}
|
86
|
-
connection_opts[:"client.id"] = options[:client_ref] if options[:client_ref]
|
87
|
-
connection_opts.merge!(options.except(:port, :host, :hosts, :encoding, :protocol, :client_ref))
|
88
|
-
|
89
82
|
::Rdkafka::Config.logger = logger
|
90
|
-
@kafka_client = ::Rdkafka::Config.new(
|
83
|
+
@kafka_client = ::Rdkafka::Config.new(rdkafka_connection_opts(options))
|
84
|
+
end
|
85
|
+
|
86
|
+
def rdkafka_connection_opts(options)
|
87
|
+
hosts = Array(options[:hosts] || options[:host])
|
88
|
+
hosts.collect! { |host| "#{host}:#{options[:port]}" }
|
89
|
+
|
90
|
+
result = {:"bootstrap.servers" => hosts.join(',')}
|
91
|
+
result[:"client.id"] = options[:client_ref] if options[:client_ref]
|
92
|
+
result[:"sasl.username"] = options[:username] if options[:username]
|
93
|
+
result[:"sasl.password"] = options[:password] if options[:password]
|
94
|
+
|
95
|
+
result.merge(options.except(:port, :host, :hosts, :encoding, :protocol, :client_ref, :username, :password))
|
91
96
|
end
|
92
97
|
end
|
93
98
|
end
|
@@ -21,12 +21,9 @@ module ManageIQ
|
|
21
21
|
@consumer = kafka_client.consumer
|
22
22
|
end
|
23
23
|
|
24
|
-
def raw_publish(
|
24
|
+
def raw_publish(body, options)
|
25
25
|
options[:payload] = encode_body(options[:headers], body)
|
26
|
-
producer.produce(options)
|
27
|
-
handle.wait if wait
|
28
|
-
logger.info("Published to topic(#{options[:topic]}), msg(#{payload_log(body.inspect)})")
|
29
|
-
end
|
26
|
+
producer.produce(options)
|
30
27
|
end
|
31
28
|
|
32
29
|
def queue_for_publish(options)
|
@@ -8,11 +8,11 @@ module ManageIQ
|
|
8
8
|
|
9
9
|
def publish_message_impl(options)
|
10
10
|
raise ArgumentError, "Kafka messaging implementation does not take a block" if block_given?
|
11
|
-
raw_publish(
|
11
|
+
raw_publish(*queue_for_publish(options)).wait
|
12
12
|
end
|
13
13
|
|
14
14
|
def publish_messages_impl(messages)
|
15
|
-
handles = messages.collect { |msg_options| raw_publish(
|
15
|
+
handles = messages.collect { |msg_options| raw_publish(*queue_for_publish(msg_options)) }
|
16
16
|
handles.each(&:wait)
|
17
17
|
end
|
18
18
|
|
@@ -8,8 +8,9 @@ module ManageIQ
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def publish_topic_impl(
|
12
|
-
raw_publish(
|
11
|
+
def publish_topic_impl(messages)
|
12
|
+
handles = messages.collect { |message| raw_publish(*topic_for_publish(message)) }
|
13
|
+
handles.each(&:wait)
|
13
14
|
end
|
14
15
|
|
15
16
|
def subscribe_topic_impl(options, &block)
|
@@ -4,7 +4,7 @@ module ManageIQ
|
|
4
4
|
module Topic
|
5
5
|
private
|
6
6
|
|
7
|
-
def
|
7
|
+
def publish_topic_single(options)
|
8
8
|
address, headers = topic_for_publish(options)
|
9
9
|
headers[:sender] = options[:sender] if options[:sender]
|
10
10
|
headers[:event_type] = options[:event] if options[:event]
|
@@ -12,6 +12,10 @@ module ManageIQ
|
|
12
12
|
raw_publish(address, options[:payload], headers)
|
13
13
|
end
|
14
14
|
|
15
|
+
def publish_topic_impl(messages)
|
16
|
+
messages.each { |message| publish_topic_single(message) }
|
17
|
+
end
|
18
|
+
|
15
19
|
def subscribe_topic_impl(options)
|
16
20
|
queue_name, headers = topic_for_subscribe(options)
|
17
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manageiq-messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ManageIQ Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
209
|
requirements: []
|
210
|
-
rubygems_version: 3.2.
|
210
|
+
rubygems_version: 3.2.5
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: Client library for ManageIQ components to exchange messages through its internal
|