omq-cli 0.18.0 → 0.20.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c13378d48e8072d5537c35b476340431cd3c735f4a9ef6bea93036b776da2fa5
4
- data.tar.gz: 6fffa2d883b8a332b81307c874bc59ac6600997bc2cf954159aa82c14db9ed1a
3
+ metadata.gz: ede67317b3727323e0de601f26a6cb93112a645d0c78f63b77902efad8847bb7
4
+ data.tar.gz: 00aa53d8b0de26cb145562c32854eb6e428533f0a59bf86c1984b579070be743
5
5
  SHA512:
6
- metadata.gz: e35a88c00fdfbee35163bfc6bf7059f5b89fa97c735523932e76a61b87eafb84bbb9be29ba918cc81f394ff0879cd8978d5075d84ef234d75b30bde09b458c28
7
- data.tar.gz: 728b01ef1873bf8f7651f7cc56f0c88c6d8d147a1ee5a0b42c99b6eb0762b9c8159d921c1db6a0dd352cd2c040529bbd33d0b1be527997fc70156595fe1b2bfc
6
+ metadata.gz: cb3f2520d519501aa5a92f74a0429295e3e6f7340787ccd796ceddcdc78c7264fb4ca5b55954ae3b9e70095deea463cb06aa32a782bd7cef049961dde936b253
7
+ data.tar.gz: db1669fa2a29536f827557572f6bc07d238a6bef118bfd62b3eec138f80aee3664f192c2a92e8fc2139941a508c2f3d2213c758f06e4ef419a459452cf2411c5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.20.0 - 2026-11-26
6
+
7
+ - `-z` and `--compress=zstd` compress at an adaptive level: each connection
8
+ steps within -7..4 toward speed when compression is the limit and toward
9
+ ratio when the link is. They used a fixed level -3. `pub` and `radio`
10
+ keep -1, and `-Z` and `--compress=zstd:LEVEL` a fixed level.
11
+ - Require `omq-zstd ~> 0.6` and `omq-lz4 ~> 0.5`.
12
+
13
+ ## 0.19.1 - 2026-08-08
14
+
15
+ - Added `OMQ_BACKEND` support for choosing `ruby`, `rust`, or `libzmq`
16
+ as the default socket backend.
17
+ - Made `omq -v` print the effective socket backend at startup.
18
+
19
+ ## 0.19.0 — 2026-08-03
20
+
21
+ - **Rust backend selection via `--backend rust`.** Loads
22
+ `omq-backend-rust` and passes `backend: :rust` to socket
23
+ constructors.
24
+ - **Monorepo import.** `omq-cli` now lives under `gems/omq-cli` in
25
+ `omq.rb` and participates in monorepo test and release tasks.
26
+
3
27
  ## 0.17.1 — 2026-05-04
4
28
 
