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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56402b3a8736e2983e711c6521c39e12c5afac32dc431e1fc64c9a608c59cc09
4
- data.tar.gz: cfe1fb310fbf5971c98f69e866d2637e0b3639822bd05dbc8a16a607c0fbd133
3
+ metadata.gz: 64efdc1c23146264a24fb6464a2d72480cacd3db28ebc729394ac511d82dbec4
4
+ data.tar.gz: bb21c6264ee6c05c1d5ea6151f49fe81a156b2f2f9180682a2a14a5597047969
5
5
  SHA512:
6
- metadata.gz: d107b4468ef6e1b6a37a6a2ab3b294c2fa6f2a6482949bec3b01cc38aa75f8cc4ccf95eeb7e0a22802afcf0e8158dc4cb68de0ea26b22713c520febd8457b1be
7
- data.tar.gz: 0fd07ec8805d22ac6cdfef59f58b5e30393e011e822a534f6f6e2159104aa7cba28f1403e1b78872f4f73e5a506e466c25d061318510090bd8fc836345cb8c85
6
+ metadata.gz: 6f8823df33b9cf386e2ff0188e6df0aa1a28bfb90b6b81b6e6112cc1249429cbc2548601ebf81e2970635535fb4c81b76559e203210b4a97d7a4c6513dad84a8
7
+ data.tar.gz: 93ec75aa96126b9938318f107e0b789aa5a02f557137668d563506abf24e3d78af333f334318ea114e2bfcc4e1ebdfe9a2659f5d81319a914b9c31a476ad87e4
data/.codeclimate.yml CHANGED
@@ -1,18 +1,21 @@
1
- ---
2
- exclude_paths:
3
- - ".git/"
4
- - "**.xml"
5
- - "**.yaml"
6
- - "**.yml"
7
- - "locale/"
8
- - "spec/"
9
- - "tools/"
10
- engines:
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: "eslint-3"
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
- rubocop:
35
- enabled: true
36
- config: '.rubocop_cc.yml'
37
- channel: 'rubocop-0-69'
38
- prepare:
39
- fetch:
40
- - url: "https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml"
41
- path: ".rubocop_base.yml"
42
- - url: "https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml"
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
@@ -1,5 +1,4 @@
1
1
  inherit_gem:
2
- manageiq-style: .rubocop_base.yml
2
+ manageiq-style: ".rubocop_base.yml"
3
3
  inherit_from:
4
- # put all local rubocop config into .rubocop_local.yml as it will be loaded by .rubocop_cc.yml as well
5
- - .rubocop_local.yml
4
+ - ".rubocop_local.yml"
data/.rubocop_cc.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  inherit_from:
2
- # this is downloaded by .codeclimate.yml
3
- - .rubocop_base.yml
4
- - .rubocop_cc_base.yml
5
- - .rubocop_local.yml
2
+ - ".rubocop_base.yml"
3
+ - ".rubocop_cc_base.yml"
4
+ - ".rubocop_local.yml"
data/CHANGES CHANGED
@@ -28,3 +28,6 @@
28
28
 
29
29
  = 1.0.2 - 4-Jan-2021
30
30
  * Rails 6.0 Support
31
+
32
+ = 1.0.3 - 12-May-2021
33
+ * Allow bulk publish of messages to a topic
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
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/array/wrap'
1
2
  require 'active_support/core_ext/module/delegation'
2
3
  require 'active_support/core_ext/hash'
3
4
  require 'yaml'
@@ -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
- # Expected keys in +options+ are:
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(options)
173
- assert_options(options, [:event, :service])
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(options)
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(connection_opts)
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(wait, body, options)
24
+ def raw_publish(body, options)
25
25
  options[:payload] = encode_body(options[:headers], body)
26
- producer.produce(options).tap do |handle|
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(true, *queue_for_publish(options))
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(false, *queue_for_publish(msg_options)) }
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(options)
12
- raw_publish(true, *topic_for_publish(options))
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 publish_topic_impl(options)
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
 
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module Messaging
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
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.2
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-01-04 00:00:00.000000000 Z
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.0.rc.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