streamforce 0.1.0 → 0.1.1

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: 5d03ff265d884babb70b8db70637c9814a5819834ed83109b2b26537cb5c992b
4
- data.tar.gz: b7b87b62347f92e9a27139536655ee95339e8a3b22bf2c1980db1eca00fa66e9
3
+ metadata.gz: 39b60e818f6a705ee63949e7ff6a48858565917a737691cb6a94c109e37f7342
4
+ data.tar.gz: ca563677771ec54e9fbef2a3ddf4de157d59d3e879ad9f7ad8841269da02bed3
5
5
  SHA512:
6
- metadata.gz: c4dc737d70d28c061ee3c89379b97274983c14008184acbe7c99139b59c3ed79b3ef79893ba3d486d3f142172d30461260237d171bdb7a230c6f92471769a605
7
- data.tar.gz: 6a3bbd281947060861c34e5cceab6814cfad52a80e964c80ef4da4956a3c40287e1315ef05419c69b31e60ac2bd20b394336e85a087c8fd41e22691543f6f7d7
6
+ metadata.gz: 1491f1d6772bf34b393879dfdec8b18b6310e28fcfcafe6f8136994b9c7667c09e07221a8dd52f032e9d746771802f80b87356534b65f33b2ba1a33290520f9a
7
+ data.tar.gz: fde46e8c412e01be566741d5474216ea55ea3e77f83cf29f19a3cd417017d646c64f9140cf153bd727a88997e9698fc7f54decf906cf0581b586e6c21c77e226
data/README.md CHANGED
@@ -1,45 +1,22 @@
1
1
  # Streamforce
2
2
 
3
- In most cases, processing events received from the Salesforce Streaming API can be
3
+ In most cases, consuming events received from the Salesforce Streaming API can be
4
4
  broken down into three very specific steps:
5
5
 
6
- 1. Connecting to the Salesforce API and listening for messaging
6
+ 1. Connecting to the Salesforce API and listening for messages
7
7
  2. Ingesting received messages into some sort of internal event bus (e.g. RabbitMQ,
8
8
  Kafka, Redis, etc)
9
9
  3. Processing the stored messages
10
10
 
