salesforce_streamer 1.1.3 → 1.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/Gemfile.lock +10 -10
- data/README.md +20 -0
- data/lib/salesforce_streamer/configuration.rb +11 -1
- data/lib/salesforce_streamer/push_topic.rb +20 -0
- data/lib/salesforce_streamer/server.rb +5 -3
- data/lib/salesforce_streamer/version.rb +1 -1
- data/lib/salesforce_streamer.rb +0 -1
- metadata +3 -4
- data/lib/salesforce_streamer/message_receiver.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2174b14554d0de8cd9d40a4ed7d85323316a363915a7030dba34f392bfb7cf66
|
4
|
+
data.tar.gz: d841e9dca629409c5c0572267da8246d5f21e301c5c7c85d6f0f44cac32ca664
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f4e6a58005ab86abbe38816e1b511bb2201bd4cdb66bfb90d918e9e7e8123158780b32f937106d39f70d987d9527ef25007aecd104063e647f3119bf601ab3
|
7
|
+
data.tar.gz: 951a5316f531b860f52c0c7198542414209a4384c9361a2e28f10f33ae92406c29def1e79d23f79ea987d04176a896e0186385b4ad1a3db64cf7a330ec9eabf9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
salesforce_streamer (1.
|
4
|
+
salesforce_streamer (1.2.0)
|
5
5
|
faye (= 0.8.9)
|
6
6
|
restforce (~> 4.2)
|
7
7
|
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
addressable (2.7.0)
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
13
13
|
ast (2.4.0)
|
14
|
-
byebug (11.1.
|
14
|
+
byebug (11.1.3)
|
15
15
|
codecov (0.1.16)
|
16
16
|
json
|
17
17
|
simplecov
|
@@ -49,9 +49,9 @@ GEM
|
|
49
49
|
jwt (2.2.1)
|
50
50
|
multipart-post (2.1.1)
|
51
51
|
parallel (1.19.1)
|
52
|
-
parser (2.7.
|
52
|
+
parser (2.7.1.2)
|
53
53
|
ast (~> 2.4.0)
|
54
|
-
public_suffix (4.0.
|
54
|
+
public_suffix (4.0.4)
|
55
55
|
rack (2.2.2)
|
56
56
|
rainbow (3.0.0)
|
57
57
|
rake (13.0.1)
|
@@ -66,16 +66,16 @@ GEM
|
|
66
66
|
rspec-core (~> 3.9.0)
|
67
67
|
rspec-expectations (~> 3.9.0)
|
68
68
|
rspec-mocks (~> 3.9.0)
|
69
|
-
rspec-core (3.9.
|
70
|
-
rspec-support (~> 3.9.
|
71
|
-
rspec-expectations (3.9.
|
69
|
+
rspec-core (3.9.2)
|
70
|
+
rspec-support (~> 3.9.3)
|
71
|
+
rspec-expectations (3.9.2)
|
72
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
73
73
|
rspec-support (~> 3.9.0)
|
74
74
|
rspec-mocks (3.9.1)
|
75
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
76
|
rspec-support (~> 3.9.0)
|
77
|
-
rspec-support (3.9.
|
78
|
-
rubocop (0.
|
77
|
+
rspec-support (3.9.3)
|
78
|
+
rubocop (0.82.0)
|
79
79
|
jaro_winkler (~> 1.5.1)
|
80
80
|
parallel (~> 1.10)
|
81
81
|
parser (>= 2.7.0.1)
|
@@ -85,7 +85,7 @@ GEM
|
|
85
85
|
unicode-display_width (>= 1.4.0, < 2.0)
|
86
86
|
rubocop-performance (1.5.2)
|
87
87
|
rubocop (>= 0.71.0)
|
88
|
-
rubocop-rspec (1.
|
88
|
+
rubocop-rspec (1.39.0)
|
89
89
|
rubocop (>= 0.68.1)
|
90
90
|
ruby-progressbar (1.10.1)
|
91
91
|
simplecov (0.18.5)
|
data/README.md
CHANGED
@@ -20,6 +20,26 @@ And then execute:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
### Middleware
|
24
|
+
|
25
|
+
You can initialize the streamer server with any number of middleware classes.
|
26
|
+
When a message is received by a PushTopic subscription, the chain of middleware
|
27
|
+
classes are executed before the message handler is called.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# config/initializers/streamer.rb
|
31
|
+
class MySimpleMiddleware
|
32
|
+
def initialize(handler)
|
33
|
+
@handler = handler
|
34
|
+
end
|
35
|
+
def call(message)
|
36
|
+
@handler.call(message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
SalesforceStreamer.config.use_middleware MySimpleMiddleware
|
41
|
+
```
|
42
|
+
|
23
43
|
### Configure Push Topics
|
24
44
|
|
25
45
|
Create a YAML file to configure your server subscriptions. The configuration
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module SalesforceStreamer
|
2
2
|
# Manages server configuration.
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :environment, :logger, :require_path, :config_file, :manage_topics,
|
4
|
+
attr_accessor :environment, :logger, :require_path, :config_file, :manage_topics,
|
5
|
+
:server, :exception_adapter, :persistence_adapter, :redis_connection, :middleware
|
5
6
|
|
6
7
|
class << self
|
7
8
|
attr_writer :instance
|
@@ -19,12 +20,21 @@ module SalesforceStreamer
|
|
19
20
|
@manage_topics = false
|
20
21
|
@config_file = './config/streamer.yml'
|
21
22
|
@require_path = './config/environment'
|
23
|
+
@middleware = []
|
22
24
|
end
|
23
25
|
|
24
26
|
def manage_topics?
|
25
27
|
@manage_topics
|
26
28
|
end
|
27
29
|
|
30
|
+
def use_middleware(klass, *args, &block)
|
31
|
+
middleware << proc { |app| klass.new(app, *args, &block) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def middleware_chain_for(app)
|
35
|
+
middleware.reduce(app) { |memo, middleware| middleware.call(memo) }
|
36
|
+
end
|
37
|
+
|
28
38
|
def push_topic_data
|
29
39
|
return @push_topic_data if @push_topic_data
|
30
40
|
|
@@ -20,6 +20,14 @@ module SalesforceStreamer
|
|
20
20
|
ReplayPersistence.retrieve(name) || @static_replay
|
21
21
|
end
|
22
22
|
|
23
|
+
def handle(message)
|
24
|
+
handle_chain.call(message)
|
25
|
+
ReplayPersistence.record @name, message.dig('event', 'replayId')
|
26
|
+
rescue StandardError => e
|
27
|
+
Log.error e
|
28
|
+
Configuration.instance.exception_adapter.call e
|
29
|
+
end
|
30
|
+
|
23
31
|
def to_s
|
24
32
|
"PushTopic id=#{id} name=#{name} handler=#{handler} " \
|
25
33
|
"replay=#{replay} notify_for_fields=#{notify_for_fields} " \
|
@@ -38,6 +46,18 @@ module SalesforceStreamer
|
|
38
46
|
raise(PushTopicHandlerMissingError, message)
|
39
47
|
end
|
40
48
|
|
49
|
+
def handle_chain
|
50
|
+
Configuration.instance.middleware_chain_for(handler_proc)
|
51
|
+
end
|
52
|
+
|
53
|
+
def handler_proc
|
54
|
+
if handler_constant.respond_to? :perform_async
|
55
|
+
proc { |message| handler_constant.perform_async message }
|
56
|
+
else
|
57
|
+
handler_constant
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
41
61
|
def strip_spaces(str)
|
42
62
|
fail(NilQueryError, @name) unless str
|
43
63
|
|
@@ -34,9 +34,11 @@ module SalesforceStreamer
|
|
34
34
|
def start_em
|
35
35
|
EM.run do
|
36
36
|
@push_topics.map do |topic|
|
37
|
-
client.subscribe topic.name, replay: topic.replay.to_i do |
|
38
|
-
|
39
|
-
|
37
|
+
client.subscribe topic.name, replay: topic.replay.to_i do |message|
|
38
|
+
replay_id = message.dig('event', 'replayId')
|
39
|
+
Log.info "Message #{replay_id} received from topic #{topic.name}"
|
40
|
+
topic.handle message
|
41
|
+
topic.id = replay_id
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
data/lib/salesforce_streamer.rb
CHANGED
@@ -14,7 +14,6 @@ require 'salesforce_streamer/topic_manager'
|
|
14
14
|
require 'salesforce_streamer/salesforce_client'
|
15
15
|
require 'salesforce_streamer/replay_persistence'
|
16
16
|
require 'salesforce_streamer/redis_replay'
|
17
|
-
require 'salesforce_streamer/message_receiver'
|
18
17
|
require 'salesforce_streamer/server'
|
19
18
|
require 'salesforce_streamer/version'
|
20
19
|
require 'salesforce_streamer/launcher'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforce_streamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Serok
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faye
|
@@ -163,7 +163,6 @@ files:
|
|
163
163
|
- lib/salesforce_streamer/errors.rb
|
164
164
|
- lib/salesforce_streamer/launcher.rb
|
165
165
|
- lib/salesforce_streamer/log.rb
|
166
|
-
- lib/salesforce_streamer/message_receiver.rb
|
167
166
|
- lib/salesforce_streamer/push_topic.rb
|
168
167
|
- lib/salesforce_streamer/redis_replay.rb
|
169
168
|
- lib/salesforce_streamer/replay_id_error_extension.rb
|
@@ -194,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
193
|
- !ruby/object:Gem::Version
|
195
194
|
version: '0'
|
196
195
|
requirements: []
|
197
|
-
rubygems_version: 3.
|
196
|
+
rubygems_version: 3.0.6
|
198
197
|
signing_key:
|
199
198
|
specification_version: 4
|
200
199
|
summary: A wrapper around the Restforce Streaming API with a built-in PushTopic manager.
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module SalesforceStreamer
|
2
|
-
class MessageReceiver
|
3
|
-
class << self
|
4
|
-
# @param topic [String] The unique Salesforce Topic name
|
5
|
-
# @param handler [Object] An object that responds to .call(message)
|
6
|
-
# @param message [Hash] The event payload
|
7
|
-
def call(topic, handler, message)
|
8
|
-
if handler.respond_to? :perform_async
|
9
|
-
handler.perform_async message
|
10
|
-
else
|
11
|
-
handler.call message
|
12
|
-
end
|
13
|
-
ReplayPersistence.record topic, message.dig('event', 'replayId')
|
14
|
-
rescue StandardError => e
|
15
|
-
Configuration.instance.exception_adapter.call e
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|