Module: OMQ::Rust

Defined in:
lib/omq/rs/socket.rb,
lib/omq/rs/version.rb

Overview

OMQ.rs-backed Ruby socket API.

Defined Under Namespace

Classes: CHANNEL, CLIENT, DEALER, DISH, GATHER, MechanismPeerInfo, Monitor, PAIR, PEER, PUB, PULL, PUSH, RADIO, REP, REQ, ROUTER, SCATTER, SERVER, STREAM, SUB, Socket, XPUB, XSUB

Constant Summary collapse

SOCKET_TYPES =

Supported socket type names.

Returns:

  • (Array<Symbol>)
%i[
  req rep pub sub xpub xsub push pull dealer router pair stream
  client server radio dish scatter gather channel peer
].freeze
ROUTED_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[server].freeze
SINGLE_FRAME_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[client server scatter gather channel].freeze
VERSION =

Ruby binding version.

Returns:

  • (String)
"0.1.0"

Class Method Summary collapse

Class Method Details

.curve_keypairArray<String>

Generates a CurveZMQ keypair.

Returns:

  • (Array<String>)

    public and secret 40-byte Z85 keys



75
76
77
# File 'lib/omq/rs/socket.rb', line 75

def curve_keypair
  Native.curve_keypair
end

.curve_public(secret_key) ⇒ String

Derives CurveZMQ public key from a secret key.

Parameters:

  • secret_key (String)

    40-byte Z85 secret key

Returns:

  • (String)

    40-byte Z85 public key

Raises:

  • (ArgumentError)

    if secret_key is invalid



84
85
86
# File 'lib/omq/rs/socket.rb', line 84

def curve_public(secret_key)
  Native.curve_public(secret_key)
end

.has(feature) ⇒ Boolean

Reports whether binding was compiled with a feature.

Parameters:

  • feature (Symbol, String)

    feature name, such as :curve or :zstd

Returns:

  • (Boolean)


68
69
70
# File 'lib/omq/rs/socket.rb', line 68

def has(feature)
  Native.has(feature.to_s)
end

.io_threadsInteger

Returns number of OMQ.rs IO threads.

Returns:

  • (Integer)


33
34
35
# File 'lib/omq/rs/socket.rb', line 33

def io_threads
  Native.io_threads
end

.io_threads=(count) ⇒ Integer

Sets number of OMQ.rs IO threads used by subsequently created sockets.

Parameters:

  • count (Integer)

    positive IO thread count

Returns:

  • (Integer)

    assigned count

Raises:

  • (ArgumentError)

    if count is not positive



42
43
44
45
46
47
# File 'lib/omq/rs/socket.rb', line 42

def io_threads=(count)
  count = Integer(count)
  raise ArgumentError, "io_threads must be positive" unless count.positive?

  Native.send(:io_threads=, count)
end

.socket(socket_type, **options) ⇒ Socket

Creates a socket for a named OMQ pattern.

Parameters:

  • socket_type (Symbol, String)

    socket pattern, such as :pull

  • options (Hash)

    native socket options

Returns:

  • (Socket)

    concrete socket instance

Raises:

  • (ArgumentError)

    if socket_type is unknown or an option is invalid



55
56
57
58
59
60
61
62
# File 'lib/omq/rs/socket.rb', line 55

def socket(socket_type, **options)
  type = socket_type.to_s.downcase.to_sym
  unless SOCKET_TYPES.include?(type)
    raise ArgumentError, "unknown socket type: #{socket_type}"
  end

  const_get(type.to_s.upcase).new(**options)
end

.wrap_curve_authenticator(authenticator) ⇒ Proc

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adapts a public CURVE authenticator to native peer metadata.

Parameters:

Returns:

  • (Proc)


93
94
95
96
97
98
99
100
101
102
# File 'lib/omq/rs/socket.rb', line 93

def wrap_curve_authenticator(authenticator)
  proc do |peer|
    authenticator.call(
      MechanismPeerInfo.new(
        public_key: peer.fetch(:public_key),
        identity: peer[:identity],
      ),
    )
  end
end