rocketman 0.2.0 → 0.3.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/Gemfile.lock +1 -1
- data/README.md +14 -11
- data/lib/rocketman.rb +0 -1
- data/lib/rocketman/pool.rb +1 -1
- data/lib/rocketman/relay/redis.rb +24 -0
- data/lib/rocketman/version.rb +1 -1
- metadata +2 -2
- data/lib/rocketman/bridge.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c53df1e5764393ba4c82cab6335b4e30e21d5fb98cabd9eedeee06269f9f49
|
4
|
+
data.tar.gz: ea9d6e275d988d72dda04fe568051238cc9b5e6b55b1c663d4e7e85097f51702
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc991a79bd61cab01af627031a5ec122ae22bfeff062c214c800fd2d1ba29442f1289b7f136b56ddfa7a8d6dee769f17d70e4a0ec6e23195f7840f6551ddca34
|
7
|
+
data.tar.gz: 6789a883d18b13c1b681b2f924f8a1b903e3dee130a223708822971626d711e91b0016d002865d5ceb6d0d3e444d60f61374a53c92bc08b19ab0b4e136bbfe76
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -62,23 +62,24 @@ end
|
|
62
62
|
|
63
63
|
Simple isn't it?
|
64
64
|
|
65
|
-
#### Consume events from external services
|
65
|
+
#### Consume events from external services (Relays)
|
66
66
|
|
67
|
-
If you want to also consume events from external services, you
|
67
|
+
If you want to also consume events from external services, you can do that too.
|
68
68
|
|
69
|
-
Rocketman
|
69
|
+
Rocketman has the concept of a `Relay`. The cool thing is, `Relay`s are just `Producer`s that understand how to relay messages from external services (like `Redis`) into Rocketman events.
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
**This pattern is powerful because this means your consumers do not have to know where the events are coming from, as long as they're registed onto `Registry`.**
|
74
|
-
|
75
|
-
Right now, only `Redis` is supported. Assuming you have the `redis` gem installed, this is how you register a bridge.
|
71
|
+
Rocketman ships with a `Redis` relay, which you can use it like so (assuming you have Redis installed):
|
76
72
|
|
77
73
|
```ruby
|
78
|
-
|
74
|
+
require 'rocketman/relay/redis' # This is not required by default, so you need to explicitly require it.
|
75
|
+
Rocketman::Relay::Redis.new.start(Redis.new)
|
79
76
|
```
|
80
77
|
|
81
|
-
|
78
|
+
> **NOTE**: You should always pass in a **new, dedicated** connection to `Redis` to `Bridge#construct`. This is because `redis.psubscribe` will hog the whole Redis connection (not just Ruby process), so `Relay` expects a dedicated connection for itself.
|
79
|
+
|
80
|
+
That's it, the `Redis` relay service will now listen for events from external services on behalf of you, and then it'll push those events onto the internal `Registry`.
|
81
|
+
|
82
|
+
It'll translate the following:
|
82
83
|
|
83
84
|
```
|
84
85
|
redis-cli> PUBLISH hello payload
|
@@ -94,7 +95,9 @@ end
|
|
94
95
|
|
95
96
|
Notice how it behaves exactly the same as if the events did not come from Redis :)
|
96
97
|
|
97
|
-
**
|
98
|
+
**This pattern is powerful because this means your consumers do not have to know where the events are coming from, as long as they're registed onto `Registry`.**
|
99
|
+
|
100
|
+
Right now, only `Redis` is supported, but it is extremely easy to add a `Relay` yourself since it's just a `Producer`. Checkout the implementation of `rocketman/relay/redis` for reference, upstream contributions for services are very welcomed too.
|
98
101
|
|
99
102
|
## Persisting emitted events
|
100
103
|
|
data/lib/rocketman.rb
CHANGED
data/lib/rocketman/pool.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'redis'
|
2
|
+
|
3
|
+
module Rocketman
|
4
|
+
module Relay
|
5
|
+
class Redis
|
6
|
+
include Rocketman::Producer
|
7
|
+
|
8
|
+
# You should always pass in a new, dedicated connection to `Redis`.
|
9
|
+
# This is because `redis.psubscribe` will hog the whole Redis connection, thus if you pass in an existing Redis connection, you won't be able to do anything with that connection anymore.
|
10
|
+
def start(service)
|
11
|
+
puts "Rocketman> Using Redis as external producer".freeze if Rocketman.configuration.debug
|
12
|
+
|
13
|
+
Thread.abort_on_exception = Rocketman.configuration.debug
|
14
|
+
Thread.new do
|
15
|
+
service.psubscribe("*") do |on|
|
16
|
+
on.pmessage do |_pattern, event, payload|
|
17
|
+
emit(event, payload)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/rocketman/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edison Yap
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
101
|
- lib/rocketman.rb
|
102
|
-
- lib/rocketman/bridge.rb
|
103
102
|
- lib/rocketman/config.rb
|
104
103
|
- lib/rocketman/consumer.rb
|
105
104
|
- lib/rocketman/event.rb
|
@@ -107,6 +106,7 @@ files:
|
|
107
106
|
- lib/rocketman/pool.rb
|
108
107
|
- lib/rocketman/producer.rb
|
109
108
|
- lib/rocketman/registry.rb
|
109
|
+
- lib/rocketman/relay/redis.rb
|
110
110
|
- lib/rocketman/version.rb
|
111
111
|
- rocketman.gemspec
|
112
112
|
- rocketman.jpg
|
data/lib/rocketman/bridge.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Rocketman
|
2
|
-
class Bridge
|
3
|
-
include Rocketman::Producer
|
4
|
-
|
5
|
-
attr_reader :service
|
6
|
-
|
7
|
-
def initialize(service)
|
8
|
-
@service = service
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.construct(service)
|
12
|
-
instance = new(service)
|
13
|
-
|
14
|
-
case instance.service.class.to_s
|
15
|
-
when "Redis"
|
16
|
-
puts "Rocketman> Using Redis as external producer".freeze
|
17
|
-
Thread.new do
|
18
|
-
instance.service.psubscribe("*") do |on|
|
19
|
-
on.pmessage do |_pattern, event, payload|
|
20
|
-
instance.emit(event, payload)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
else
|
25
|
-
puts "Rocketman> Don't know how to handle service: `#{service}`"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|