StompMq 0.3 → 0.4
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.
- data/lib/stompmq/connection.rb +11 -10
- metadata +2 -2
data/lib/stompmq/connection.rb
CHANGED
@@ -14,13 +14,15 @@ module StompMq
|
|
14
14
|
# Connect to a STOMP broker and log in.
|
15
15
|
def initialize(opts = { :broker => 'localhost', :port => 61613, :username => nil, :passcode => nil })
|
16
16
|
@buffer = ""
|
17
|
-
@broker = opts[:broker]
|
18
|
-
@port = opts[:port]
|
17
|
+
@broker = opts[:broker] || 'localhost'
|
18
|
+
@port = opts[:port] || 61613
|
19
19
|
@username = opts[:username]
|
20
20
|
@passcode = opts[:passcode]
|
21
21
|
@sock = TCPSocket.new @broker, @port
|
22
22
|
send_frame :connect, {:login => @username, :passcode => @passcode}
|
23
23
|
frame = receive_frame(15)
|
24
|
+
# some brokers add a \n after null-terminators, including after CONNECTED frames.
|
25
|
+
@buffer = ""
|
24
26
|
raise ProtocolSequenceViolation unless frame.cmd == 'CONNECTED'
|
25
27
|
self
|
26
28
|
end
|
@@ -56,20 +58,21 @@ module StompMq
|
|
56
58
|
private
|
57
59
|
|
58
60
|
# Transmit a standard STOMP frame.
|
59
|
-
def send_frame(function, header = {}, content =
|
61
|
+
def send_frame(function, header = {}, content = '')
|
60
62
|
frame = "#{function.to_s.upcase}\n"
|
61
|
-
header['content-length'] = content.to_s.length
|
63
|
+
header['content-length'] = content.to_s.length if content.to_s.include?("\000")
|
62
64
|
header.each do |key, val|
|
63
65
|
frame += "#{key.to_s}:#{val.to_s}\n"
|
64
66
|
end
|
65
67
|
frame += "\n"
|
66
68
|
frame += "#{content.to_s}\000"
|
67
|
-
@sock.
|
69
|
+
@sock.write(frame)
|
68
70
|
end
|
69
71
|
|
70
72
|
# Receive a standard STOMP frame.
|
71
73
|
def receive_frame(timeout = nil)
|
72
|
-
frame =
|
74
|
+
frame = parse_frame
|
75
|
+
return frame unless frame.nil?
|
73
76
|
# FIXME: we'll violate the timeout given if half a packet comes in at first, then more later.
|
74
77
|
until frame do
|
75
78
|
return nil if receive_data(timeout) == nil
|
@@ -105,7 +108,7 @@ module StompMq
|
|
105
108
|
# split the header text up into a proper hash
|
106
109
|
header = {}
|
107
110
|
header_text.split("\n").each do |keyval|
|
108
|
-
key,val = keyval.split(':')
|
111
|
+
key,val = keyval.split(':', 2)
|
109
112
|
header[key] = val
|
110
113
|
end
|
111
114
|
|
@@ -132,8 +135,6 @@ module StompMq
|
|
132
135
|
return StompMq::Frame.new(cmd, header, content)
|
133
136
|
end
|
134
137
|
|
135
|
-
|
136
|
-
@buffer = buffer
|
137
|
-
end
|
138
|
+
attr_accessor :buffer
|
138
139
|
end
|
139
140
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: StompMq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarah Nordstrom
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-12 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|