event_people 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: 2edc78cae5809676875057845aa4646b5b7c2cf10b2c0cd19a3db4303c20ed6d
4
- data.tar.gz: f02920c4bcc5fa8851677050e33ad91fe09a647f598ae6bb5b955e0a72bafcf6
3
+ metadata.gz: 8fe37c13b973b908692331742769cfe80e9275fd9b00c10f8ce1754caed401dd
4
+ data.tar.gz: 0bd35eac8aa30ac949d335e93d9ddc4e85d691561727c8b215d1780c34fd0c31
5
5
  SHA512:
6
- metadata.gz: 38b52078fbdf1dc410aba893b0269dc39bdfef91a651975100c3ec0d236e2dace74b3bda66e9d0fa9f9c0a8287cddeb0c369afe32c65a94fb00384acc41282cf
7
- data.tar.gz: ebf453a791a7184943d92157b8bf693712e94f4fb40146cf3db4f76e10c4b35e0cf9b1de03cfe20619076226c4a3e5b546865c3d6bb2a53d5e49c386d263268e
6
+ metadata.gz: f47f4f894349f3d551cca37b555d295ced7413407242cf5ad6c9a9ec7ef1e0438498a7450026b4515d7561b1454c930c8c36d68f359a27beccd369b730d61b6c
7
+ data.tar.gz: 7723659cc5cb3774f2d01c0217a1da4a3de1b2e9d83bd39d30884af351bf8b223e378c37580f84c16b0602ef14e2cb52637848b209fcd1245fe9e748c803bb81
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.3)
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
 
@@ -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
@@ -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
- 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
- )
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, 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.channel, context.delivery_info).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.3'
3
3
  end
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.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-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler