Class: Miu::Forwarder

Inherits:
Object
  • Object
show all
Defined in:
lib/miu/forwarder.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Forwarder

Returns a new instance of Forwarder.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/miu/forwarder.rb', line 7

def initialize(options = {})
  @pub = pub_socket_class.new
  @pub.bind Miu::Socket.build_address(options[:pub_host], options[:pub_port])

  @sub = sub_socket_class.new
  @sub.bind Miu::Socket.build_address(options[:sub_host], options[:sub_port])
  @sub.subscribe ''

  if options[:bridge_port]
    @bridge = sub_socket_class.new
    @bridge.connect Miu::Socket.build_address(options[:bridge_host], options[:bridge_port])
    @bridge.subscribe ''
  end
end

Instance Method Details

#closeObject



22
23
24
25
26
# File 'lib/miu/forwarder.rb', line 22

def close
  @bridge.close if @bridge
  @sub.close
  @pub.close
end

#runObject



28
29
30
31
32
33
34
# File 'lib/miu/forwarder.rb', line 28

def run
  frontends = [@sub, @bridge].compact
  backends = [@pub]

  proxy = Proxy.new frontends, backends
  proxy.run
end