zebra 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,13 @@
1
+ Usage:
2
+
3
+ # First start the queue
4
+ zebra --config contrib/config.yml queue
5
+
6
+ # Then start the workers
7
+ zebra --config contrib/config.yml worker
8
+
9
+ # Then start the proxy server
10
+ zebra --config contrib/config.yml server
11
+
12
+ # For more arguments, check out:
13
+ zebra --help
@@ -1 +1,12 @@
1
1
  #log_file: "/tmp/zebra.log"
2
+ server:
3
+ port: 8000
4
+ chdir: "/tmp"
5
+ frontend_uri: 'tcp://localhost:5600'
6
+ queue:
7
+ frontend_uri: 'tcp://*:5600'
8
+ backend_uri: 'tcp://*:5601'
9
+ worker:
10
+ timeout: 3600
11
+ workers: 10
12
+ backend_uri: 'tcp://localhost:5601'
@@ -39,16 +39,15 @@ module Zebra
39
39
  Zebra.config.mode = ARGV.shift if ARGV.length > 0
40
40
  raise MissingArgumentException.new("Missing --config parameter") unless Zebra.config.config_file?
41
41
  raise MissingArgumentException.new("Missing mode of operation: server|proxy|queue") unless Zebra.config.mode?
42
+ rescue SystemExit
43
+ exit(1)
42
44
  rescue MissingArgumentException => e
43
45
  puts usage(e)
44
- exit 1
45
46
  rescue ArgumentError => e
46
47
  puts usage(e)
47
- exit 1
48
48
  rescue Exception => e
49
- puts e.message
49
+ puts "#{e.class}: #{e.message}"
50
50
  puts e.backtrace.join("\n\t")
51
- exit 1
52
51
  end
53
52
  end
54
53
 
@@ -16,7 +16,7 @@ module Zebra
16
16
  config[:context] = EM::ZeroMQ::Context.new(1)
17
17
  config[:connection_pool] = EM::Synchrony::ConnectionPool.new(:size => 20) do
18
18
  config[:context].socket(ZMQ::REQ) do |socket|
19
- socket.connect("tcp://localhost:5559")
19
+ socket.connect(Zebra.config.server[:frontend_uri])
20
20
  end
21
21
  end
22
22
  end
@@ -27,8 +27,7 @@ module Zebra
27
27
  raw_headers
28
28
  end
29
29
 
30
- def get_conn(url)
31
- uri = URI.parse(url)
30
+ def get_conn(uri)
32
31
  conn_key = uri.scheme + '://' + uri.host
33
32
  return EM::HttpRequest.new(conn_key, :connect_timeout => 1, :inactivity_timeout => 1)
34
33
  if @conns.has_key?(conn_key)
@@ -38,12 +37,11 @@ module Zebra
38
37
  end
39
38
  end
40
39
 
41
- def fetch(method, url, request_headers = {})
40
+ def fetch(method, uri, request_headers = {})
42
41
  @response = nil
43
- @logger.debug "Proxying #{method} #{url} #{request_headers.inspect}"
42
+ @logger.debug "Proxying #{method} #{uri} #{request_headers.inspect}"
44
43
  t_start = Time.now
45
- uri = URI.parse(url)
46
- conn = get_conn(url)
44
+ conn = get_conn(uri)
47
45
  request_headers['Host'] = uri.host
48
46
  http = conn.send(method, path: uri.path, query: uri.query, head: request_headers, :keepalive => true)
49
47
  @logger.debug "Request finished"
@@ -67,10 +65,15 @@ module Zebra
67
65
  def handle_message(m)
68
66
  #ap m.copy_out_string
69
67
  env = JSON.parse(m.copy_out_string)
70
- #url = 'http://' + env['HTTP_HOST'] + env['REQUEST_URI']
71
- url = env['REQUEST_URI']
68
+ uri = URI.parse(env['REQUEST_URI'])
69
+ uri.host = env['HTTP_HOST'] if uri.host.nil? || uri.host.empty?
70
+ uri.path = '/' if uri.path.nil? || uri.path.empty?
71
+ puts env.inspect
72
+ uri.scheme = env['HTTP_X_FORWARDED_PROTO'].downcase if env.has_key?('HTTP_X_FORWARDED_PROTO')
73
+ uri.scheme = 'http' if uri.scheme.nil? || uri.scheme.empty?
72
74
  method = env['REQUEST_METHOD'].downcase.to_sym
