manageiq-messaging 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +47 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_cc.yml +5 -0
- data/.rubocop_local.yml +2 -0
- data/.travis.yml +10 -0
- data/CHANGES +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +171 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples/README.md +16 -0
- data/examples/background_job.rb +36 -0
- data/examples/common.rb +40 -0
- data/examples/message.rb +42 -0
- data/lib/manageiq-messaging.rb +1 -0
- data/lib/manageiq/messaging.rb +24 -0
- data/lib/manageiq/messaging/client.rb +205 -0
- data/lib/manageiq/messaging/common.rb +36 -0
- data/lib/manageiq/messaging/kafka.rb +7 -0
- data/lib/manageiq/messaging/kafka/background_job.rb +13 -0
- data/lib/manageiq/messaging/kafka/client.rb +91 -0
- data/lib/manageiq/messaging/kafka/common.rb +105 -0
- data/lib/manageiq/messaging/kafka/queue.rb +41 -0
- data/lib/manageiq/messaging/kafka/topic.rb +28 -0
- data/lib/manageiq/messaging/null_logger.rb +11 -0
- data/lib/manageiq/messaging/received_message.rb +11 -0
- data/lib/manageiq/messaging/stomp.rb +7 -0
- data/lib/manageiq/messaging/stomp/background_job.rb +61 -0
- data/lib/manageiq/messaging/stomp/client.rb +85 -0
- data/lib/manageiq/messaging/stomp/common.rb +84 -0
- data/lib/manageiq/messaging/stomp/queue.rb +53 -0
- data/lib/manageiq/messaging/stomp/topic.rb +37 -0
- data/lib/manageiq/messaging/version.rb +5 -0
- data/manageiq-messaging.gemspec +33 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e14f157513c6d74acad91f2afd7c3ec932e331d6
|
4
|
+
data.tar.gz: b0cd36a056c1cca5a9ea93f484b64b36e1495034
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a07451e8cf57e968a6ad20c5964deca42b5c26392ba22ee52b1586f46ee0f376fc8136eb0ff81093db55e04b6140f4941b07368dedea8ef9c2527709cec45d7
|
7
|
+
data.tar.gz: 19c118466aa8202534457ca03c5760f9f987bd024297490d226a2465e9be7d70d2ac0ab8d18c00b2374305b80481b231884ca0b87b723feb1f4a9af185f8110d
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
exclude_paths:
|
3
|
+
- ".git/"
|
4
|
+
- "**.xml"
|
5
|
+
- "**.yaml"
|
6
|
+
- "**.yml"
|
7
|
+
- "locale/"
|
8
|
+
- "spec/"
|
9
|
+
- "tools/"
|
10
|
+
engines:
|
11
|
+
brakeman:
|
12
|
+
# very slow :sad_panda:
|
13
|
+
enabled: false
|
14
|
+
bundler-audit:
|
15
|
+
# requires Gemfile.lock
|
16
|
+
enabled: false
|
17
|
+
csslint:
|
18
|
+
enabled: false
|
19
|
+
duplication:
|
20
|
+
enabled: true
|
21
|
+
config:
|
22
|
+
languages:
|
23
|
+
- ruby
|
24
|
+
- javascript
|
25
|
+
eslint:
|
26
|
+
enabled: false
|
27
|
+
channel: "eslint-3"
|
28
|
+
fixme:
|
29
|
+
# let's enable later
|
30
|
+
enabled: false
|
31
|
+
markdownlint:
|
32
|
+
# let's enable later
|
33
|
+
enabled: false
|
34
|
+
rubocop:
|
35
|
+
enabled: true
|
36
|
+
config: '.rubocop_cc.yml'
|
37
|
+
prepare:
|
38
|
+
fetch:
|
39
|
+
- url: "https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_base.yml"
|
40
|
+
path: ".rubocop_base.yml"
|
41
|
+
- url: "https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml"
|
42
|
+
path: ".rubocop_cc_base.yml"
|
43
|
+
ratings:
|
44
|
+
paths:
|
45
|
+
- Gemfile.lock
|
46
|
+
- "**.rake"
|
47
|
+
- "**.rb"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_cc.yml
ADDED
data/.rubocop_local.yml
ADDED
data/.travis.yml
ADDED
data/CHANGES
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at bilwei@redhat.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 ManageIQ Authors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
# ManageIQ Messaging Client
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/manageiq-messaging.svg)](http://badge.fury.io/rb/manageiq-messaging)
|
4
|
+
[![Build Status](https://travis-ci.org/ManageIQ/manageiq-messaging.svg)](https://travis-ci.org/ManageIQ/manageiq-messaging)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/ManageIQ/manageiq-messaging.svg)](https://codeclimate.com/github/ManageIQ/manageiq-messaging)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/ManageIQ/manageiq-messaging/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/manageiq-messaging/coverage)
|
7
|
+
[![Dependency Status](https://gemnasium.com/ManageIQ/manageiq-messaging.svg)](https://gemnasium.com/ManageIQ/manageiq-messaging)
|
8
|
+
[![Security](https://hakiri.io/github/ManageIQ/manageiq-messaging/master.svg)](https://hakiri.io/github/ManageIQ/manageiq-messaging/master)
|
9
|
+
|
10
|
+
Client library for ManageIQ components to exchange messages through its internal message bus.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'manageiq-messaging'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install manageiq-messaging
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Initialize a client
|
31
|
+
|
32
|
+
It is not recommended to directly create an actual client through `new` operation. Follow the example by specifying a protocol. This allows to easily switch the underlying messaging system from one type to another. Currently `:Stomp` and `:Kafka` are implemented.
|
33
|
+
|
34
|
+
```
|
35
|
+
ManageIQ::Messaging.logger = Logger.new(STDOUT)
|
36
|
+
|
37
|
+
client = ManageIQ::Messaging::Client.open(
|
38
|
+
:protocol => 'Stomp',
|
39
|
+
:host => 'localhost',
|
40
|
+
:port => 61616,
|
41
|
+
:password => 'smartvm',
|
42
|
+
:username => 'admin',
|
43
|
+
:client_ref => 'generic_1',
|
44
|
+
:encoding => 'json' # default 'yaml'
|
45
|
+
)
|
46
|
+
|
47
|
+
# publish or consume messages using the client
|
48
|
+
|
49
|
+
client.close
|
50
|
+
```
|
51
|
+
|
52
|
+
Alternatively, you can pass a block to `.open` without the need to explicitly close the client.
|
53
|
+
|
54
|
+
```
|
55
|
+
ManageIQ::Messaging::Client.open(
|
56
|
+
:protocol => 'Stomp',
|
57
|
+
:host => 'localhost',
|
58
|
+
:port => 61616,
|
59
|
+
:password => 'smartvm',
|
60
|
+
:username => 'admin',
|
61
|
+
:client_ref => 'generic_1'
|
62
|
+
) do |client|
|
63
|
+
# do stuff with the client
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### Publish and subscribe messages
|
69
|
+
|
70
|
+
This is the one-to-one publish/subscribe pattern. Multiple subscribers can subscribe to the same queue but only one will consume the message. Subscribers are load balanced.
|
71
|
+
|
72
|
+
```
|
73
|
+
client.publish_message(
|
74
|
+
:service => 'ems_operation',
|
75
|
+
:affinity => 'ems_amazon1',
|
76
|
+
:message => 'power_on',
|
77
|
+
:payload => {
|
78
|
+
:ems_ref => 'u987',
|
79
|
+
:id => '123'
|
80
|
+
}
|
81
|
+
)
|
82
|
+
|
83
|
+
client.subscribe_messages(:service => 'ems_operation', :affinity => 'ems_amazon1') do |messages|
|
84
|
+
messages.each do |msg|
|
85
|
+
# do stuff with msg.message and msg.payload
|
86
|
+
client.ack(msg.ack_ref)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# You can create a second client instance and call subscribe_messages with
|
91
|
+
# the same options. Then both clients will take turns to consume the messages.
|
92
|
+
```
|
93
|
+
|
94
|
+
For better sending performance, you can publish a collection of messages together
|
95
|
+
|
96
|
+
```
|
97
|
+
msg1 = {:service => 'ems_inventory', :affinity => 'ems1', :message => 'refresh', :payload => 'vm1'}
|
98
|
+
msg2 = {:service => 'ems_inventory', :affinity => 'ems1', :massage => 'refresh', :payload => 'vm2')
|
99
|
+
client.publish_messages([msg1, msg2])
|
100
|
+
```
|
101
|
+
|
102
|
+
Provide a block if you want `#publish_message` to wait on a response from the subscriber. This feature may not be supported by every underlying messaging system.
|
103
|
+
|
104
|
+
```
|
105
|
+
client.publish_message(
|
106
|
+
:service => 'ems_operation',
|
107
|
+
:affinity => 'ems_amazon1',
|
108
|
+
:message => 'power_on',
|
109
|
+
:payload => {
|
110
|
+
:ems_ref => 'u987',
|
111
|
+
:id => '123'
|
112
|
+
}
|
113
|
+
) do |result|
|
114
|
+
ansible_install_pkg(vm1) if result == 'running'
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
### Publish and subscribe background jobs
|
119
|
+
|
120
|
+
Background Job is a special type of message with a known `class_name` and the subscriber knows how to process the message without a user block
|
121
|
+
|
122
|
+
```
|
123
|
+
client.publish_message(
|
124
|
+
:service => 'generic',
|
125
|
+
:class_name => 'MiqTask',
|
126
|
+
:message => 'update_attributes', # method name
|
127
|
+
:payload => {
|
128
|
+
:instance_id => 2,
|
129
|
+
:args => [{:status => 'Timeout'}]
|
130
|
+
}
|
131
|
+
)
|
132
|
+
|
133
|
+
client.subscribe_background_job(:service => 'generic')
|
134
|
+
```
|
135
|
+
|
136
|
+
Provide a call block if you want `#publish_message` to wait on a response from the subscriber.
|
137
|
+
|
138
|
+
### Publish and subscribe topics (events)
|
139
|
+
|
140
|
+
This is the one-to-many publish/subscribe pattern. Multiple subscribers can subscribe to the same queue and each one will receive the same message.
|
141
|
+
|
142
|
+
```
|
143
|
+
client.publish_topic(
|
144
|
+
:service => 'provider_events',
|
145
|
+
:event => 'powered_on',
|
146
|
+
:sender => 'ems_amazon1', # optional
|
147
|
+
:payload => {
|
148
|
+
:ems_ref => 'uid987',
|
149
|
+
:timestamp => '1501091391'
|
150
|
+
})
|
151
|
+
|
152
|
+
client.subscribe_topic(:service => 'provider_events', :persist_ref => 'automate_1') do |sender, event, payload|
|
153
|
+
# do stuff with event and payload. sender may be nil if not set by the publisher
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
By default, events are delivered to live subscribers only. Some messaging systems support persistence with options.
|
158
|
+
|
159
|
+
## Development
|
160
|
+
|
161
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
162
|
+
|
163
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
164
|
+
|
165
|
+
## Contributing
|
166
|
+
|
167
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ManageIQ/manageiq-messaging. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
168
|
+
|
169
|
+
## License
|
170
|
+
|
171
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "manageiq/messaging"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/examples/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Examples for manageiq-messaging
|
2
|
+
|
3
|
+
|
4
|
+
```bash
|
5
|
+
docker run -d -p 61616:61616 \
|
6
|
+
-e ARTEMIS_USERNAME=admin \
|
7
|
+
-e ARTEMIS_PASSWORD=smartvm \
|
8
|
+
vromero/activemq-artemis
|
9
|
+
```
|
10
|
+
|
11
|
+
|
12
|
+
```bash
|
13
|
+
cd examples
|
14
|
+
bundle exec ruby message.rb
|
15
|
+
bundle exec ruby background_job.rb
|
16
|
+
```
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'manageiq-messaging'
|
4
|
+
require_relative "common"
|
5
|
+
|
6
|
+
Thread::abort_on_exception = true
|
7
|
+
|
8
|
+
class ProducerConsumer < Common
|
9
|
+
SERVICE_NAME = "prodcom"
|
10
|
+
def run
|
11
|
+
ManageIQ::Messaging::Client.open(q_options) do |client|
|
12
|
+
puts "producer"
|
13
|
+
5.times do |i|
|
14
|
+
client.publish_message(:service => SERVICE_NAME,
|
15
|
+
:class_name => self.class.name,
|
16
|
+
:message => 'do_stuff',
|
17
|
+
:payload => {:args=>["hello#{i}"]}
|
18
|
+
)
|
19
|
+
end
|
20
|
+
puts "produced 5 jobs"
|
21
|
+
|
22
|
+
# this could be a different client
|
23
|
+
puts "consumer"
|
24
|
+
client.subscribe_background_job(:service => SERVICE_NAME)
|
25
|
+
|
26
|
+
sleep(5) # wait for consumer to consume all
|
27
|
+
puts "consumed"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.do_stuff(args)
|
32
|
+
puts "GOT MESSAGE: do_stuff(#{args.inspect})"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ProducerConsumer.new.parse.run
|