hey-pubsub 0.1.0 → 0.2.0
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/README.md +73 -7
- data/lib/hey/configuration.rb +2 -1
- data/lib/hey/event_name.rb +19 -0
- data/lib/hey/pubsub/event.rb +1 -1
- data/lib/hey/pubsub/middleware/faraday.rb +19 -0
- data/lib/hey/version.rb +1 -1
- data/lib/hey.rb +5 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7e86cccd486ebf7f99dcb3b3fd054ee87dc643e
|
4
|
+
data.tar.gz: a93db839d76dd98c5178ad72b4b865ba06e86902
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97edb277e81c3761a444be82f8507a80c59dd4c259da5dd860ebe32cc855749f202c9a281484c7b5c5b601ddc94d2e58827ba4458a4aa491596ca48a0172562
|
7
|
+
data.tar.gz: fda8810ce7f36deed31c4c1bd96eb91d8c8dfbfc48f8fe426013d97523164c2ac3e0e24c0c7349fb5d46e433e9f7c8779ac7ff47fa3ebac8b02135cc3ecc6231
|
data/README.md
CHANGED
@@ -51,7 +51,29 @@ chain of events to be associated later in a Kibana dashboard, for example.
|
|
51
51
|
This UUID could be used across disparate systems subscribing to the same message bus, so long as the convention is
|
52
52
|
adhered to.
|
53
53
|
|
54
|
-
###
|
54
|
+
### Contexts
|
55
|
+
|
56
|
+
Use contexts if you want to attach meta-data to all events that happen on a thread from a certain point forward.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
Hey.context(ip_address: "127.0.0.1") do
|
60
|
+
Hey.publish!("registration.succeeded", { email: "john@ecommerce.com" })
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
The payloads of all events wrapped in a context will include this extra data.
|
65
|
+
|
66
|
+
You may also nest contexts:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Hey.context(ip_address: "127.0.0.1") do
|
70
|
+
Hey.context(current_actor: "Jack Ship") do
|
71
|
+
Hey.publish!("registration.succeeded", { email: "john@ecommerce.com" })
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
#### Sanitizing payloads
|
55
77
|
|
56
78
|
There are times you'd like sensitive information to be stripped from event payloads. For example, if you are logging API
|
57
79
|
requests and responses you should redact credentials before writing to a database or logfile.
|
@@ -60,21 +82,52 @@ It's easier to handle this sanitization during publication, since subscribers of
|
|
60
82
|
values to strip. Hey provides a utility to record these sensitive values and every event published during the life of
|
61
83
|
the current thread will redact them from their payloads.
|
62
84
|
|
85
|
+
You can sanitize data by using the key `sanitize` in your contexts:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
Hey.context(sanitize: ["227-76-1234"]) do
|
89
|
+
Hey.publish!("registration.succeeded", { email: "john@ecommerce.com" })
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Namespacing events
|
94
|
+
|
95
|
+
You can automatically namespace your event names using contexts and a top-level namespace.
|
96
|
+
|
97
|
+
A top-level namespace can be configured like this:
|
98
|
+
|
63
99
|
```ruby
|
64
|
-
Hey.
|
100
|
+
Hey.configure do |config|
|
101
|
+
config.global_namespace = “my-app”
|
102
|
+
end
|
65
103
|
```
|
66
104
|
|
67
|
-
|
105
|
+
As can a delimiter for chaining an event name together, the default of which is “:” :
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Hey.configure do |config|
|
109
|
+
config.delimiter = “/”
|
110
|
+
end
|
111
|
+
```
|
68
112
|
|
69
|
-
|
113
|
+
With this configuration, an event’s name would look like this:
|
70
114
|
|
71
115
|
```ruby
|
72
|
-
Hey.
|
116
|
+
Hey.publish!("registered", { email: "john@ecommerce.com" })
|
117
|
+
=> "my-app/registered"
|
73
118
|
```
|
74
119
|
|
75
|
-
|
120
|
+
You can also set a namespace on contexts and they will automatically be chained together in the order they are nested:
|
76
121
|
|
77
|
-
|
122
|
+
```ruby
|
123
|
+
Hey.context(namespace: “foo”) do
|
124
|
+
Hey.context(namespace: “bar”) do
|
125
|
+
Hey.publish!(“hooray”)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
=> "foo:bar:hooray"
|
130
|
+
```
|
78
131
|
|
79
132
|
## Event publishing and subscribing
|
80
133
|
|
@@ -127,6 +180,19 @@ Hey.subscribe!("registration.succeeded") do |payload|
|
|
127
180
|
end
|
128
181
|
```
|
129
182
|
|
183
|
+
## Middleware
|
184
|
+
|
185
|
+
A faraday middleware adapter is provided to automatically broadcast all requests and responses.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
faraday_connection = ::Faraday.new(url: base_url) do |faraday|
|
189
|
+
faraday.use Hey::Pubsub::Middleware::Faraday
|
190
|
+
faraday.adapter ::Faraday.default_adapter
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
It will broadcast the event names "request" and "response", so be sure to use contexts and namespacing to make the event names more meaningful.
|
195
|
+
|
130
196
|
## Development
|
131
197
|
|
132
198
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/hey/configuration.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
class Hey::EventName
|
2
|
+
def initialize(name)
|
3
|
+
@name = name
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_s
|
7
|
+
[Hey.global_namespace, namespaces, name].flatten.compact.join(Hey.configuration.delimiter)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
def namespaces
|
15
|
+
@namespaces ||= Hey::ThreadCargo.contexts.map do |context|
|
16
|
+
Array[context[:namespace]]
|
17
|
+
end.flatten.compact
|
18
|
+
end
|
19
|
+
end
|
data/lib/hey/pubsub/event.rb
CHANGED
data/lib/hey/version.rb
CHANGED
data/lib/hey.rb
CHANGED
@@ -17,9 +17,12 @@ module Hey
|
|
17
17
|
configuration.pubsub_adapter
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.global_namespace
|
21
|
+
configuration.global_namespace
|
22
|
+
end
|
23
|
+
|
20
24
|
module Behavior
|
21
25
|
def publish!(event_name, payload = {}, &block)
|
22
|
-
event_name = "#{Hey.configuration.namespace}.#{event_name}" unless Hey.configuration.namespace.nil?
|
23
26
|
event = Hey::Pubsub::Event.new(name: event_name, metadata: payload)
|
24
27
|
pubsub_adapter.publish!(event, &block)
|
25
28
|
end
|
@@ -43,6 +46,7 @@ end
|
|
43
46
|
|
44
47
|
require "hey/configuration"
|
45
48
|
require "hey/context"
|
49
|
+
require "hey/event_name"
|
46
50
|
require "hey/thread_cargo"
|
47
51
|
require "hey/sanitized_hash"
|
48
52
|
require "hey/pubsub"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hey-pubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ShippingEasy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,9 +86,11 @@ files:
|
|
86
86
|
- lib/hey.rb
|
87
87
|
- lib/hey/configuration.rb
|
88
88
|
- lib/hey/context.rb
|
89
|
+
- lib/hey/event_name.rb
|
89
90
|
- lib/hey/pubsub.rb
|
90
91
|
- lib/hey/pubsub/adapters/asn_adapter.rb
|
91
92
|
- lib/hey/pubsub/event.rb
|
93
|
+
- lib/hey/pubsub/middleware/faraday.rb
|
92
94
|
- lib/hey/sanitized_hash.rb
|
93
95
|
- lib/hey/thread_cargo.rb
|
94
96
|
- lib/hey/version.rb
|
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
114
|
version: '0'
|
113
115
|
requirements: []
|
114
116
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.4.8
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: Pubsub wrapper with utilities to chain events, sanitize payloads and record
|