event_people 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile.lock +2 -1
- data/README.md +10 -10
- data/bin/setup +8 -0
- data/examples/listener.rb +6 -1
- data/lib/event_people/broker/rabbit/queue.rb +2 -1
- data/lib/event_people/broker/rabbit.rb +1 -3
- data/lib/event_people/event.rb +1 -1
- data/lib/event_people/listeners/base.rb +25 -14
- data/lib/event_people/listeners/manager.rb +2 -2
- data/lib/event_people/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fe37c13b973b908692331742769cfe80e9275fd9b00c10f8ce1754caed401dd
|
4
|
+
data.tar.gz: 0bd35eac8aa30ac949d335e93d9ddc4e85d691561727c8b215d1780c34fd0c31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f47f4f894349f3d551cca37b555d295ced7413407242cf5ad6c9a9ec7ef1e0438498a7450026b4515d7561b1454c930c8c36d68f359a27beccd369b730d61b6c
|
7
|
+
data.tar.gz: 7723659cc5cb3774f2d01c0217a1da4a3de1b2e9d83bd39d30884af351bf8b223e378c37580f84c16b0602ef14e2cb52637848b209fcd1245fe9e748c803bb81
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
|
5
5
|
EventPeople is a tool to simplify the communication of services based on events. It is an extension of the [EventBus](https://github.com/EmpregoLigado/event_bus_rb) gem.
|
6
6
|
|
7
|
-
The main idea is to provide a tool that can emit or consume events based on its names, the event name has 4 words (`resource.origin.action.
|
7
|
+
The main idea is to provide a tool that can emit or consume events based on its names, the event name has 4 words (`resource.origin.action.destination`) which defines some important info about what kind of event it is, where it comes from and who is eligible to consume it:
|
8
8
|
|
9
9
|
- **resource:** Defines which resource this event is related like a `user`, a `product`, `company` or anything that you want;
|
10
10
|
- **origin:** Defines the name of the system which emitted the event;
|
11
|
-
- **action:** What action is made on the resource like `create`, `delete`, `update`, etc. PS: *It is recommended to use the
|
12
|
-
- **
|
11
|
+
- **action:** What action is made on the resource like `create`, `delete`, `update`, etc. PS: *It is recommended to use the Simple Present tense for actions*;
|
12
|
+
- **destination (Optional):** This word is optional and if not provided EventPeople will add a `.all` to the end of the event name. It defines which service should consume the event being emitted, so if it is defined and there is a service whith the given name only this service will receive it. It is very helpful when you need to re-emit some events. Also if it is `.all` all services will receive it.
|
13
13
|
|
14
14
|
As of today EventPeople uses RabbitMQ as its datasource, but there are plans to add support for other Brokers in the future.
|
15
15
|
|
@@ -45,7 +45,7 @@ The main component of `EventPeople` is the `EventPeople::Event` class which wrap
|
|
45
45
|
|
46
46
|
It has 2 attributes `name` and `payload`:
|
47
47
|
|
48
|
-
- **name:** The name must follow our conventions, being it 3 (`resource.origin.action`) or 4 words (`resource.origin.action.
|
48
|
+
- **name:** The name must follow our conventions, being it 3 (`resource.origin.action`) or 4 words (`resource.origin.action.destination`);
|
49
49
|
- **payload:** It is the body of the massage, it should be a Hash object for simplicity and flexibility.
|
50
50
|
|
51
51
|
```ruby
|
@@ -103,12 +103,12 @@ require 'event_people'
|
|
103
103
|
# counterpart: 'payment.payments.pay.all'
|
104
104
|
event_name = 'payment.payments.pay'
|
105
105
|
|
106
|
-
EventPeople::Listener.on(event_name) do |event,
|
106
|
+
EventPeople::Listener.on(event_name) do |event, context|
|
107
107
|
puts ""
|
108
108
|
puts " - Received the "#{event.name}" message from #{event.origin}:"
|
109
109
|
puts " Message: #{event.body}"
|
110
110
|
puts ""
|
111
|
-
success!
|
111
|
+
context.success!
|
112
112
|
end
|
113
113
|
|
114
114
|
EventPeople::Config.broker.close_connection
|
@@ -125,13 +125,13 @@ has_events = true
|
|
125
125
|
while has_events do
|
126
126
|
has_events = false
|
127
127
|
|
128
|
-
EventPeople::Listener.on(event_name) do |event,
|
128
|
+
EventPeople::Listener.on(event_name) do |event, context|
|
129
129
|
has_events = true
|
130
130
|
puts ""
|
131
131
|
puts " - Received the "#{event.name}" message from #{event.origin}:"
|
132
132
|
puts " Message: #{event.body}"
|
133
133
|
puts ""
|
134
|
-
success!
|
134
|
+
context.success!
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
@@ -224,7 +224,7 @@ EventPeople::Daemon.start
|
|
224
224
|
|
225
225
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
226
226
|
|
227
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
227
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
228
228
|
|
229
229
|
## Contributing
|
230
230
|
|
@@ -236,4 +236,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
236
236
|
|
237
237
|
## License
|
238
238
|
|
239
|
-
The gem is available as open source under the terms of the [
|
239
|
+
The gem is available as open source under the terms of the [LGPL 3.0 License](https://www.gnu.org/licenses/lgpl-3.0.en.html).
|
data/bin/setup
ADDED
data/examples/listener.rb
CHANGED
@@ -17,13 +17,18 @@ event_name = 'resource.origin.action'
|
|
17
17
|
|
18
18
|
puts 'Start receiving messages'
|
19
19
|
|
20
|
-
EventPeople::Listener.on(event_name) do |event|
|
20
|
+
EventPeople::Listener.on(event_name) do |event, context|
|
21
21
|
puts ''
|
22
22
|
puts " - Received a message from #{event.name}:"
|
23
23
|
puts " Message: #{event.body}"
|
24
24
|
puts ''
|
25
|
+
|
26
|
+
context.success!
|
25
27
|
end
|
26
28
|
|
29
|
+
# Wait for job to finish!
|
30
|
+
sleep(0.5)
|
31
|
+
|
27
32
|
puts 'Stop receiving messages'
|
28
33
|
|
29
34
|
EventPeople::Config.broker.close_connection
|
@@ -29,8 +29,9 @@ module EventPeople
|
|
29
29
|
event_name = delivery_info.routing_key
|
30
30
|
|
31
31
|
event = EventPeople::Event.new(event_name, payload)
|
32
|
+
context = EventPeople::Listeners::Base.new(channel, delivery_info)
|
32
33
|
|
33
|
-
block.call(event,
|
34
|
+
block.call(event, context)
|
34
35
|
end
|
35
36
|
|
36
37
|
def topic
|
data/lib/event_people/event.rb
CHANGED
@@ -26,21 +26,32 @@ module EventPeople
|
|
26
26
|
|
27
27
|
def self.bind(method, event_name)
|
28
28
|
app_name = ENV['RABBIT_EVENT_PEOPLE_APP_NAME'].downcase
|
29
|
+
splitted_event_name = event_name.split('.')
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
31
|
+
if splitted_event_name.size == 3
|
32
|
+
Manager.register_listener_configuration(
|
33
|
+
{
|
34
|
+
listener_class: self,
|
35
|
+
method:,
|
36
|
+
routing_key: fixed_event_name(event_name, 'all')
|
37
|
+
}
|
38
|
+
)
|
39
|
+
Manager.register_listener_configuration(
|
40
|
+
{
|
41
|
+
listener_class: self,
|
42
|
+
method:,
|
43
|
+
routing_key: fixed_event_name(event_name, app_name)
|
44
|
+
}
|
45
|
+
)
|
46
|
+
else
|
47
|
+
Manager.register_listener_configuration(
|
48
|
+
{
|
49
|
+
listener_class: self,
|
50
|
+
method:,
|
51
|
+
routing_key: event_name
|
52
|
+
}
|
53
|
+
)
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
def self.fixed_event_name(event_name, postfix)
|
@@ -5,8 +5,8 @@ module EventPeople
|
|
5
5
|
class << self
|
6
6
|
def bind_all_listeners
|
7
7
|
listener_configurations.each do |config|
|
8
|
-
EventPeople::Listener.on(config[:routing_key]) do |event,
|
9
|
-
config[:listener_class].new(channel, delivery_info).callback(config[:method], event)
|
8
|
+
EventPeople::Listener.on(config[:routing_key]) do |event, context|
|
9
|
+
config[:listener_class].new(context.channel, context.delivery_info).callback(config[:method], event)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/event_people/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_people
|
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
|
- Pin People
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- LICENSE.txt
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
|
+
- bin/setup
|
100
101
|
- event_people.gemspec
|
101
102
|
- examples/daemon.rb
|
102
103
|
- examples/emitter.rb
|