event_people 1.0.2 → 1.0.4

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: 2edc78cae5809676875057845aa4646b5b7c2cf10b2c0cd19a3db4303c20ed6d
4
- data.tar.gz: f02920c4bcc5fa8851677050e33ad91fe09a647f598ae6bb5b955e0a72bafcf6
3
+ metadata.gz: c7f58e0e92901db867e0a3a1e74a7019bf25d62fda4d9e6506f1722b4c6c6594
4
+ data.tar.gz: 6d79d5a555bbb697e4a94f58e1fc0c9cd8e474f5214237d6e2c160ead786bc73
5
5
  SHA512:
6
- metadata.gz: 38b52078fbdf1dc410aba893b0269dc39bdfef91a651975100c3ec0d236e2dace74b3bda66e9d0fa9f9c0a8287cddeb0c369afe32c65a94fb00384acc41282cf
7
- data.tar.gz: ebf453a791a7184943d92157b8bf693712e94f4fb40146cf3db4f76e10c4b35e0cf9b1de03cfe20619076226c4a3e5b546865c3d6bb2a53d5e49c386d263268e
6
+ metadata.gz: ef16aeb1e9544b762663d1fa70a689bda225400560061f4db7c8a71cd83fd84f481c0c286d1f020d6fda8b28b67383ed8afb5367849e339172ab31d45a7645a6
7
+ data.tar.gz: 9ef63b463f16b335c71e6130745e3337bb7240a59931f38e5fbeeaf8d9071d3fa90411882233c4e86ad1305ac7b68a7b1e60d2ba77e307af65000a8e54bd5d1d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- event_people (1.0.2)
4
+ event_people (1.0.4)
5
5
  bunny (~> 2.7)
6
6
 
7
7
  GEM
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.destiny`) which defines some important info about what kind of event it is, where it comes from and who is eligible to consume it:
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 Semple Present tense for actions*;
12
- - **destiny (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.
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.destiny`);
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, _delivery_info|
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, _delivery_info|
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
 
@@ -0,0 +1,17 @@
1
+ module EventPeople
2
+ module Broker
3
+ class Context
4
+ def success!
5
+ raise NotImplementedError.new('Must be implemented')
6
+ end
7
+
8
+ def fail!
9
+ raise NotImplementedError.new('Must be implemented')
10
+ end
11
+
12
+ def reject!
13
+ raise NotImplementedError.new('Must be implemented')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -29,7 +29,7 @@ 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
+ context = EventPeople::Broker::Rabbit::RabbitContext.new(channel, delivery_info)
33
33
 
34
34
  block.call(event, context)
35
35
  end
@@ -0,0 +1,22 @@
1
+ module EventPeople
2
+ module Broker
3
+ class Rabbit::RabbitContext < EventPeople::Broker::Context
4
+ def initialize(channel, delivery_info)
5
+ @channel = channel
6
+ @delivery_info = delivery_info
7
+ end
8
+
9
+ def success!
10
+ @channel.ack(@delivery_info.delivery_tag, false)
11
+ end
12
+
13
+ def fail!
14
+ @channel.nack(@delivery_info.delivery_tag, false, true)
15
+ end
16
+
17
+ def reject!
18
+ @channel.reject(@delivery_info.delivery_tag, false)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -28,9 +28,7 @@ module EventPeople
28
28
  end
29
29
 
30
30
  def session
31
- Bunny.new(url).tap do |session|
32
- session.start
33
- end
31
+ Bunny.new(url).tap(&:start)
34
32
  end
35
33
 
36
34
  def url
@@ -42,7 +42,7 @@ module EventPeople
42
42
  resource: header_spec[0],
43
43
  origin: header_spec[1],
44
44
  action: header_spec[2],
45
- destiny: header_spec[3] || 'all',
45
+ destination: header_spec[3] || 'all',
46
46
  schemaVersion: schema_version
47
47
  }
48
48
  end
@@ -1,11 +1,8 @@
1
1
  module EventPeople
2
2
  module Listeners
3
3
  class Base
4
- attr_reader :channel, :delivery_info
5
-
6
- def initialize(channel, delivery_info)
7
- @channel = channel
8
- @delivery_info = delivery_info
4
+ def initialize(context)
5
+ @context = context
9
6
  end
10
7
 
11
8
  def callback(method_name, event)
@@ -13,34 +10,45 @@ module EventPeople
13
10
  end
14
11
 
15
12
  def success!
16
- channel.ack(delivery_info.delivery_tag, false)
13
+ @context.success!
17
14
  end
18
15
 
19
16
  def fail!
20
- channel.nack(delivery_info.delivery_tag, false, true)
17
+ @context.fail!
21
18
  end
22
19
 
23
20
  def reject!
24
- channel.reject(delivery_info.delivery_tag, false)
21
+ @context.reject!
25
22
  end
26
23
 
27
24
  def self.bind(method, event_name)
28
25
  app_name = ENV['RABBIT_EVENT_PEOPLE_APP_NAME'].downcase
26
+ splitted_event_name = event_name.split('.')
29
27
 
30
- Manager.register_listener_configuration(
31
- {
32
- listener_class: self,
33
- method:,
34
- routing_key: fixed_event_name(event_name, 'all')
35
- }
36
- )
37
- Manager.register_listener_configuration(
38
- {
39
- listener_class: self,
40
- method:,
41
- routing_key: fixed_event_name(event_name, app_name)
42
- }
43
- )
28
+ if splitted_event_name.size <= 3
29
+ Manager.register_listener_configuration(
30
+ {
31
+ listener_class: self,
32
+ method:,
33
+ routing_key: fixed_event_name(event_name, 'all')
34
+ }
35
+ )
36
+ Manager.register_listener_configuration(
37
+ {
38
+ listener_class: self,
39
+ method:,
40
+ routing_key: fixed_event_name(event_name, app_name)
41
+ }
42
+ )
43
+ else
44
+ Manager.register_listener_configuration(
45
+ {
46
+ listener_class: self,
47
+ method:,
48
+ routing_key: fixed_event_name(event_name, app_name)
49
+ }
50
+ )
51
+ end
44
52
  end
45
53
 
46
54
  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, channel, delivery_info|
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).callback(config[:method], event)
10
10
  end
11
11
  end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module EventPeople
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.4'
3
3
  end
data/lib/event_people.rb CHANGED
@@ -7,8 +7,10 @@ require 'event_people/listener'
7
7
  require 'event_people/listeners/base'
8
8
  require 'event_people/listeners/manager'
9
9
  require 'event_people/broker/base'
10
+ require 'event_people/broker/context'
10
11
  require 'event_people/broker/rabbit'
11
12
  require 'event_people/broker/rabbit/queue'
13
+ require 'event_people/broker/rabbit/rabbit_context'
12
14
  require 'event_people/broker/rabbit/topic'
13
15
 
14
16
  module EventPeople
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.2
4
+ version: 1.0.4
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-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,8 +104,10 @@ files:
104
104
  - examples/listener.rb
105
105
  - lib/event_people.rb
106
106
  - lib/event_people/broker/base.rb
107
+ - lib/event_people/broker/context.rb
107
108
  - lib/event_people/broker/rabbit.rb
108
109
  - lib/event_people/broker/rabbit/queue.rb
110
+ - lib/event_people/broker/rabbit/rabbit_context.rb
109
111
  - lib/event_people/broker/rabbit/topic.rb
110
112
  - lib/event_people/config.rb
111
113
  - lib/event_people/daemon.rb