manageiq-messaging 1.0.0 → 1.1.0

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: aa6536d137d3873d7b73cecfc02add52d949bf4c240846b9df4c0a46b02be560
4
- data.tar.gz: 240ffe6f8dacc50a80759335f4d748dc826675cf38e0567117809582580489a0
3
+ metadata.gz: 7dd9c250d5717fe5eff8c8d84483a3b6ee4286026584beffa2a9f2491b968901
4
+ data.tar.gz: 12560dc540325e6681757934f5842497e19890c5c55747f5a06b3265591e8fa1
5
5
  SHA512:
6
- metadata.gz: 45b6e6592e772ffc7373489116a72403d5b6fb2a2e322b4d5d6c629ee6eddd575c3eaf1e7d92afe504b361eaaaa46047e0d85b8ed640272d41098b5d185d8a45
7
- data.tar.gz: e95db7f79892be46eb800e4f241b932282cdebf2f4ffb30a65bfea8a85f24161b9fdc5afbca4d182170aa7fb33f85edcf59881b51a8be80db868bf65bbf6da5b
6
+ metadata.gz: a46c52b888a699c483c81c19a9e1287b8dbde9a2aa3e4f7c30b220775a398b81d9fc7ea6b846b66c186ed1a83461395898bf010412e23427b8e271b7c73f349d
7
+ data.tar.gz: 2a5ae4e0b8ef60fd8f3d18c132719a91a2a9d0c940c01f241e1e30555d993e3b609c966895e0b135e17534d74e9f1680bd3e244d3689471b36d1a50af46ef07a
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,4 +1,4 @@
1
+ inherit_gem:
2
+ manageiq-style: ".rubocop_base.yml"
1
3
  inherit_from:
2
- - https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml
3
- # put all local rubocop config into .rubocop_local.yml as it will be loaded by .rubocop_cc.yml as well
4
- - .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/.travis.yml CHANGED
@@ -1,10 +1,11 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.4.5
5
- - 2.5.7
6
- - 2.6.5
3
+ - 2.6.9
4
+ - 2.7.5
7
5
  before_install: gem install bundler -v 1.13.0
8
6
  after_script: bundle exec codeclimate-test-reporter
9
- sudo: false
10
7
  cache: bundler
8
+ env:
9
+ matrix:
10
+ - TEST_RAILS_VERSION=6.1
11
+ - TEST_RAILS_VERSION=6.0
data/.whitesource ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "settingsInheritedFrom": "ManageIQ/whitesource-config@master"
3
+ }
data/CHANGES CHANGED
@@ -20,3 +20,17 @@
20
20
 
21
21
  = 1.0.0 - 28-Sep-2020
22
22
  * Switch to use rdkafka client
23
+
24
+ = 1.0.1 - 15-Dec-2020
25
+ * Allow all kafka options to be passed
26
+ * remove sudo:false from .travis.yml
27
+ * Use manageiq-style
28
+
29
+ = 1.0.2 - 4-Jan-2021
30
+ * Rails 6.0 Support
31
+
32
+ = 1.0.3 - 12-May-2021
33
+ * Allow bulk publish of messages to a topic
34
+
35
+ = 1.1.0 - 09-Feb-2022
36
+ * Allow rails 6.1
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in manageiq-messaging.gemspec
4
4
  gemspec
