simplepubsub 1.1.14 → 1.2.0
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 +1 -115
- data.tar.gz.sig +0 -0
- metadata +19 -39
- 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: 0b7490e4aeeacc8821ee174e35b70df351298ec6
|
4
|
+
data.tar.gz: fa80ab134536a7283cf6f8575962d8915d842aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c65ceeb1fa9945436d03ca63be5246d27558864b4086ee66be9edfe9e8cb1a6fc4bcf97619b68e08468199c7d2ab11d7bfb83b66a0e640fd17c4d670ff7865
|
7
|
+
data.tar.gz: 11021d83a5849aeb2cac03ed02bfc5ca82fc1045c9dadf254461f834f9e2bf0714eb1c11998726e1cbb1908c1112624c8c88434758da764327481c9fc77b0a76
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/simplepubsub.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
# file: simplepubsub.rb
|
4
4
|
|
5
5
|
require 'websocket-eventmachine-server'
|
6
|
-
require 'websocket-eventmachine-client'
|
7
6
|
require 'xml-registry'
|
8
7
|
|
9
8
|
|
@@ -84,123 +83,10 @@ module SimplePubSub
|
|
84
83
|
end
|
85
84
|
end
|
86
85
|
|
87
|
-
class Client
|
88
|
-
|
89
|
-
class PubSub
|
90
|
-
|
91
|
-
attr_reader :proc, :topic, :message
|
92
|
-
|
93
|
-
def get(topic, options={}, &get_proc)
|
94
|
-
|
95
|
-
@topic = 'subscribe to topic'
|
96
|
-
@proc, @message = get_proc, topic
|
97
|
-
end
|
98
|
-
|
99
|
-
def publish(*args)
|
100
|
-
|
101
|
-
topic, message = args.length > 1 ? args : args.first.split(':',2)
|
102
|
-
|
103
|
-
@topic, @message = topic, message
|
104
|
-
@proc = ->(_,_){}
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.connect(hostname, port: '59000', auto_retry: false, &connect_blk)
|
109
|
-
|
110
|
-
retry_count = nil
|
111
|
-
pubsub = PubSub.new
|
112
|
-
connect_blk.call(pubsub)
|
113
|
-
|
114
|
-
blk = lambda do |ws, pubsub, em_already_running|
|
115
|
-
|
116
|
-
ws.onopen do
|
117
|
-
puts "Connected"
|
118
|
-
retry_count = 0
|
119
|
-
end
|
120
|
-
|
121
|
-
ws.onmessage do |msg, type|
|
122
|
-
|
123
|
-
a = msg.split(/\s*:\s*/,2)
|
124
|
-
topic, message = a
|
125
|
-
EM.defer {pubsub.proc.call topic, message}
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
ws.onclose do
|
130
|
-
|
131
|
-
|
132
|
-
if auto_retry and retry_count and retry_count <= 3 then
|
133
|
-
puts "Disconnected"
|
134
|
-
|
135
|
-
# reconnect within a minute
|
136
|
-
seconds = rand(60)
|
137
|
-
|
138
|
-
seconds.downto(1) do |i|
|
139
|
-
s = "reconnecting in %s seconds" % i;
|
140
|
-
print s
|
141
|
-
sleep 1
|
142
|
-
print "\b" * s.length
|
143
|
-
end
|
144
|
-
puts
|
145
|
-
|
146
|
-
|
147
|
-
self.connect hostname, port: port, retry_count: retry_count+1, &connect_blk
|
148
|
-
else
|
149
|
-
puts 'Unable to connect' if auto_retry
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
EventMachine.next_tick do
|
154
|
-
ws.send pubsub.topic + ': ' + pubsub.message
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
address = hostname + ':' + port
|
160
|
-
params = {uri: 'ws://' + address}
|
161
|
-
c = WebSocket::EventMachine::Client
|
162
|
-
|
163
|
-
begin
|
164
|
-
|
165
|
-
# attempt to run a websocket assuming the EventMachine is
|
166
|
-
# already running
|
167
|
-
|
168
|
-
ws = c.connect(params)
|
169
|
-
blk.call ws, pubsub, em_already_running = true
|
170
|
-
rescue
|
171
|
-
|
172
|
-
thread = Thread.new do
|
173
|
-
EM.run do
|
174
|
-
|
175
|
-
ws = c.connect(params)
|
176
|
-
blk.call(ws, pubsub, em_already_running = false)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
thread.join
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
end
|
184
86
|
end
|
185
87
|
|
186
88
|
if __FILE__ == $0 then
|
187
89
|
|
188
|
-
# Server example
|
189
90
|
SimplePubSub::Broker.start
|
190
91
|
|
191
|
-
|
192
|
-
|
193
|
-
# Subscribe example
|
194
|
-
SimplePubSub::Client.connect('localhost') do |client|
|
195
|
-
client.get('test') do |topic, message|
|
196
|
-
puts "#{topic}: #{message}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Publish example
|
201
|
-
SimplePubSub::Client.connect('localhost') do |client|
|
202
|
-
client.publish('test', Time.now.to_s)
|
203
|
-
end
|
204
|
-
|
205
|
-
=end
|
206
|
-
end
|
92
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplepubsub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -12,26 +12,26 @@ cert_chain:
|
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
14
|
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
-
|
15
|
+
8ixkARkWAmV1MB4XDTE1MTAwOTA1MjkxNFoXDTE2MT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SDDWM5Y98HJLRzX+y+Xlech9W
|
29
|
+
TbQQDs4sT8Bw2w7g3IzXrlj1+XiytFwLUTauE6+FdhhSaCvJBzwV7VhC3eAeIYvx
|
30
|
+
hA7pXn7vTl8mPLKS2zY1xziPJQA+hYj+5EBeND89eWFYPR9f+Qc+/KM91PQU/29K
|
31
|
+
kIiwfbNsuzjbgWzdKm7Rmqd2eqM34Vn+TRGopqMQ8lTxyrQst+2LQnDV0BVrkl+h
|
32
|
+
GtYDHIOX5GPNIg==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-
|
34
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: websocket-eventmachine-server
|
@@ -53,26 +53,6 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 1.0.1
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: websocket-eventmachine-client
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - "~>"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '1.0'
|
63
|
-
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: 1.1.0
|
66
|
-
type: :runtime
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: !ruby/object:Gem::Requirement
|
69
|
-
requirements:
|
70
|
-
- - "~>"
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: '1.0'
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.1.0
|
76
56
|
- !ruby/object:Gem::Dependency
|
77
57
|
name: xml-registry
|
78
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,8 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
100
|
version: '0'
|
121
101
|
requirements: []
|
122
102
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.4.
|
103
|
+
rubygems_version: 2.4.8
|
124
104
|
signing_key:
|
125
105
|
specification_version: 4
|
126
|
-
summary:
|
106
|
+
summary: The SimplePubSub gem is a messaging broker which uses Eventmachine + websockets.
|
127
107
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|