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
VERSION =

Ruby binding version.

Returns:

  • (String)
"0.1.1"

Class Method Summary collapse

Class Method Details

.curve_keypairArray<String>

Generates a CurveZMQ keypair.

Returns:

  • (Array<String>)

    public and secret 40-byte Z85 keys



140
141
142
# File 'lib/omq/rs/socket.rb', line 140

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



149
150
151
# File 'lib/omq/rs/socket.rb', line 149

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)


133
134
135
# File 'lib/omq/rs/socket.rb', line 133

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

.io_threadsInteger

Returns number of OMQ.rs IO threads.

Returns:

  • (Integer)


96
97
98
# File 'lib/omq/rs/socket.rb', line 96

def io_threads
  Native.io_threads
end

.io_threads=(count) ⇒ Integer

Note:

Set this before materializing any socket. It does not resize a running runtime.

Sets number of OMQ.rs IO threads before the shared runtime starts.

Parameters:

  • count (Integer)

    positive IO thread count

Returns:

  • (Integer)

    assigned count

Raises:

  • (ArgumentError)

    if count is not positive



107
108
109
110
111
112
# File 'lib/omq/rs/socket.rb', line 107

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



120
121
122
123
124
125
126
127
# File 'lib/omq/rs/socket.rb', line 120

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)


158
159
160
161
162
163
164
165
166
167
# File 'lib/omq/rs/socket.rb', line 158

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