perplexes / m2r

Mongrel2 Connection Adapter - Ruby Encrusted Steel-Reinforced Fist
MIT License
90 stars 11 forks source link

Multiple endpoints #30

Closed paneq closed 11 years ago

paneq commented 12 years ago

We should handle connecting to multiple mongrel2 endpoints. Either in the same mongrel2 instance or another one (not a real difference for us).

I was wondering about this part of the code:

      DEFAULT_OPTIONS = {
        :recv_addr => 'tcp://127.0.0.1:9997',
        :send_addr => 'tcp://127.0.0.1:9996',
        :sender_id => SecureRandom.uuid
      }

      def self.run(app, options = {})
        options    = DEFAULT_OPTIONS.merge(options)
        # ....
      end

      def self.valid_options
        {
          'recv_addr=RECV_ADDR' => 'Receive address',
          'send_addr=SEND_ADDR' => 'Send address',
          'sender_id=UUID' => 'Sender UUID'
        }

What are the possible ways of running our rack handler ?

Our binary:

3rd party binaries:

Anything else ?

How are those 3rd party libs processing the commandline options? I was wondering how we can support passing arrays of uuids? Obviously it is easier with our own binary. It could use thor I guess: https://github.com/wycats/thor/wiki/Method-Options

paneq commented 12 years ago

Maybe it is good enough if we support multiple endpoints only with our own binary ? In most advanced usecases you won't use rails s or rackup anyway right ?

paneq commented 12 years ago

I think this is related to #44 . My idea is that you should implemented more complicated use-cases yourself. And load file implementing it with require:

> rackup --help
Usage: rackup [ruby options] [rack options] [rackup config]

Ruby options:
  -r, --require LIBRARY    require the library, before executing your script

So I think our user could write a file that implements ConnectionFactory and sets it to the constant:

#factory.rb
MyCustomConnectionFactory = ConnectionFactory.new.request_parser(parser).context(context).request_socket do |sock|
  socket.connect(@request_addr)
  socket.setsockopt(ZMQ::IDENTITY, @sender_id)
  socket.setsockopt(ZMQ::HWM, 100)
end.response_socket do |sock|
  socket.connect(@response_addr)
  socket.setsockopt(ZMQ::IDENTITY, @sender_id)
  socket.setsockopt(ZMQ::LINGER, 5000)
end

load that file with -r and set some option to point to Factory that we should used:

rackup -r factory.rb -s mongrel2 rack_app.ru -O factory=MyCustomConnectionFactory