11
- Streamforce aims to handle #1 and simplify the work done for #2.
12
-
13
- [Restforce](https://github.com/restforce/restforce) provides a simple API to connect
14
- to the Streaming API and consume messages:
15
-
16
- ```ruby
17
- # Restforce uses faye as the underlying implementation for CometD.
18
- require 'faye'
19
-
20
- # Initialize a client with your username/password/oauth token/etc.
21
- client = Restforce.new(username: 'foo',
22
- password: 'bar',
23
- security_token: 'security token',
24
- client_id: 'client_id',
25
- client_secret: 'client_secret')
26
-
27
- EM.run do
28
- # Subscribe to the PushTopic.
29
- client.subscription '/topic/AllAccounts' do |message|
30
- puts message.inspect
31
- end
32
- end
33
- ```
34
-
35
- However, the above code is usable in a production environment because:
11
+ Streamforce aims to be an abstraction for the first step, by implementing some of the
12
+ common tasks that need to be performed by any well-behaved client:
36
13
 
37
14
  * The interactions with the Streaming API need to be logged using the correct severity
38
15
  (e.g. handshakes should use `Logger::DEBUG` while subscription errors should use
39
16
  `Logger::ERROR` for better visibility)
40
17
  * Replay IDs need to be stored using a persistent storage like Redis and not in-memory
41
18
 
42
- Streamforce comes with all the batteries included.
19
+ As an alternative, checkout [Restforce](https://github.com/restforce/restforce).
43
20
 
44
21
  ## Usage
45
22
 
@@ -5,36 +5,36 @@ class Streamforce::Extension::Logging
5
5
 
6
6
  def incoming(payload, callback)
7
7
  message = Streamforce::Message.new(payload)
8
- log_incoming_message(message)
8
+
9
+ case message.channel
10
+ when "/meta/handshake"
11
+ log_incoming_handshake(message)
12
+ when "/meta/connect"
13
+ log_incoming_connect(message)
14
+ when "/meta/subscribe"
15
+ log_incoming_subscribe(message)
16
+ else
17
+ @logger.debug "[#{message.channel}] #{message.data}"
18
+ end
9
19
 
10
20
  callback.call(payload)
11
21
  end
12
22
 
13
23
  def outgoing(payload, callback)
14
24
  message = Streamforce::Message.new(payload)
15
- log_outgoing_message(message)
16
-
17
- callback.call(payload)
18
- end
19
-
20
- def log_incoming_message(message)
21
- if message.channel_type == "meta"
22
- public_send("log_incoming_#{message.channel_name}", message)
23
- else
24
- @logger.debug "[#{message.channel_name}] #{message.data}"
25
- end
26
- end
27
25
 
28
- def log_outgoing_message(message)
29
- if message.channel_type == "meta"
30
- public_send("log_outgoing_#{message.channel_name}", message)
26
+ case message.channel
27
+ when "/meta/handshake"
28
+ @logger.debug "[Client] Handshake requested..."
29
+ when "/meta/connect"
30
+ debug message, "Sending connection request"
31
+ when "/meta/subscribe"
32
+ log_outgoing_subscribe(message)
31
33
  else
32
- @logger.debug "[#{message.channel_name}] #{message.data}"
34
+ @logger.debug "[#{message.channel}] #{message.data}"
33
35
  end
34
- end
35
36
 
36
- def log_outgoing_handshake(message)
37
- @logger.debug "[Client] Handshake requested..."
37
+ callback.call(payload)
38
38
  end
39
39
 
40
40
  def log_incoming_handshake(message)
@@ -45,10 +45,6 @@ class Streamforce::Extension::Logging
45
45
  end
46
46
  end
47
47
 
48
- def log_outgoing_connect(message)
49
- debug message, "Sending connection request"
50
- end
51
-
52
48
  def log_incoming_connect(message)
53
49
  if message.success?
54
50
  debug message, "Connection successful!"
@@ -60,9 +56,9 @@ class Streamforce::Extension::Logging
60
56
  def log_outgoing_subscribe(message)
61
57
  replay_id = message.replay_id
62
58
 
63
- replay_info = if replay_id == -1
59
+ replay_info = if message.no_replay?
64
60
  "for all new messages"
65
- elsif replay_id == -2
61
+ elsif message.replay_available_messages?
66
62
  "and requesting all stored messages"
67
63
  else
68
64
  "and requesting all messages newer than ##{replay_id}"
@@ -3,8 +3,8 @@ class Streamforce::Message
3
3
  @payload = payload
4
4
  end
5
5
 
6
- def success?
7
- @payload["successful"]
6
+ def client_id
7
+ @payload["clientId"]
8
8
  end
9
9
 
10
10
  def id
@@ -19,10 +19,6 @@ class Streamforce::Message
19
19
  @payload["channel"]
20
20
  end
21
21
 
22
- def client_id
23
- @payload["clientId"]
24
- end
25
-
26
22
  def channel_type
27
23
  channel.split("/")[1]
28
24
  end
@@ -31,6 +27,10 @@ class Streamforce::Message
31
27
  channel.split("/")[2]
32
28
  end
33
29
 
30
+ def success?
31
+ @payload["successful"]
32
+ end
33
+
34
34
  def data
35
35
  @payload["data"]
36
36
  end
@@ -43,6 +43,18 @@ class Streamforce::Message
43
43
  channel == "/meta/subscribe"
44
44
  end
45
45
 
46
+ def replay_from_message?
47
+ replay_id && replay_id != -1 && replay_id != -2
48
+ end
49
+
50
+ def replay_available_messages?
51
+ replay_id == -2
52
+ end
53
+
54
+ def no_replay?
55
+ replay_id.nil? || replay_id == -1
56
+ end
57
+
46
58
  def error_message
47
59
  @payload["error"]
48
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Streamforce
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streamforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Maxim
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - andrei@andreimaxim.ro
114
114
  executables: []
@@ -133,7 +133,7 @@ metadata:
133
133
  homepage_uri: https://github.com/andreimaxim/streamforce
134
134
  source_code_uri: https://github.com/andreimaxim/streamforce
135
135
  changelog_uri: https://github.com/andreimaxim/streamforce/blob/main/CHANGELOG.md
136
- post_install_message:
136
+ post_install_message:
137
137
  rdoc_options: []
138
138
  require_paths:
139
139
  - lib
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubygems_version: 3.5.9
152
- signing_key:
152
+ signing_key:
153
153
  specification_version: 4
154
154
  summary: Small wrapper over the Salesforce Streaming API
155
155
  test_files: []