stomp_out 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +0 -1
- data/VERSION +1 -1
- data/lib/stomp_out/client.rb +14 -1
- data/lib/stomp_out/server.rb +52 -12
- data/stomp_out.gemspec +3 -6
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cc602c974a465dd13ce66f3592b59a822521816
|
4
|
+
data.tar.gz: 3f296599ba021a4c246b162e6742b29ebe96f087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922df4ff83adace96a0efd77f3b064eae0f25911bac2c645b26a16ee53616293da29767d81b945b00d1b68164a3e959778ab160046e5fdf4b0292d2722f26c45
|
7
|
+
data.tar.gz: 3518eb6cf0c298d801f0921f5758d4fbf259813fe3d76164edb5d9ca61aa599ecc13a0d951a8d15bce4c543b3d12a675640c58a535f173cc9ef635d200e81f08
|
data/CHANGELOG.rdoc
CHANGED
@@ -6,3 +6,8 @@ Initial commit
|
|
6
6
|
|
7
7
|
Made gem testable under travis and added build status to README
|
8
8
|
Enabled Server#on_connect to override the session_id it is passed
|
9
|
+
|
10
|
+
=== 0.1.2 (2015-02-09)
|
11
|
+
|
12
|
+
Generate session and message IDs incrementally rather than using UUID
|
13
|
+
Handle acks IDs in 1.0/1.1 when message IDs not unique, e.g., on resend
|
data/README.rdoc
CHANGED
@@ -80,7 +80,6 @@ and to consume messages:
|
|
80
80
|
|
81
81
|
= Dependencies
|
82
82
|
|
83
|
-
The simple_uuid gem is used by the Server for generating subscription identifiers.
|
84
83
|
The eventmachine gem is used only if the STOMP heartbeat feature is used.
|
85
84
|
The the json gem is used by the Client only if a content-type is "application/json"
|
86
85
|
and the :auto_json option is enabled.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/stomp_out/client.rb
CHANGED
@@ -46,7 +46,20 @@ module StompOut
|
|
46
46
|
|
47
47
|
MIN_SEND_HEARTBEAT = 5000
|
48
48
|
|
49
|
-
|
49
|
+
# [String] version of STOMP chosen for session
|
50
|
+
attr_reader :version
|
51
|
+
|
52
|
+
# [String] session_id assigned to session
|
53
|
+
attr_reader :session_id
|
54
|
+
|
55
|
+
# [String] name assigned to server
|
56
|
+
attr_reader :server_name
|
57
|
+
|
58
|
+
# [String] host to which client is connecting
|
59
|
+
attr_reader :host
|
60
|
+
|
61
|
+
# [Heartbeat] heartbeat generator and monitor
|
62
|
+
attr_reader :heartbeat
|
50
63
|
|
51
64
|
# Create STOMP client
|
52
65
|
#
|
data/lib/stomp_out/server.rb
CHANGED
@@ -19,8 +19,6 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
-
require 'simple_uuid'
|
23
|
-
|
24
22
|
module StompOut
|
25
23
|
|
26
24
|
# Abstract base class for STOMP server for use with an existing client connection, such
|
@@ -57,7 +55,20 @@ module StompOut
|
|
57
55
|
MIN_SEND_HEARTBEAT = 5000
|
58
56
|
DESIRED_RECEIVE_HEARTBEAT = 60000
|
59
57
|
|
60
|
-
|
58
|
+
# [Integer] value of last generated session ID for class
|
59
|
+
@@last_session_id = 0
|
60
|
+
|
61
|
+
# [String] version of STOMP chosen for session
|
62
|
+
attr_reader :version
|
63
|
+
|
64
|
+
# [String] session_id assigned to session
|
65
|
+
attr_reader :session_id
|
66
|
+
|
67
|
+
# [String] name assigned to server
|
68
|
+
attr_reader :server_name
|
69
|
+
|
70
|
+
# [Heartbeat] heartbeat generator and monitor
|
71
|
+
attr_reader :heartbeat
|
61
72
|
|
62
73
|
# Create STOMP server
|
63
74
|
#
|
@@ -71,6 +82,7 @@ module StompOut
|
|
71
82
|
@options = options
|
72
83
|
@ack_id = 0
|
73
84
|
@ack_ids = {} # message-id is key
|
85
|
+
@message_id = 0
|
74
86
|
@subscribe_id = 0
|
75
87
|
@subscribes = {} # destination is key
|
76
88
|
@server_name = options[:name] + (options[:version] ? "/#{options[:version]}" : "") if options[:name]
|
@@ -250,18 +262,19 @@ module StompOut
|
|
250
262
|
# - may set other application-specific headers
|
251
263
|
#
|
252
264
|
# @param [Hash] headers for message per requirements above but with "message-id"
|
253
|
-
# defaulting to generated
|
265
|
+
# defaulting to generated ID and "ack" defaulting to generated ID if not specified
|
254
266
|
# @param [String] body of message
|
255
267
|
#
|
256
268
|
# @return [Array] message ID and ack ID; latter is nil if ack is in "auto" mode
|
257
269
|
#
|
258
270
|
# @raise [ProtocolError] not connected
|
259
|
-
# @raise [ApplicationError] subscription not found, subscription does not match destination
|
271
|
+
# @raise [ApplicationError] subscription not found, subscription does not match destination,
|
272
|
+
# non-unique message ID
|
260
273
|
def message(headers, body)
|
261
274
|
raise ProtocolError.new("Not connected") unless @connected
|
262
275
|
frame = Frame.new(nil, (headers && headers.dup) || {})
|
263
276
|
destination, subscribe_id = frame.require(@version, "destination" => [], "subscription" => ["1.0"])
|
264
|
-
message_id = frame.headers["message-id"] ||=
|
277
|
+
message_id = frame.headers["message-id"] ||= (@message_id += 1).to_s
|
265
278
|
|
266
279
|
ack_id = nil
|
267
280
|
if (subscribe = @subscribes[destination])
|
@@ -272,10 +285,11 @@ module StompOut
|
|
272
285
|
# Create ack ID if there is none so that user of this server can rely
|
273
286
|
# on always receiving an ack ID (as opposed to a message ID) on ack/nack
|
274
287
|
# independent of STOMP version in use
|
275
|
-
|
276
|
-
|
288
|
+
if @version < "1.2"
|
289
|
+
ack_id = frame.headers.delete("ack") || (@ack_id += 1).to_s
|
290
|
+
@ack_ids[message_id] = (@ack_ids[message_id] || []) << ack_id
|
277
291
|
else
|
278
|
-
frame.headers["ack"] ||= (@ack_id += 1).to_s
|
292
|
+
ack_id = frame.headers["ack"] ||= (@ack_id += 1).to_s
|
279
293
|
end
|
280
294
|
end
|
281
295
|
else
|
@@ -380,7 +394,7 @@ module StompOut
|
|
380
394
|
headers["heart-beat"] = [@heartbeat.outgoing_rate, @heartbeat.incoming_rate].join(",")
|
381
395
|
end
|
382
396
|
headers["server"] = @server_name if @server_name
|
383
|
-
default_session_id =
|
397
|
+
default_session_id = self.class.next_session_id
|
384
398
|
if (result = on_connect(frame, frame.headers["login"], frame.headers["passcode"], host, default_session_id))
|
385
399
|
@connected = true
|
386
400
|
@session_id = (result.is_a?(String) || result.is_a?(Integer)) ? result.to_s : default_session_id
|
@@ -485,7 +499,7 @@ module StompOut
|
|
485
499
|
# @raise [ProtocolError] missing header
|
486
500
|
def receive_ack(frame)
|
487
501
|
id, message_id = frame.require(@version, "id" => ["1.0", "1.1"], "message-id" => ["1.2"])
|
488
|
-
on_ack(frame, id ||
|
502
|
+
on_ack(frame, id || to_ack(message_id))
|
489
503
|
true
|
490
504
|
end
|
491
505
|
|
@@ -501,7 +515,7 @@ module StompOut
|
|
501
515
|
def receive_nack(frame)
|
502
516
|
raise ProtocolError.new("Invalid command", frame) if @version == "1.0"
|
503
517
|
id, message_id = frame.require(@version, "id" => ["1.0", "1.1"], "message-id" => ["1.2"])
|
504
|
-
on_nack(frame, id ||
|
518
|
+
on_nack(frame, id || to_ack(message_id))
|
505
519
|
true
|
506
520
|
end
|
507
521
|
|
@@ -666,6 +680,32 @@ module StompOut
|
|
666
680
|
version
|
667
681
|
end
|
668
682
|
|
683
|
+
# Convert message ID to ack ID
|
684
|
+
# Allow for the possibility of a message being resent before being acknowledged
|
685
|
+
# (or message IDs not being unique), in which case arbitrarily convert to oldest ack ID
|
686
|
+
#
|
687
|
+
# @param [String] message_id to be converted
|
688
|
+
#
|
689
|
+
# @return [String] ack ID
|
690
|
+
#
|
691
|
+
# @raise [ApplicationError] message ID unknown
|
692
|
+
def to_ack(message_id)
|
693
|
+
if (ids = @ack_ids[message_id])
|
694
|
+
id = ids.shift
|
695
|
+
@ack_ids.delete(message_id) if ids.empty?
|
696
|
+
id
|
697
|
+
else
|
698
|
+
raise ApplicationError.new("Unknown 'message-id': #{message_id.inspect}")
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
# Generate next session ID
|
703
|
+
#
|
704
|
+
# @return [String] session ID
|
705
|
+
def self.next_session_id
|
706
|
+
(@@last_session_id += 1).to_s
|
707
|
+
end
|
708
|
+
|
669
709
|
end # Server
|
670
710
|
|
671
711
|
end # StompOut
|
data/stomp_out.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: stomp_out 0.1.
|
5
|
+
# stub: stomp_out 0.1.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "stomp_out"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Lee Kirchhoff"]
|
14
|
-
s.date = "2015-02-
|
14
|
+
s.date = "2015-02-09"
|
15
15
|
s.description = "This implementation of STOMP is aimed at environments where a network connection, such as a WebSocket or TCP socket, is created and then raw data from that connection is passed to/from the STOMP client or server messaging layer provided by this gem."
|
16
16
|
s.email = "support@rightscale.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -48,7 +48,6 @@ Gem::Specification.new do |s|
|
|
48
48
|
|
49
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
50
|
s.add_runtime_dependency(%q<json>, ["~> 1.4"])
|
51
|
-
s.add_runtime_dependency(%q<simple_uuid>, ["~> 0.2"])
|
52
51
|
s.add_development_dependency(%q<rake>, ["~> 10.0"])
|
53
52
|
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
54
53
|
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
@@ -56,7 +55,6 @@ Gem::Specification.new do |s|
|
|
56
55
|
s.add_development_dependency(%q<pry-byebug>, [">= 0"])
|
57
56
|
else
|
58
57
|
s.add_dependency(%q<json>, ["~> 1.4"])
|
59
|
-
s.add_dependency(%q<simple_uuid>, ["~> 0.2"])
|
60
58
|
s.add_dependency(%q<rake>, ["~> 10.0"])
|
61
59
|
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
62
60
|
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
@@ -65,7 +63,6 @@ Gem::Specification.new do |s|
|
|
65
63
|
end
|
66
64
|
else
|
67
65
|
s.add_dependency(%q<json>, ["~> 1.4"])
|
68
|
-
s.add_dependency(%q<simple_uuid>, ["~> 0.2"])
|
69
66
|
s.add_dependency(%q<rake>, ["~> 10.0"])
|
70
67
|
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
71
68
|
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stomp_out
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Kirchhoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.4'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: simple_uuid
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.2'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.2'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|