Class: ZMQMachine::Device::Forwarder
- Inherits:
-
Object
- Object
- ZMQMachine::Device::Forwarder
- Defined in:
- lib/zm/devices/forwarder.rb
Overview
Used in conjunction with PUB/SUB sockets to allow multiple publishers to all publish to the same “bus.”
The basic mechanics are that the program contains 1 (or more) publishers that broadcast to the same bus. Connecting to an intermediate queue device allows for the publishers to have all of their traffic aggregated to a single port.
Example:
# the queue creates sockets and binds to both given addresses; all messages get
# republished from +incoming+ to +outgoing+
forwarder = ZM::Device::Forwarder.new reactor, "tcp://192.168.0.100:5050", "tcp://192.168.0.100:5051"
# the +pub_handler+ internally calls "connect" to the incoming address given above
pub1 = reactor.pub_socket pub_handler
pub2 = reactor.pub_socket pub_handler
# the +sub_handler+ internally calls "connect" to the outgoing address given above
subscriber = reactor.sub_socket sub_handler
Defined Under Namespace
Classes: Handler
Instance Method Summary collapse
-
#initialize(reactor, incoming, outgoing, opts = {:verbose => false}) ⇒ Forwarder
constructor
Takes either a properly formatted string that can be converted into a ZM::Address or takes a ZM::Address directly.
Constructor Details
#initialize(reactor, incoming, outgoing, opts = {:verbose => false}) ⇒ Forwarder
Takes either a properly formatted string that can be converted into a ZM::Address or takes a ZM::Address directly.
Forwards all messages received by the incoming
address to the outgoing
address.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/zm/devices/forwarder.rb', line 138 def initialize reactor, incoming, outgoing, opts = {:verbose => false} incoming = Address.from_string incoming if incoming.kind_of? String outgoing = Address.from_string outgoing if outgoing.kind_of? String # setup the handlers for processing messages @handler_in = Handler.new reactor, incoming, opts @handler_out = Handler.new reactor, outgoing, opts # create each socket and pass in the appropriate handler @incoming = reactor.sub_socket @handler_in @outgoing = reactor.pub_socket @handler_out # set each handler's outgoing socket @handler_in.socket_out = @outgoing @handler_out.socket_out = @incoming end |