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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b5a1cb157137e4894f21237379ea6bfa577c1029cf3f6cfc435eb18b19c767
4
- data.tar.gz: 1d47bc328a3ff19de8c15acd34ada270343d626335406878c967b4b734e3f213
3
+ metadata.gz: c4c53df1e5764393ba4c82cab6335b4e30e21d5fb98cabd9eedeee06269f9f49
4
+ data.tar.gz: ea9d6e275d988d72dda04fe568051238cc9b5e6b55b1c663d4e7e85097f51702
5
5
  SHA512:
6
- metadata.gz: 26f006bd824c1993463984c6b57401fb866ad2293585c72b01506000e6af18f9358d90cd9b8558f17796820f7d20d4aa0da145cdcdd490e358d396788d187a32
7
- data.tar.gz: 05ee47a76e61a3d6700e28a1208d80e856731d160330c373fa86cd4d38a471b8f7bcba481d9a55924dcc5ddd7171ccc311a355426919ec3763c2ff33cd18fd2f
6
+ metadata.gz: bc991a79bd61cab01af627031a5ec122ae22bfeff062c214c800fd2d1ba29442f1289b7f136b56ddfa7a8d6dee769f17d70e4a0ec6e23195f7840f6551ddca34
7
+ data.tar.gz: 6789a883d18b13c1b681b2f924f8a1b903e3dee130a223708822971626d711e91b0016d002865d5ceb6d0d3e444d60f61374a53c92bc08b19ab0b4e136bbfe76
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rocketman (0.2.0)
4
+ rocketman (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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're in luck (well, as long as you're using `Redis` anyway..)
67
+ If you want to also consume events from external services, you can do that too.
68
68
 
69
- Rocketman exposes a `Rocketman::Bridge`, which allows your Ruby code to start consuming events from Redis, **without any changes to your consumers**.
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
- This works because `Bridge` will listen for events from those services on behalf of you, and then it'll push those events onto the internal `Registry`.
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
- Rocketman::Bridge.construct(Redis.new)
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
- That's all! Rocketman will translate the following
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
- **NOTE**: You should always pass in a **new, dedicated** connection to `Redis` to `Bridge#construct`. This is because `redis.subscribe` will hog the whole Redis connection (not just Ruby process), so `Bridge` expects a dedicated connection for itself.
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
 
@@ -4,4 +4,3 @@ require 'rocketman/registry.rb'
4
4
  require 'rocketman/event.rb'
5
5
  require 'rocketman/producer.rb'
6
6
  require 'rocketman/consumer.rb'
7
- require 'rocketman/bridge.rb'
@@ -25,7 +25,7 @@ module Rocketman
25
25
  private
26
26
 
27
27
  def spawn_worker
28
- Thread.abort_on_exception = true if Rocketman.configuration.debug
28
+ Thread.abort_on_exception if Rocketman.configuration.debug
29
29
 
30
30
  Thread.new do
31
31
  loop do
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rocketman
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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
@@ -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