omq 0.5.1 → 0.6.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +173 -0
- data/README.md +21 -19
- data/exe/omq +6 -0
- data/lib/omq/cli/base_runner.rb +423 -0
- data/lib/omq/cli/channel.rb +8 -0
- data/lib/omq/cli/client_server.rb +106 -0
- data/lib/omq/cli/config.rb +51 -0
- data/lib/omq/cli/formatter.rb +75 -0
- data/lib/omq/cli/pair.rb +31 -0
- data/lib/omq/cli/peer.rb +8 -0
- data/lib/omq/cli/pipe.rb +249 -0
- data/lib/omq/cli/pub_sub.rb +14 -0
- data/lib/omq/cli/push_pull.rb +14 -0
- data/lib/omq/cli/radio_dish.rb +27 -0
- data/lib/omq/cli/req_rep.rb +77 -0
- data/lib/omq/cli/router_dealer.rb +70 -0
- data/lib/omq/cli/scatter_gather.rb +14 -0
- data/lib/omq/cli.rb +444 -0
- data/lib/omq/pub_sub.rb +2 -2
- data/lib/omq/radio_dish.rb +2 -2
- data/lib/omq/socket.rb +74 -27
- data/lib/omq/version.rb +1 -1
- data/lib/omq/zmtp/connection.rb +24 -3
- data/lib/omq/zmtp/engine.rb +179 -17
- data/lib/omq/zmtp/options.rb +4 -3
- data/lib/omq/zmtp/reactor.rb +10 -5
- data/lib/omq/zmtp/routing/channel.rb +8 -2
- data/lib/omq/zmtp/routing/fan_out.rb +38 -8
- data/lib/omq/zmtp/routing/pair.rb +8 -2
- data/lib/omq/zmtp/routing/peer.rb +7 -1
- data/lib/omq/zmtp/routing/push.rb +14 -7
- data/lib/omq/zmtp/routing/radio.rb +32 -11
- data/lib/omq/zmtp/routing/rep.rb +11 -7
- data/lib/omq/zmtp/routing/req.rb +1 -2
- data/lib/omq/zmtp/routing/round_robin.rb +35 -1
- data/lib/omq/zmtp/routing/router.rb +7 -1
- data/lib/omq/zmtp/routing/scatter.rb +16 -3
- data/lib/omq/zmtp/routing/server.rb +7 -1
- data/lib/omq/zmtp/routing/xsub.rb +7 -1
- data/lib/omq/zmtp/transport/inproc.rb +40 -5
- data/lib/omq/zmtp/transport/ipc.rb +9 -7
- data/lib/omq/zmtp/transport/tcp.rb +14 -7
- data/lib/omq/zmtp/writable.rb +21 -4
- data/lib/omq.rb +7 -0
- metadata +18 -3
- data/exe/omqcat +0 -532
|
@@ -46,6 +46,7 @@ module OMQ
|
|
|
46
46
|
Listener.new(endpoint)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
|
|
49
50
|
# Connects to a bound inproc endpoint.
|
|
50
51
|
#
|
|
51
52
|
# @param endpoint [String] e.g. "inproc://my-endpoint"
|
|
@@ -76,6 +77,7 @@ module OMQ
|
|
|
76
77
|
establish_link(engine, bound_engine, endpoint)
|
|
77
78
|
end
|
|
78
79
|
|
|
80
|
+
|
|
79
81
|
# Removes a bound endpoint from the registry.
|
|
80
82
|
#
|
|
81
83
|
# @param endpoint [String]
|
|
@@ -85,6 +87,7 @@ module OMQ
|
|
|
85
87
|
@mutex.synchronize { @registry.delete(endpoint) }
|
|
86
88
|
end
|
|
87
89
|
|
|
90
|
+
|
|
88
91
|
# Resets the registry. Used in tests.
|
|
89
92
|
#
|
|
90
93
|
# @return [void]
|
|
@@ -96,8 +99,17 @@ module OMQ
|
|
|
96
99
|
end
|
|
97
100
|
end
|
|
98
101
|
|
|
102
|
+
|
|
99
103
|
private
|
|
100
104
|
|
|
105
|
+
|
|
106
|
+
# Wires up a client-server inproc pipe pair after validating
|
|
107
|
+
# that the two socket types are compatible.
|
|
108
|
+
#
|
|
109
|
+
# @param client_engine [Engine] the connecting engine
|
|
110
|
+
# @param server_engine [Engine] the bound engine
|
|
111
|
+
# @param endpoint [String] the inproc endpoint name
|
|
112
|
+
#
|
|
101
113
|
def establish_link(client_engine, server_engine, endpoint)
|
|
102
114
|
client_type = client_engine.socket_type
|
|
103
115
|
server_type = server_engine.socket_type
|
|
@@ -138,8 +150,15 @@ module OMQ
|
|
|
138
150
|
server_engine.connection_ready(server_pipe, endpoint: endpoint)
|
|
139
151
|
end
|
|
140
152
|
|
|
153
|
+
|
|
154
|
+
# Spawns a background task that periodically retries
|
|
155
|
+
# #establish_link until the endpoint appears in the registry.
|
|
156
|
+
#
|
|
157
|
+
# @param endpoint [String] the inproc endpoint name
|
|
158
|
+
# @param engine [Engine] the connecting engine
|
|
159
|
+
#
|
|
141
160
|
def start_connect_retry(endpoint, engine)
|
|
142
|
-
Reactor.spawn_pump do
|
|
161
|
+
Reactor.spawn_pump(annotation: "reconnect") do
|
|
143
162
|
ri = engine.options.reconnect_interval
|
|
144
163
|
ivl = ri.is_a?(Range) ? ri.begin : ri
|
|
145
164
|
loop do
|
|
@@ -161,12 +180,14 @@ module OMQ
|
|
|
161
180
|
#
|
|
162
181
|
attr_reader :endpoint
|
|
163
182
|
|
|
183
|
+
|
|
164
184
|
# @param endpoint [String]
|
|
165
185
|
#
|
|
166
186
|
def initialize(endpoint)
|
|
167
187
|
@endpoint = endpoint
|
|
168
188
|
end
|
|
169
189
|
|
|
190
|
+
|
|
170
191
|
# Stops the listener by removing it from the registry.
|
|
171
192
|
#
|
|
172
193
|
# @return [void]
|
|
@@ -183,32 +204,38 @@ module OMQ
|
|
|
183
204
|
#
|
|
184
205
|
# When a routing strategy sets {#direct_recv_queue} on a pipe,
|
|
185
206
|
# {#send_message} enqueues directly into the peer's recv queue,
|
|
186
|
-
# bypassing the intermediate
|
|
187
|
-
#
|
|
207
|
+
# bypassing the intermediate pipe queues and the recv pump task.
|
|
208
|
+
# This reduces inproc from 3 queue hops to 2 (send_queue →
|
|
209
|
+
# recv_queue), eliminating the internal pipe queue in between.
|
|
188
210
|
#
|
|
189
211
|
class DirectPipe
|
|
190
212
|
# @return [String] peer's socket type
|
|
191
213
|
#
|
|
192
214
|
attr_reader :peer_socket_type
|
|
193
215
|
|
|
216
|
+
|
|
194
217
|
# @return [String] peer's identity
|
|
195
218
|
#
|
|
196
219
|
attr_reader :peer_identity
|
|
197
220
|
|
|
221
|
+
|
|
198
222
|
# @return [DirectPipe, nil] the other end of this pipe pair
|
|
199
223
|
#
|
|
200
224
|
attr_accessor :peer
|
|
201
225
|
|
|
226
|
+
|
|
202
227
|
# @return [Async::LimitedQueue, nil] when set, {#send_message}
|
|
203
228
|
# enqueues directly here instead of using the internal queue
|
|
204
229
|
#
|
|
205
230
|
attr_reader :direct_recv_queue
|
|
206
231
|
|
|
232
|
+
|
|
207
233
|
# @return [Proc, nil] optional transform applied before
|
|
208
234
|
# enqueuing into {#direct_recv_queue}
|
|
209
235
|
#
|
|
210
236
|
attr_accessor :direct_recv_transform
|
|
211
237
|
|
|
238
|
+
|
|
212
239
|
# @param send_queue [Async::Queue, nil] outgoing command queue
|
|
213
240
|
# (nil for non-PUB/SUB types that don't exchange commands)
|
|
214
241
|
# @param receive_queue [Async::Queue, nil] incoming command queue
|
|
@@ -227,6 +254,7 @@ module OMQ
|
|
|
227
254
|
@pending_direct = nil
|
|
228
255
|
end
|
|
229
256
|
|
|
257
|
+
|
|
230
258
|
# Sets the direct recv queue. Drains any messages that were
|
|
231
259
|
# buffered before the queue was available.
|
|
232
260
|
#
|
|
@@ -240,6 +268,7 @@ module OMQ
|
|
|
240
268
|
end
|
|
241
269
|
end
|
|
242
270
|
|
|
271
|
+
|
|
243
272
|
# Sends a multi-frame message.
|
|
244
273
|
#
|
|
245
274
|
# When {#direct_recv_queue} is set (inproc fast path), the
|
|
@@ -252,24 +281,27 @@ module OMQ
|
|
|
252
281
|
def send_message(parts)
|
|
253
282
|
raise IOError, "closed" if @closed
|
|
254
283
|
if @direct_recv_queue
|
|
255
|
-
msg = @direct_recv_transform ? @direct_recv_transform.call(parts) : parts
|
|
284
|
+
msg = @direct_recv_transform ? @direct_recv_transform.call(parts).freeze : parts
|
|
256
285
|
@direct_recv_queue.enqueue(msg)
|
|
257
286
|
elsif @send_queue
|
|
258
287
|
@send_queue.enqueue(parts)
|
|
259
288
|
else
|
|
260
|
-
msg = @direct_recv_transform ? @direct_recv_transform.call(parts) : parts
|
|
289
|
+
msg = @direct_recv_transform ? @direct_recv_transform.call(parts).freeze : parts
|
|
261
290
|
(@pending_direct ||= []) << msg
|
|
262
291
|
end
|
|
263
292
|
end
|
|
264
293
|
|
|
294
|
+
|
|
265
295
|
alias write_message send_message
|
|
266
296
|
|
|
297
|
+
|
|
267
298
|
# No-op — inproc has no IO buffer to flush.
|
|
268
299
|
#
|
|
269
300
|
# @return [void]
|
|
270
301
|
#
|
|
271
302
|
def flush = nil
|
|
272
303
|
|
|
304
|
+
|
|
273
305
|
# Receives a multi-frame message.
|
|
274
306
|
#
|
|
275
307
|
# @return [Array<String>]
|
|
@@ -281,6 +313,7 @@ module OMQ
|
|
|
281
313
|
msg
|
|
282
314
|
end
|
|
283
315
|
|
|
316
|
+
|
|
284
317
|
# Sends a command via the internal command queue.
|
|
285
318
|
# Only available for PUB/SUB-family pipes.
|
|
286
319
|
#
|
|
@@ -292,6 +325,7 @@ module OMQ
|
|
|
292
325
|
@send_queue.enqueue([:command, command])
|
|
293
326
|
end
|
|
294
327
|
|
|
328
|
+
|
|
295
329
|
# Reads one command frame from the internal command queue.
|
|
296
330
|
# Used by PUB/XPUB subscription listeners.
|
|
297
331
|
#
|
|
@@ -308,6 +342,7 @@ module OMQ
|
|
|
308
342
|
end
|
|
309
343
|
end
|
|
310
344
|
|
|
345
|
+
|
|
311
346
|
# Closes this pipe end.
|
|
312
347
|
#
|
|
313
348
|
# @return [void]
|
|
@@ -28,16 +28,11 @@ module OMQ
|
|
|
28
28
|
|
|
29
29
|
server = UNIXServer.new(sock_path)
|
|
30
30
|
|
|
31
|
-
accept_task = Reactor.spawn_pump do
|
|
31
|
+
accept_task = Reactor.spawn_pump(annotation: "ipc accept #{endpoint}") do
|
|
32
32
|
loop do
|
|
33
33
|
client = server.accept
|
|
34
|
-
|
|
34
|
+
Async::Task.current.defer_stop do
|
|
35
35
|
engine.handle_accepted(IO::Stream::Buffered.wrap(client), endpoint: endpoint)
|
|
36
|
-
rescue ProtocolError, *ZMTP::CONNECTION_LOST
|
|
37
|
-
# peer disconnected during handshake
|
|
38
|
-
rescue
|
|
39
|
-
client&.close rescue nil
|
|
40
|
-
raise
|
|
41
36
|
end
|
|
42
37
|
end
|
|
43
38
|
rescue IOError
|
|
@@ -92,6 +87,12 @@ module OMQ
|
|
|
92
87
|
#
|
|
93
88
|
attr_reader :endpoint
|
|
94
89
|
|
|
90
|
+
|
|
91
|
+
# @param endpoint [String] the IPC endpoint URI
|
|
92
|
+
# @param server [UNIXServer]
|
|
93
|
+
# @param accept_task [#stop] the accept loop handle
|
|
94
|
+
# @param path [String] filesystem or abstract namespace path
|
|
95
|
+
#
|
|
95
96
|
def initialize(endpoint, server, accept_task, path)
|
|
96
97
|
@endpoint = endpoint
|
|
97
98
|
@server = server
|
|
@@ -99,6 +100,7 @@ module OMQ
|
|
|
99
100
|
@path = path
|
|
100
101
|
end
|
|
101
102
|
|
|
103
|
+
|
|
102
104
|
# Stops the listener.
|
|
103
105
|
#
|
|
104
106
|
def stop
|
|
@@ -25,16 +25,11 @@ module OMQ
|
|
|
25
25
|
host_part = host.include?(":") ? "[#{host}]" : host
|
|
26
26
|
resolved = "tcp://#{host_part}:#{actual_port}"
|
|
27
27
|
|
|
28
|
-
accept_task = Reactor.spawn_pump do
|
|
28
|
+
accept_task = Reactor.spawn_pump(annotation: "tcp accept #{resolved}") do
|
|
29
29
|
loop do
|
|
30
30
|
client = server.accept
|
|
31
|
-
|
|
31
|
+
Async::Task.current.defer_stop do
|
|
32
32
|
engine.handle_accepted(IO::Stream::Buffered.wrap(client), endpoint: resolved)
|
|
33
|
-
rescue ProtocolError, *ZMTP::CONNECTION_LOST
|
|
34
|
-
# peer disconnected during handshake
|
|
35
|
-
rescue
|
|
36
|
-
client&.close rescue nil
|
|
37
|
-
raise
|
|
38
33
|
end
|
|
39
34
|
end
|
|
40
35
|
rescue IOError
|
|
@@ -58,6 +53,11 @@ module OMQ
|
|
|
58
53
|
|
|
59
54
|
private
|
|
60
55
|
|
|
56
|
+
# Parses a TCP endpoint URI into host and port.
|
|
57
|
+
#
|
|
58
|
+
# @param endpoint [String]
|
|
59
|
+
# @return [Array(String, Integer)]
|
|
60
|
+
#
|
|
61
61
|
def parse_endpoint(endpoint)
|
|
62
62
|
uri = URI.parse(endpoint)
|
|
63
63
|
[uri.hostname, uri.port]
|
|
@@ -75,6 +75,12 @@ module OMQ
|
|
|
75
75
|
#
|
|
76
76
|
attr_reader :port
|
|
77
77
|
|
|
78
|
+
|
|
79
|
+
# @param endpoint [String] resolved endpoint URI
|
|
80
|
+
# @param server [TCPServer]
|
|
81
|
+
# @param accept_task [#stop] the accept loop handle
|
|
82
|
+
# @param port [Integer] bound port number
|
|
83
|
+
#
|
|
78
84
|
def initialize(endpoint, server, accept_task, port)
|
|
79
85
|
@endpoint = endpoint
|
|
80
86
|
@server = server
|
|
@@ -82,6 +88,7 @@ module OMQ
|
|
|
82
88
|
@port = port
|
|
83
89
|
end
|
|
84
90
|
|
|
91
|
+
|
|
85
92
|
# Stops the listener.
|
|
86
93
|
#
|
|
87
94
|
def stop
|
data/lib/omq/zmtp/writable.rb
CHANGED
|
@@ -14,10 +14,7 @@ module OMQ
|
|
|
14
14
|
# @raise [IO::TimeoutError] if write_timeout exceeded
|
|
15
15
|
#
|
|
16
16
|
def send(message)
|
|
17
|
-
parts = message
|
|
18
|
-
raise ArgumentError, "message has no parts" if parts.empty?
|
|
19
|
-
parts = parts.map { |p| p.b.freeze }
|
|
20
|
-
|
|
17
|
+
parts = freeze_message(message)
|
|
21
18
|
with_timeout(@options.write_timeout) { @engine.enqueue_send(parts) }
|
|
22
19
|
self
|
|
23
20
|
end
|
|
@@ -31,6 +28,26 @@ module OMQ
|
|
|
31
28
|
send(message)
|
|
32
29
|
end
|
|
33
30
|
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
# Converts a message into a frozen array of frozen binary strings.
|
|
34
|
+
#
|
|
35
|
+
# @param message [String, Array<String>]
|
|
36
|
+
# @return [Array<String>] frozen array of frozen binary strings
|
|
37
|
+
#
|
|
38
|
+
def freeze_message(message)
|
|
39
|
+
parts = message.is_a?(Array) ? message : [message]
|
|
40
|
+
raise ArgumentError, "message has no parts" if parts.empty?
|
|
41
|
+
if parts.frozen?
|
|
42
|
+
parts = parts.map { |p| p.to_str.b.freeze }
|
|
43
|
+
else
|
|
44
|
+
parts.map! { |p| p.to_str.b.freeze }
|
|
45
|
+
end
|
|
46
|
+
parts.freeze
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
public
|
|
50
|
+
|
|
34
51
|
# Waits until the socket is writable.
|
|
35
52
|
#
|
|
36
53
|
# @param timeout [Numeric, nil] timeout in seconds
|
data/lib/omq.rb
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
#
|
|
11
11
|
|
|
12
12
|
require_relative "omq/version"
|
|
13
|
+
|
|
14
|
+
module OMQ
|
|
15
|
+
# Raised when an internal pump task crashes unexpectedly.
|
|
16
|
+
# The socket is no longer usable; the original error is available via #cause.
|
|
17
|
+
#
|
|
18
|
+
class SocketDeadError < RuntimeError; end
|
|
19
|
+
end
|
|
13
20
|
require_relative "omq/zmtp"
|
|
14
21
|
require_relative "omq/socket"
|
|
15
22
|
require_relative "omq/req_rep"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patrik Wenger
|
|
@@ -42,16 +42,31 @@ description: Pure Ruby implementation of the ZMTP 3.1 wire protocol (ZeroMQ) usi
|
|
|
42
42
|
email:
|
|
43
43
|
- paddor@gmail.com
|
|
44
44
|
executables:
|
|
45
|
-
-
|
|
45
|
+
- omq
|
|
46
46
|
extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
|
48
48
|
files:
|
|
49
49
|
- CHANGELOG.md
|
|
50
50
|
- LICENSE
|
|
51
51
|
- README.md
|
|
52
|
-
- exe/
|
|
52
|
+
- exe/omq
|
|
53
53
|
- lib/omq.rb
|
|
54
54
|
- lib/omq/channel.rb
|
|
55
|
+
- lib/omq/cli.rb
|
|
56
|
+
- lib/omq/cli/base_runner.rb
|
|
57
|
+
- lib/omq/cli/channel.rb
|
|
58
|
+
- lib/omq/cli/client_server.rb
|
|
59
|
+
- lib/omq/cli/config.rb
|
|
60
|
+
- lib/omq/cli/formatter.rb
|
|
61
|
+
- lib/omq/cli/pair.rb
|
|
62
|
+
- lib/omq/cli/peer.rb
|
|
63
|
+
- lib/omq/cli/pipe.rb
|
|
64
|
+
- lib/omq/cli/pub_sub.rb
|
|
65
|
+
- lib/omq/cli/push_pull.rb
|
|
66
|
+
- lib/omq/cli/radio_dish.rb
|
|
67
|
+
- lib/omq/cli/req_rep.rb
|
|
68
|
+
- lib/omq/cli/router_dealer.rb
|
|
69
|
+
- lib/omq/cli/scatter_gather.rb
|
|
55
70
|
- lib/omq/client_server.rb
|
|
56
71
|
- lib/omq/pair.rb
|
|
57
72
|
- lib/omq/peer.rb
|