73
- fetch(method, url)
75
+ puts "uri: #{uri.to_s}"
76
+ fetch(method, uri)
74
77
  end
75
78
 
76
79
  def on_readable(socket, messages)
@@ -100,6 +103,9 @@ module Zebra
100
103
  :app_name => @app_name,
101
104
  :logger => @log,
102
105
  :timeout => @timeout }
106
+ params[:stdout_path] = Zebra.config.log_file if Zebra.config.log_file?
107
+ params[:stderr_path] = Zebra.config.log_file if Zebra.config.log_file?
108
+
103
109
  workers = Preforker.new(params) do |master|
104
110
  config = {:logger => @log}
105
111
  handler = ProxyWorkerReceiveMessageHandler.new(config)
@@ -114,7 +120,7 @@ module Zebra
114
120
  context = EM::ZeroMQ::Context.new(1)
115
121
  # connection_pool = EM::Synchrony::ConnectionPool.new(:size => 1) do
116
122
  socket = context.socket(ZMQ::REP, handler)
117
- socket.connect('tcp://localhost:5560')
123
+ socket.connect(Zebra.config.worker[:backend_uri])
118
124
  # end
119
125
  end
120
126
  end
@@ -5,8 +5,8 @@ module Zebra
5
5
  attr_accessor :context, :frontend, :backend, :poller, :log, :frontend_uri, :backend_uri
6
6
  def initialize(config)
7
7
  @log = config[:logger] || Logger.new(STDERR)
8
- @frontend_uri = config[:frontend] || 'tcp://*:5559'
9
- @backend_uri = config[:backend] || 'tcp://*:5560'
8
+ @frontend_uri = config[:frontend_uri] || 'tcp://*:5559'
9
+ @backend_uri = config[:backend_uri] || 'tcp://*:5560'
10
10
  @context = ZMQ::Context.new
11
11
 
12
12
  # Socket facing clients
@@ -1,3 +1,3 @@
1
1
  module Zebra
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["osterman"]
9
9
  s.email = ["e@osterman.com"]
10
10
  s.homepage = "https://github.com/osterman/zebra"
11
- s.summary = %q{A Goliath ZMQ Reverse HTTP Proxy Implementation}
12
- s.description = %q{A proxy that uses ZMQ as the wire protocol between HTTP proxy gateway and backend worker nodes. This allows for each load distribution to worker nodes behind a firewall.}
11
+ s.summary = %q{A Goliath Reverse HTTP Proxy Implementation Using ZMQ}
12
+ s.description = %q{Zebra is a HTTP proxy server that uses ZMQ as the wire protocol between HTTP proxy gateway(s) and backend worker node(s). This allows for seamless load distribution to worker nodes behind a firewall.}
13
13
 
14
14
  s.rubyforge_project = "zebra"
15
15
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zebra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - osterman
@@ -192,7 +192,7 @@ dependencies:
192
192
  version: 1.1.0
193
193
  type: :runtime
194
194
  version_requirements: *id011
195
- description: A proxy that uses ZMQ as the wire protocol between HTTP proxy gateway and backend worker nodes. This allows for each load distribution to worker nodes behind a firewall.
195
+ description: Zebra is a HTTP proxy server that uses ZMQ as the wire protocol between HTTP proxy gateway(s) and backend worker node(s). This allows for seamless load distribution to worker nodes behind a firewall.
196
196
  email:
197
197
  - e@osterman.com
198
198
  executables:
@@ -204,6 +204,7 @@ extra_rdoc_files: []
204
204
  files:
205
205
  - .gitignore
206
206
  - Gemfile
207
+ - README
207
208
  - Rakefile
208
209
  - bin/zebra
209
210
  - contrib/config.yml
@@ -249,6 +250,6 @@ rubyforge_project: zebra
249
250
  rubygems_version: 1.3.7
250
251
  signing_key:
251
252
  specification_version: 3
252
- summary: A Goliath ZMQ Reverse HTTP Proxy Implementation
253
+ summary: A Goliath Reverse HTTP Proxy Implementation Using ZMQ
253
254
  test_files: []
254
255