omq 0.4.2 → 0.5.1

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.
@@ -12,6 +12,25 @@ module OMQ
12
12
  # the socket's send/recv queues.
13
13
  #
14
14
  module Routing
15
+ # Maximum messages to drain from the send queue per flush cycle.
16
+ MAX_SEND_BATCH = 64
17
+
18
+ # Drains up to +max+ additional messages from +queue+ into +batch+
19
+ # without blocking. Call after the initial blocking dequeue.
20
+ #
21
+ # @param queue [Async::LimitedQueue]
22
+ # @param batch [Array]
23
+ # @param max [Integer]
24
+ # @return [void]
25
+ #
26
+ def self.drain_send_queue(queue, batch, max = MAX_SEND_BATCH)
27
+ while batch.size < max
28
+ msg = queue.dequeue(timeout: 0)
29
+ break unless msg
30
+ batch << msg
31
+ end
32
+ end
33
+
15
34
  # Returns the routing strategy class for a socket type.
16
35
  #
17
36
  # @param socket_type [Symbol] e.g. :PAIR, :REQ
@@ -28,8 +47,16 @@ module OMQ
28
47
  when :SUB then Sub
29
48
  when :XPUB then XPub
30
49
  when :XSUB then XSub
31
- when :PUSH then Push
32
- when :PULL then Pull
50
+ when :PUSH then Push
51
+ when :PULL then Pull
52
+ when :CLIENT then Client
53
+ when :SERVER then Server
54
+ when :RADIO then Radio
55
+ when :DISH then Dish
56
+ when :SCATTER then Scatter
57
+ when :GATHER then Gather
58
+ when :PEER then Peer
59
+ when :CHANNEL then Channel
33
60
  else raise ArgumentError, "unknown socket type: #{socket_type}"
34
61
  end
35
62
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OMQ
4
+ module ZMTP
5
+ # Mixin that rejects multipart messages.
6
+ #
7
+ # All draft socket types (CLIENT, SERVER, RADIO, DISH, SCATTER,
8
+ # GATHER, PEER, CHANNEL) require single-frame messages for
9
+ # thread-safe atomic operations.
10
+ #
11
+ module SingleFrame
12
+ def send(message)
13
+ if message.is_a?(Array) && message.size > 1
14
+ raise ArgumentError, "#{self.class} does not support multipart messages"
15
+ end
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
@@ -17,7 +17,7 @@ module OMQ
17
17
  module Inproc
18
18
  # Socket types that exchange commands (SUBSCRIBE/CANCEL) over inproc.
19
19
  #
20
- COMMAND_TYPES = %i[PUB SUB XPUB XSUB].freeze
20
+ COMMAND_TYPES = %i[PUB SUB XPUB XSUB RADIO DISH].freeze
21
21
 
22
22
  # Global registry of bound inproc endpoints.
23
23
  #
@@ -262,6 +262,14 @@ module OMQ
262
262
  end
263
263
  end
264
264
 
265
+ alias write_message send_message
266
+
267
+ # No-op — inproc has no IO buffer to flush.
268
+ #
269
+ # @return [void]
270
+ #
271
+ def flush = nil
272
+
265
273
  # Receives a multi-frame message.
266
274
  #
267
275
  # @return [Array<String>]
@@ -14,8 +14,16 @@ module OMQ
14
14
  SUB: %i[PUB XPUB].freeze,
15
15
  XPUB: %i[SUB XSUB].freeze,
16
16
  XSUB: %i[PUB XPUB].freeze,
17
- PUSH: %i[PULL].freeze,
18
- PULL: %i[PUSH].freeze,
17
+ PUSH: %i[PULL].freeze,
18
+ PULL: %i[PUSH].freeze,
19
+ CLIENT: %i[SERVER].freeze,
20
+ SERVER: %i[CLIENT].freeze,
21
+ RADIO: %i[DISH].freeze,
22
+ DISH: %i[RADIO].freeze,
23
+ SCATTER: %i[GATHER].freeze,
24
+ GATHER: %i[SCATTER].freeze,
25
+ PEER: %i[PEER].freeze,
26
+ CHANNEL: %i[CHANNEL].freeze,
19
27
  }.freeze
20
28
  end
21
29
  end
data/lib/omq/zmtp.rb CHANGED
@@ -63,6 +63,15 @@ require_relative "zmtp/routing/xpub"
63
63
  require_relative "zmtp/routing/xsub"
64
64
  require_relative "zmtp/routing/push"
65
65
  require_relative "zmtp/routing/pull"
66
+ require_relative "zmtp/routing/scatter"
67
+ require_relative "zmtp/routing/gather"
68
+ require_relative "zmtp/routing/channel"
69
+ require_relative "zmtp/routing/client"
70
+ require_relative "zmtp/routing/server"
71
+ require_relative "zmtp/routing/radio"
72
+ require_relative "zmtp/routing/dish"
73
+ require_relative "zmtp/routing/peer"
74
+ require_relative "zmtp/single_frame"
66
75
  require_relative "zmtp/engine"
67
76
  require_relative "zmtp/readable"
68
77
  require_relative "zmtp/writable"
data/lib/omq.rb CHANGED
@@ -17,6 +17,11 @@ require_relative "omq/router_dealer"
17
17
  require_relative "omq/pub_sub"
18
18
  require_relative "omq/push_pull"
19
19
  require_relative "omq/pair"
20
+ require_relative "omq/scatter_gather"
21
+ require_relative "omq/channel"
22
+ require_relative "omq/client_server"
23
+ require_relative "omq/radio_dish"
24
+ require_relative "omq/peer"
20
25
 
21
26
  # For the purists.
22
27
  ØMQ = OMQ
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.2
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -51,11 +51,16 @@ files:
51
51
  - README.md
52
52
  - exe/omqcat
53
53
  - lib/omq.rb
54
+ - lib/omq/channel.rb
55
+ - lib/omq/client_server.rb
54
56
  - lib/omq/pair.rb
57
+ - lib/omq/peer.rb
55
58
  - lib/omq/pub_sub.rb
56
59
  - lib/omq/push_pull.rb
60
+ - lib/omq/radio_dish.rb
57
61
  - lib/omq/req_rep.rb
58
62
  - lib/omq/router_dealer.rb
63
+ - lib/omq/scatter_gather.rb
59
64
  - lib/omq/socket.rb
60
65
  - lib/omq/version.rb
61
66
  - lib/omq/zmtp.rb
@@ -70,19 +75,28 @@ files:
70
75
  - lib/omq/zmtp/reactor.rb
71
76
  - lib/omq/zmtp/readable.rb
72
77
  - lib/omq/zmtp/routing.rb
78
+ - lib/omq/zmtp/routing/channel.rb
79
+ - lib/omq/zmtp/routing/client.rb
73
80
  - lib/omq/zmtp/routing/dealer.rb
81
+ - lib/omq/zmtp/routing/dish.rb
74
82
  - lib/omq/zmtp/routing/fan_out.rb
83
+ - lib/omq/zmtp/routing/gather.rb
75
84
  - lib/omq/zmtp/routing/pair.rb
85
+ - lib/omq/zmtp/routing/peer.rb
76
86
  - lib/omq/zmtp/routing/pub.rb
77
87
  - lib/omq/zmtp/routing/pull.rb
78
88
  - lib/omq/zmtp/routing/push.rb
89
+ - lib/omq/zmtp/routing/radio.rb
79
90
  - lib/omq/zmtp/routing/rep.rb
80
91
  - lib/omq/zmtp/routing/req.rb
81
92
  - lib/omq/zmtp/routing/round_robin.rb
82
93
  - lib/omq/zmtp/routing/router.rb
94
+ - lib/omq/zmtp/routing/scatter.rb
95
+ - lib/omq/zmtp/routing/server.rb
83
96
  - lib/omq/zmtp/routing/sub.rb
84
97
  - lib/omq/zmtp/routing/xpub.rb
85
98
  - lib/omq/zmtp/routing/xsub.rb
99
+ - lib/omq/zmtp/single_frame.rb
86
100
  - lib/omq/zmtp/transport/inproc.rb
87
101
  - lib/omq/zmtp/transport/ipc.rb
88
102
  - lib/omq/zmtp/transport/tcp.rb