Class: CZTop::Socket::SUB

Inherits:
CZTop::Socket show all
Defined in:
lib/cztop/socket/types.rb

Overview

Subscribe socket for the ZeroMQ Publish-Subscribe Pattern.

Constant Summary

EVERYTHING =

Returns subscription prefix to subscribe to everything

Returns:

  • (String)

    subscription prefix to subscribe to everything

""

Constants inherited from CZTop::Socket

TypeNames

Instance Attribute Summary

Attributes inherited from CZTop::Socket

#last_tcp_port

Attributes included from HasFFIDelegate

#ffi_delegate

Instance Method Summary collapse

Methods inherited from CZTop::Socket

#CURVE_client!, #CURVE_server!, #bind, #close, #connect, #disconnect, #inspect, #last_endpoint, new_by_type, #unbind

Methods included from HasFFIDelegate::ClassMethods

#ffi_delegate, #from_ffi_delegate

Methods included from PolymorphicZsockMethods

#set_unbounded, #signal, #wait

Methods included from CZTop::SendReceiveMethods

#<<, #receive

Methods included from ZsockOptions

#fd, #options, #readable?, #writable?

Methods included from HasFFIDelegate

#attach_ffi_delegate, #from_ffi_delegate, #raise_zmq_err, raise_zmq_err, #to_ptr

Constructor Details

#initialize(endpoints = nil, subscription = nil) ⇒ SUB

Returns a new instance of SUB

Parameters:

  • endpoints (String) (defaults to: nil)

    endpoints to connect to

  • subscription (String) (defaults to: nil)

    what to subscribe to



133
134
135
# File 'lib/cztop/socket/types.rb', line 133

def initialize(endpoints = nil, subscription = nil)
  attach_ffi_delegate(Zsock.new_sub(endpoints, subscription))
end

Instance Method Details

#subscribe(prefix = EVERYTHING) ⇒ void

This method returns an undefined value.

Subscribes to the given prefix string.

Parameters:

  • prefix (String) (defaults to: EVERYTHING)

    prefix string to subscribe to



143
144
145
# File 'lib/cztop/socket/types.rb', line 143

def subscribe(prefix = EVERYTHING)
  ffi_delegate.set_subscribe(prefix)
end

#unsubscribe(prefix) ⇒ void

This method returns an undefined value.

Unsubscribes from the given prefix.

Parameters:

  • prefix (String)

    prefix string to unsubscribe from



150
151
152
# File 'lib/cztop/socket/types.rb', line 150

def unsubscribe(prefix)
  ffi_delegate.set_unsubscribe(prefix)
end