5
+
6
+ case ENV['TEST_RAILS_VERSION']
7
+ when "6.0"
8
+ gem "activesupport", "~>6.0.4"
9
+ when "6.1"
10
+ gem "activesupport", "~>6.1.4"
11
+ end
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  [![Build Status](https://travis-ci.com/ManageIQ/manageiq-messaging.svg)](https://travis-ci.com/ManageIQ/manageiq-messaging)
5
5
  [![Code Climate](https://codeclimate.com/github/ManageIQ/manageiq-messaging.svg)](https://codeclimate.com/github/ManageIQ/manageiq-messaging)
6
6
  [![Test Coverage](https://codeclimate.com/github/ManageIQ/manageiq-messaging/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/manageiq-messaging/coverage)
7
- [![Security](https://hakiri.io/github/ManageIQ/manageiq-messaging/master.svg)](https://hakiri.io/github/ManageIQ/manageiq-messaging/master)
8
7
 
9
8
  Client library for ManageIQ components to exchange messages through its internal message bus.
10
9
 
@@ -155,6 +154,19 @@ This is the one-to-many publish/subscribe pattern. Multiple subscribers can subs
155
154
 
156
155
  By default, events are delivered to live subscribers only. Some messaging systems support persistence with options.
157
156
 
157
+ ### Publish bulk messages to a topic
158
+
159
+ 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:
160
+
161
+ ```ruby
162
+ client.publish_topic(
163
+ [
164
+ {:service => 'provider_events', :event => 'powered_off', :payload => {:ems_ref => 'uid987', :timestamp => '1501091391'}},
165
+ {:service => 'provider_events', :event => 'powered_on', :payload => {:ems_ref => 'uid987', :timestamp => '1501091429'}},
166
+ ]
167
+ )
168
+ ```
169
+
158
170
  ### Add your own headers to a message (Queue or Topic)
159
171
 
160
172
  If you want you can add in your own headers to the send message
@@ -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,17 +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
-
88
82
  ::Rdkafka::Config.logger = logger
89
- @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))
90
96
  end
91
97
  end
92
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.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -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'
@@ -21,15 +21,14 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency 'activesupport', '~> 5.2.4.3'
24
+ spec.add_dependency 'activesupport', '>= 5.2.4.3', "< 7.0"
25
25
  spec.add_dependency 'rdkafka', '~> 0.8'
26
26
  spec.add_dependency 'stomp', '~> 1.4.4'
27
27
 
28
28
  spec.add_development_dependency "bundler"
29
29
  spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
30
+ spec.add_development_dependency "manageiq-style"
30
31
  spec.add_development_dependency "rake", ">= 12.3.3"
31
32
  spec.add_development_dependency "rspec", "~> 3.0"
32
- spec.add_development_dependency "rubocop"
33
- spec.add_development_dependency "rubocop-performance"
34
33
  spec.add_development_dependency "simplecov"
35
34
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-29 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 5.2.4.3
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 5.2.4.3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rdkafka
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -81,61 +87,47 @@ dependencies:
81
87
  - !ruby/object:Gem::Version
82
88
  version: 1.0.0
83
89
  - !ruby/object:Gem::Dependency
84
- name: rake
90
+ name: manageiq-style
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - ">="
88
94
  - !ruby/object:Gem::Version
89
- version: 12.3.3
95
+ version: '0'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - ">="
95
101
  - !ruby/object:Gem::Version
96
- version: 12.3.3
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.0'
102
+ version: '0'
111
103
  - !ruby/object:Gem::Dependency
112
- name: rubocop
104
+ name: rake
113
105
  requirement: !ruby/object:Gem::Requirement
114
106
  requirements:
115
107
  - - ">="
116
108
  - !ruby/object:Gem::Version
117
- version: '0'
109
+ version: 12.3.3
118
110
  type: :development
119
111
  prerelease: false
120
112
  version_requirements: !ruby/object:Gem::Requirement
121
113
  requirements:
122
114
  - - ">="
123
115
  - !ruby/object:Gem::Version
124
- version: '0'
116
+ version: 12.3.3
125
117
  - !ruby/object:Gem::Dependency
126
- name: rubocop-performance
118
+ name: rspec
127
119
  requirement: !ruby/object:Gem::Requirement
128
120
  requirements:
129
- - - ">="
121
+ - - "~>"
130
122
  - !ruby/object:Gem::Version
131
- version: '0'
123
+ version: '3.0'
132
124
  type: :development
133
125
  prerelease: false
134
126
  version_requirements: !ruby/object:Gem::Requirement
135
127
  requirements:
136
- - - ">="
128
+ - - "~>"
137
129
  - !ruby/object:Gem::Version
138
- version: '0'
130
+ version: '3.0'
139
131
  - !ruby/object:Gem::Dependency
140
132
  name: simplecov
141
133
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +144,7 @@ dependencies:
152
144
  version: '0'
153
145
  description: Client library for ManageIQ components to exchange messages through its
154
146
  internal message bus.
155
- email:
147
+ email:
156
148
  executables: []
157
149
  extensions: []
158
150
  extra_rdoc_files: []
@@ -164,6 +156,7 @@ files:
164
156
  - ".rubocop_cc.yml"
165
157
  - ".rubocop_local.yml"
166
158
  - ".travis.yml"
159
+ - ".whitesource"
167
160
  - CHANGES
168
161
  - CODE_OF_CONDUCT.md
169
162
  - Gemfile
@@ -200,7 +193,7 @@ homepage: http://github.com/ManageIQ/manageiq-messaging
200
193
  licenses:
201
194
  - MIT
202
195
  metadata: {}
203
- post_install_message:
196
+ post_install_message:
204
197
  rdoc_options: []
205
198
  require_paths:
206
199
  - lib
@@ -215,8 +208,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
208
  - !ruby/object:Gem::Version
216
209
  version: '0'
217
210
  requirements: []
218
- rubygems_version: 3.1.3
219
- signing_key:
211
+ rubygems_version: 3.3.5
212
+ signing_key:
220
213
  specification_version: 4
221
214
  summary: Client library for ManageIQ components to exchange messages through its internal
222
215
  message bus.