5
29
  - bump deps
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/omq-cli?color=e9573f)](https://rubygems.org/gems/omq-cli)
4
4
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
5
- [![Ruby](https://img.shields.io/badge/Ruby-%3E%3D%203.3-CC342D?logo=ruby&logoColor=white)](https://www.ruby-lang.org)
5
+ [![Ruby](https://img.shields.io/badge/Ruby-%3E%3D%204.0-CC342D?logo=ruby&logoColor=white)](https://www.ruby-lang.org)
6
6
 
7
7
  A command-line tool that speaks every ZeroMQ socket pattern, transforms
8
8
  messages with inline Ruby, parallelizes across Ractors, encrypts with CURVE,
@@ -75,6 +75,21 @@ omq push -c@work # IPC abstract namespace (@name → ipc://@
75
75
  Multiple endpoints are allowed — `omq pull -b tcp://:5557 -b tcp://:5558` binds both.
76
76
  Pipe takes two positional endpoints (input, output) or uses `--in`/`--out` for multiple per side.
77
77
 
78
+ ## Backends
79
+
80
+ The default backend is the pure Ruby engine.
81
+
82
+ | Flag | Backend |
83
+ |------|---------|
84
+ | `--backend ruby` | Pure Ruby backend, default |
85
+ | `--backend rust` | Rust backend from `omq-backend-rust` |
86
+ | `--backend libzmq` | libzmq backend from `omq-backend-libzmq` |
87
+ | `--backend ffi` or `--ffi` | Compatibility name for the libzmq backend |
88
+
89
+ Optional backends must be installed next to `omq-cli`.
90
+ Set `OMQ_BACKEND=ruby|rust|libzmq` to choose a default backend.
91
+ Use `-v` to print the effective backend at startup.
92
+
78
93
  ## Socket types
79
94
 
80
95
  ### Unidirectional (send-only / recv-only)
@@ -420,9 +435,9 @@ Both peers must pass `-z` (or otherwise opt into `zstd+tcp://`).
420
435
 
421
436
  | Flag | Effect |
422
437
  |------|--------|
423
- | `-z` | Compression at level **-3** (Zstd's fast strategy) |
424
- | `-Z` | Compression at level **3** (better ratio, more CPU) |
425
- | `--compress=LEVEL` | Custom level, e.g. `9`, `19`, `-1` |
438
+ | `-z` | Compression at an adaptive level: each connection steps within -7..4 toward speed when compression is the limit and toward ratio when the link is. `pub` and `radio` keep -1 |
439
+ | `-Z` | Compression at fixed level **3** (better ratio, more CPU) |
440
+ | `--compress=zstd:LEVEL` | Fixed level, e.g. `zstd:-1`, `zstd:4` |
426
441
 
427
442
  The sender auto-trains a dictionary from the first up-to-1000
428
443
  outgoing messages (or 100 KiB, whichever hits first), ships it inline
@@ -25,6 +25,7 @@ module OMQ
25
25
  # @return [void]
26
26
  def call(task)
27
27
  set_process_title
28
+ log_backend
28
29
  setup_socket
29
30
  start_event_monitor
30
31
  maybe_start_transient_monitor(task)
@@ -557,6 +558,11 @@ module OMQ
557
558
  end
558
559
 
559
560
 
561
+ def log_backend
562
+ log("backend: #{SocketSetup.backend_name(config)}")
563
+ end
564
+
565
+
560
566
  # Always attached so protocol-level disconnect events can kill
561
567
  # the socket. Verbose gating lives inside the callback:
562
568
  # -vv log connect/disconnect/retry/timeout events
@@ -277,7 +277,8 @@ module OMQ
277
277
  recv_maxsz: nil,
278
278
  curve_server: false,
279
279
  curve_server_key: nil,
280
- crypto: nil,
280
+ crypto: nil,
281
+ backend: :ruby,
281
282
  ffi: false,
282
283
  }.freeze
283
284
 
@@ -331,6 +332,7 @@ module OMQ
331
332
  def parse(argv)
332
333
  opts = DEFAULT_OPTS.transform_values { |v| v.is_a?(Array) ? v.dup : v }
333
334
  pipe_side = nil # nil = legacy positional mode; :in/:out = modal
335
+ explicit_backend = false
334
336
 
335
337
  parser = OptionParser.new do |o|
336
338
  o.banner = "Usage: omq TYPE [options]\n\n" \
@@ -437,10 +439,10 @@ module OMQ
437
439
  opts[:compress_level] = level
438
440
  end
439
441
  end
440
- o.on("-z", "Zstd compression (level -3, fast)") { set_compress.call(:zstd, -3) }
441
- o.on("-Z", "Zstd compression (level 3, better ratio)") { set_compress.call(:zstd, 3) }
442
- o.on("--lz4", "LZ4 compression (FAST)") { set_compress.call(:lz4, nil) }
443
- o.on("--compress=SPEC", "Explicit codec[:level], e.g. zstd, zstd:3, zstd:-1, lz4") do |v|
442
+ o.on("-z", "Zstd compression, level adapts to CPU and link (-7..4)") { set_compress.call(:zstd, nil) }
443
+ o.on("-Z", "Zstd compression, fixed level 3 (better ratio)") { set_compress.call(:zstd, 3) }
444
+ o.on("--lz4", "LZ4 compression (FAST)") { set_compress.call(:lz4, nil) }
445
+ o.on("--compress=SPEC", "Explicit codec[:level], e.g. zstd (adaptive), zstd:3, zstd:-1, lz4") do |v|
444
446
  codec, level = parse_compress_spec(v)
445
447
  set_compress.call(codec, level)
446
448
  end
@@ -462,8 +464,6 @@ module OMQ
462
464
  o.on("--curve-server-key KEY", "Enable CURVE as client (server's Z85 public key)") { |v| opts[:curve_server_key] = v }
463
465
  o.on("--crypto BACKEND", "Crypto backend: rbnacl (default) or nuckle (pure Ruby, DANGEROUS)") { |v| opts[:crypto] = v }
464
466
  o.separator " Install libsodium: apt install libsodium-dev / brew install libsodium"
465
- o.separator " Env vars: OMQ_SERVER_KEY (client), OMQ_SERVER_PUBLIC + OMQ_SERVER_SECRET (server)"
466
- o.separator " OMQ_CRYPTO (backend: rbnacl or nuckle)"
467
467
 
468
468
  o.separator "\nOther:"
469
469
  o.on("-v", "--verbose", "Verbosity: -v endpoints, -vv events, -vvv messages") { opts[:verbose] += 1 }
@@ -472,20 +472,22 @@ module OMQ
472
472
  }
473
473
  o.on("-q", "--quiet", "Suppress message output") { opts[:quiet] = true }
474
474
  o.on( "--transient", "Exit when all peers disconnect") { opts[:transient] = true }
475
- o.on( "--ffi", "Use libzmq FFI backend (requires omq-ffi gem + system libzmq 4.x)") do
476
- begin
477
- require "omq/ffi"
478
- rescue LoadError => e
479
- abort "omq: --ffi requires the omq-ffi gem and system libzmq 4.x (#{e.message})"
480
- end
475
+ o.on( "--backend BACKEND", %w[ruby rust libzmq ffi],
476
+ "Socket backend: ruby, rust, or libzmq") do |v|
477
+ backend = normalize_backend(v.to_sym)
478
+ load_socket_backend!(backend)
479
+ opts[:backend] = backend
480
+ opts[:ffi] = false
481
+ explicit_backend = true
482
+ end
483
+ o.on( "--ffi", "Alias for --backend libzmq") do
484
+ load_socket_backend!(:libzmq)
485
+ opts[:backend] = :libzmq
481
486
  opts[:ffi] = true
487
+ explicit_backend = true
482
488
  end
483
489
  o.on("-V", "--version") {
484
- if ENV["OMQ_DEV"]
485
- require_relative "../../../../omq/lib/omq/version"
486
- else
487
- require "omq/version"
488
- end
490
+ require "omq/version"
489
491
  puts "omq-cli #{OMQ::CLI::VERSION} (omq #{OMQ::VERSION})"
490
492
  exit
491
493
  }
@@ -496,6 +498,12 @@ module OMQ
496
498
  o.on("--examples") { CLI.page EXAMPLES
497
499
  exit }
498
500
 
501
+ o.separator "\nEnv vars:"
502
+ o.separator " OMQ_BACKEND (socket backend: ruby, rust, or libzmq)"
503
+ o.separator " OMQ_SERVER_KEY (client CURVE server key)"
504
+ o.separator " OMQ_SERVER_PUBLIC + OMQ_SERVER_SECRET (server CURVE keypair)"
505
+ o.separator " OMQ_CRYPTO (CURVE crypto backend: rbnacl or nuckle)"
506
+
499
507
  o.separator "\nExit codes: 0 = success, 1 = error, 2 = timeout"
500
508
  end
501
509
 
@@ -517,6 +525,8 @@ module OMQ
517
525
  opts[:type_name] = type_name.downcase
518
526
  end
519
527
 
528
+ apply_env_backend!(opts) if opts[:type_name] && !explicit_backend
529
+
520
530
  # Host shorthand (tcp://*:PORT, tcp://:PORT, tcp://localhost:PORT)
521
531
  # is normalized inside OMQ::Transport::TCP — see its
522
532
  # #normalize_bind_host / #normalize_connect_host / #loopback_host.
@@ -567,6 +577,53 @@ module OMQ
567
577
  end
568
578
 
569
579
 
580
+ # Loads an optional OMQ socket backend while parsing backend flags.
581
+ #
582
+ def load_socket_backend!(backend)
583
+ case backend
584
+ when :ruby
585
+ nil
586
+ when :rust
587
+ require "omq/backend/rust"
588
+ when :libzmq
589
+ require "omq/backend/libzmq"
590
+ end
591
+ rescue LoadError => e
592
+ case backend
593
+ when :rust
594
+ abort "omq: --backend rust requires the omq-backend-rust gem (#{e.message})"
595
+ when :libzmq
596
+ abort "omq: --backend #{backend} requires the omq-backend-libzmq gem and system libzmq 4.x (#{e.message})"
597
+ else
598
+ abort "omq: could not load backend #{backend} (#{e.message})"
599
+ end
600
+ end
601
+
602
+
603
+ # Applies OMQ_BACKEND when no explicit backend flag was given.
604
+ #
605
+ def apply_env_backend!(opts)
606
+ env_backend = ENV["OMQ_BACKEND"]
607
+ return if env_backend.nil? || env_backend.empty?
608
+
609
+ unless %w[ruby rust libzmq].include?(env_backend)
610
+ abort "omq: invalid OMQ_BACKEND=#{env_backend.inspect} (use ruby, rust, or libzmq)"
611
+ end
612
+
613
+ backend = env_backend.to_sym
614
+ load_socket_backend!(backend)
615
+ opts[:backend] = backend
616
+ opts[:ffi] = false
617
+ end
618
+
619
+
620
+ # Maps legacy CLI spelling to the backend name supported by omq.
621
+ #
622
+ def normalize_backend(backend)
623
+ backend == :ffi ? :libzmq : backend
624
+ end
625
+
626
+
570
627
  # Validates option combinations, aborting on invalid combos.
571
628
  #
572
629
  # @param opts [Hash] parsed options from {#parse}
@@ -625,7 +682,7 @@ module OMQ
625
682
  end
626
683
 
627
684
  (opts[:connects] + opts[:binds]).each do |url|
628
- abort "inproc not supported, use tcp:// or ipc://" if url.include?("inproc://")
685
+ abort "ruby:// not supported in CLI, use tcp:// or ipc://" if url.include?("ruby://")
629
686
  end
630
687
 
631
688
  all_urls = if type_name == "pipe"
@@ -62,6 +62,7 @@ module OMQ
62
62
  :curve_server,
63
63
  :curve_server_key,
64
64
  :crypto,
65
+ :backend,
65
66
  :ffi,
66
67
  :stdin_is_tty,
67
68
  ) do
@@ -48,7 +48,7 @@ module OMQ
48
48
 
49
49
 
50
50
  def setup_socket
51
- @sock = @config.ffi ? OMQ.const_get(@socket_sym).new(backend: :ffi) : OMQ.const_get(@socket_sym).new
51
+ @sock = OMQ.const_get(@socket_sym).new(**OMQ::CLI::SocketSetup.backend_kwargs(@config))
52
52
  OMQ::CLI::SocketSetup.apply_options(@sock, @config)
53
53
  OMQ::CLI::SocketSetup.apply_recv_maxsz(@sock, @config)
54
54
  @sock.identity = @config.identity if @config.identity
data/lib/omq/cli/pipe.rb CHANGED
@@ -46,6 +46,7 @@ module OMQ
46
46
 
47
47
  def run_sequential(task)
48
48
  set_pipe_process_title
49
+ log_backend
49
50
  in_eps, out_eps = resolve_endpoints
50
51
  @pull, @push = build_pull_push(in_eps, out_eps)
51
52
  compile_expr
@@ -83,7 +84,7 @@ module OMQ
83
84
 
84
85
 
85
86
  def build_pull_push(in_eps, out_eps)
86
- kwargs = config.ffi ? { backend: :ffi } : {}
87
+ kwargs = SocketSetup.backend_kwargs(config)
87
88
 
88
89
  pull = OMQ::PULL.new(**kwargs).tap do |sock|
89
90
  SocketSetup.apply_options(sock, config)
@@ -152,6 +153,7 @@ module OMQ
152
153
 
153
154
  def run_parallel(task)
154
155
  set_pipe_process_title
156
+ log_backend
155
157
  OMQ.freeze_for_ractors!
156
158
 
157
159
  in_eps, out_eps = resolve_endpoints
@@ -240,6 +242,12 @@ module OMQ
240
242
  end
241
243
  end
242
244
 
245
+
246
+ def log_backend
247
+ return unless config.verbose >= 1
248
+ $stderr.write("#{Term.log_prefix(config.timestamps)}omq: backend: #{SocketSetup.backend_name(config)}\n")
249
+ end
250
+
243
251
  end
244
252
  end
245
253
  end
@@ -38,7 +38,7 @@ module OMQ
38
38
 
39
39
 
40
40
  def setup_sockets
41
- kwargs = @config.ffi ? { backend: :ffi } : {}
41
+ kwargs = OMQ::CLI::SocketSetup.backend_kwargs(@config)
42
42
  @pull = OMQ::PULL.new(**kwargs)
43
43
  @push = OMQ::PUSH.new(**kwargs)
44
44
  OMQ::CLI::SocketSetup.apply_options(@pull, @config)
@@ -22,10 +22,6 @@ module OMQ
22
22
  # it entirely with --recv-maxsz 0.
23
23
  DEFAULT_RECV_MAXSZ = 1 << 20
24
24
 
25
- # Default zstd level when the user picks zstd without specifying one
26
- # (e.g. `--compress=zstd`). Matches the `-z` shortcut.
27
- DEFAULT_ZSTD_LEVEL = -3
28
-
29
25
  # Resolves compression state for a given pipe +side+ (:in, :out, or nil).
30
26
  # Per-side settings (in_compress / out_compress) override the global
31
27
  # +config.compress+. Returns +[codec, level]+ where codec is one of
@@ -63,14 +59,12 @@ module OMQ
63
59
 
64
60
 
65
61
  # Returns bind/connect kwargs for the chosen codec on the given
66
- # +side+. Zstd accepts a +level:+; LZ4 takes no tuning knobs.
62
+ # +side+. Zstd takes a fixed +level:+; without one, each connection
63
+ # adapts its level. LZ4 takes no tuning knobs.
67
64
  #
68
65
  def self.compress_opts(config, side: nil)
69
66
  codec, level = resolve_compress(config, side)
70
- case codec
71
- when :zstd then { level: level || DEFAULT_ZSTD_LEVEL }
72
- else {}
73
- end
67
+ codec == :zstd && level ? { level: level } : {}
74
68
  end
75
69
 
76
70
 
@@ -86,6 +80,31 @@ module OMQ
86
80
  end
87
81
 
88
82
 
83
+ # Returns socket constructor kwargs for the selected backend.
84
+ #
85
+ def self.backend_kwargs(config)
86
+ backend = backend_name(config)
87
+ return {} if backend.nil? || backend == :ruby
88
+
89
+ { backend: backend }
90
+ end
91
+
92
+
93
+ # Returns the effective backend name after legacy --ffi handling.
94
+ #
95
+ def self.backend_name(config)
96
+ backend = if config.respond_to?(:ffi) && config.ffi
97
+ :libzmq
98
+ elsif config.respond_to?(:backend)
99
+ config.backend
100
+ else
101
+ :ruby
102
+ end
103
+ backend = :libzmq if backend == :ffi
104
+ backend || :ruby
105
+ end
106
+
107
+
89
108
  # Apply common socket options from +config+ to +sock+.
90
109
  #
91
110
  def self.apply_options(sock, config)
@@ -105,7 +124,7 @@ module OMQ
105
124
  # Create and fully configure a socket from +klass+ and +config+.
106
125
  #
107
126
  def self.build(klass, config)
108
- sock = config.ffi ? klass.new(backend: :ffi) : klass.new
127
+ sock = klass.new(**backend_kwargs(config))
109
128
  sock.conflate = true if config.conflate && %w[pub radio].include?(config.type_name)
110
129
  apply_options(sock, config)
111
130
  apply_recv_maxsz(sock, config)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OMQ
4
4
  module CLI
5
- VERSION = "0.18.0"
5
+ VERSION = "0.20.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omq-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.27'
18
+ version: '0.28'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.27'
25
+ version: '0.28'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: ffi
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -43,28 +43,28 @@ dependencies:
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.4'
46
+ version: '0.6'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.4'
53
+ version: '0.6'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: omq-lz4
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.3'
60
+ version: '0.5'
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.3'
67
+ version: '0.5'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: msgpack
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +132,7 @@ files:
132
132
  - lib/omq/cli/term.rb
133
133
  - lib/omq/cli/transient_monitor.rb
134
134
  - lib/omq/cli/version.rb
135
- homepage: https://github.com/paddor/omq-cli
135
+ homepage: https://github.com/zeromq/omq.rb/tree/main/gems/omq-cli
136
136
  licenses:
137
137
  - ISC
138
138
  metadata: {}
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 4.0.6
153
+ rubygems_version: 4.0.20
154
154
  specification_version: 4
155
155
  summary: ZeroMQ CLI — pipe, filter, and transform messages from the terminal
156
156
  test_files: []