simplepubsub 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/simplepubsub.rb +24 -17
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfb14c303c576a5fc3ca6c8160ef526f306bc87b
|
4
|
+
data.tar.gz: 102d5dbfa5f4925c157c7f601057c81ab12e4bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b2c22abd456d71018b03cd589db440307cde52e63a557d121dd49e700a6a1d3b1810c3f2a35af3f5fe5e6e7d3be2526f6bfd19a94e4ead06c24d166a6a855b
|
7
|
+
data.tar.gz: 4107e7cbcca9f0328b0495fe3612d646cca0b8a410297a8f1e70e0bf713e0a2d5afe136edb7522eccfeb90532ba0008d7b015bcd8f6aaa8d2bce50742ec7600e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/simplepubsub.rb
CHANGED
@@ -9,7 +9,7 @@ require 'xml-registry'
|
|
9
9
|
|
10
10
|
module SimplePubSub
|
11
11
|
|
12
|
-
class
|
12
|
+
class Broker
|
13
13
|
|
14
14
|
def self.start(host: '0.0.0.0', port: 59000)
|
15
15
|
|
@@ -89,7 +89,7 @@ module SimplePubSub
|
|
89
89
|
|
90
90
|
attr_reader :proc, :topic, :message
|
91
91
|
|
92
|
-
def get(topic, &get_proc)
|
92
|
+
def get(topic, options={}, &get_proc)
|
93
93
|
|
94
94
|
@topic = 'subscribe to topic'
|
95
95
|
@proc, @message = get_proc, topic
|
@@ -104,7 +104,7 @@ module SimplePubSub
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
def self.connect(hostname, port: '59000', &connect_blk)
|
107
|
+
def self.connect(hostname, port: '59000', retry_count: nil, &connect_blk)
|
108
108
|
|
109
109
|
pubsub = PubSub.new
|
110
110
|
connect_blk.call(pubsub)
|
@@ -113,6 +113,7 @@ module SimplePubSub
|
|
113
113
|
|
114
114
|
ws.onopen do
|
115
115
|
puts "Connected"
|
116
|
+
retry_count = 0
|
116
117
|
end
|
117
118
|
|
118
119
|
ws.onmessage do |msg, type|
|
@@ -124,21 +125,27 @@ module SimplePubSub
|
|
124
125
|
end
|
125
126
|
|
126
127
|
ws.onclose do
|
127
|
-
puts "Disconnected"
|
128
128
|
|
129
|
-
# reconnect within a minute
|
130
|
-
seconds = rand(60)
|
131
129
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
-
puts
|
130
|
+
if retry_count and retry_count <= 3 then
|
131
|
+
puts "Disconnected"
|
132
|
+
|
133
|
+
# reconnect within a minute
|
134
|
+
seconds = rand(60)
|
139
135
|
|
136
|
+
seconds.downto(1) do |i|
|
137
|
+
s = "reconnecting in %s seconds" % i;
|
138
|
+
print s
|
139
|
+
sleep 1
|
140
|
+
print "\b" * s.length
|
141
|
+
end
|
142
|
+
puts
|
140
143
|
|
141
|
-
|
144
|
+
|
145
|
+
self.connect hostname, port: port, retry_count: retry_count+1, &connect_blk
|
146
|
+
else
|
147
|
+
puts 'Unable to connect'
|
148
|
+
end
|
142
149
|
end
|
143
150
|
|
144
151
|
EventMachine.next_tick do
|
@@ -156,14 +163,14 @@ module SimplePubSub
|
|
156
163
|
# attempt to run a websocket assuming the EventMachine is
|
157
164
|
# already running
|
158
165
|
|
159
|
-
ws = c.connect(params
|
166
|
+
ws = c.connect(params)
|
160
167
|
blk.call ws, pubsub, em_already_running = true
|
161
168
|
rescue
|
162
169
|
|
163
170
|
thread = Thread.new do
|
164
171
|
EM.run do
|
165
172
|
|
166
|
-
ws = c.connect(params
|
173
|
+
ws = c.connect(params)
|
167
174
|
blk.call(ws, pubsub, em_already_running = false)
|
168
175
|
end
|
169
176
|
end
|
@@ -177,7 +184,7 @@ end
|
|
177
184
|
if __FILE__ == $0 then
|
178
185
|
|
179
186
|
# Server example
|
180
|
-
SimplePubSub::
|
187
|
+
SimplePubSub::Broker.start
|
181
188
|
|
182
189
|
=begin
|
183
190
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|