event-shipper 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -26,6 +26,10 @@ To run a local example installation, start redis. Then:
26
26
  # Receive entries and store in redis
27
27
  $ ./bin/esproxy -c configs/proxy.yaml
28
28
 
29
+ STATUS
30
+
31
+ Stable in production for Ruby 1.9.3 and later.
32
+
29
33
  PERFORMANCE
30
34
 
31
35
  Good.
@@ -10,38 +10,54 @@ module EventShipper
10
10
  class Proxy < Clamp::Command
11
11
 
12
12
  option %w(-c --config), "FILE", "Location of the configuration file."
13
+ option %w(-v --verbose), :flag, "Prints all events before forwarding them."
13
14
 
14
15
  def execute
15
16
  fail "Please specify a configuration file to use on the command line. (--config)" \
16
17
  unless config
17
18
 
18
- configuration = YAML.load_file(config)
19
+ configure_with YAML.load_file(config)
19
20
 
20
- listen = configuration['listen']
21
- host, port = listen['host'], listen['port']
22
- transport = UDP.new(host, port)
21
+ begin
22
+ trap('SIGINFO') { puts transport.stats }
23
+ rescue ArgumentError
24
+ # unsupported signal SIGINFO
25
+ end
26
+
27
+ main_loop
28
+ end
29
+
30
+ def main_loop
31
+ transport.dispatch { |queue, message|
32
+ handle_message queue, message }
33
+ end
34
+ def handle_message queue, message
35
+ puts message if verbose?
36
+ redis.lpush queue, message
37
+ end
38
+
39
+ attr_reader :host, :port
40
+ attr_reader :listen
41
+ attr_reader :userdb
42
+ attr_reader :redis
43
+ attr_reader :transport
44
+
45
+ def configure_with configuration
46
+ @listen = configuration['listen']
47
+ @host, @port = listen['host'], listen['port']
48
+ @transport = UDP.new(host, port)
23
49
 
24
50
  if configuration['encrypt']
25
51
  users = configuration['users']
26
- userdb = Hash[users.map { |str| str.split('/') }]
52
+ @userdb = Hash[users.map { |str| str.partition('/').values_at(0,2) }]
27
53
 
28
54
  transport.wrap Filter::Decrypt.new(userdb)
29
55
  end
30
56
 
31
57
  redis_config = configuration['redis']
32
- redis = Redis.new(
58
+ @redis = Redis.new(
33
59
  host: redis_config['host'],
34
60
  port: redis_config['port'])
35
-
36
- begin
37
- trap('SIGINFO') { puts transport.stats }
38
- rescue ArgumentError
39
- # unsupported signal SIGINFO
40
- end
41
-
42
- transport.dispatch { |queue, message|
43
- # puts message }
44
- redis.lpush queue, message }
45
61
  end
46
62
  end
47
63
  end
@@ -19,6 +19,10 @@ module EventShipper
19
19
  @stats = Stats.new
20
20
  end
21
21
 
22
+ def close
23
+ @socket.close
24
+ end
25
+
22
26
  def wrap filter
23
27
  @filters << filter
24
28
  end
@@ -27,7 +31,7 @@ module EventShipper
27
31
  @filters.inject(obj) { |o, f| f.en(o) }
28
32
  end
29
33
  def decode obj
30
- @filters.reverse.inject(obj) { |o, f| f.de(o) }
34
+ @filters.reverse.inject([obj, {}]) { |o, f| f.de(*o) }
31
35
  end
32
36
 
33
37
  # Sends messages via UDP to a central proxy. Using the queue argument, the
@@ -67,7 +71,7 @@ module EventShipper
67
71
  loop do
68
72
  datagram, source_info = @socket.recvfrom(10 * 1024)
69
73
 
70
- handle_message(datagram)
74
+ handle_message(datagram, &Proc.new)
71
75
  end
72
76
  end
73
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event-shipper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-24 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis