fluent-plugin-zmq 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,46 +2,49 @@ Zeromq plugin for Fluentd
2
2
  =============
3
3
  fluent-plugin-zmq provides an adaptor between fluentd and zeromq.
4
4
 
5
- Getting Started
6
- ------
7
- 1. setup the source
8
- > ZeroMQ input
9
- > <source>
10
- > type zmq
11
- > port 4444
12
- > </source>
5
+ # Getting Started
6
+ Setup the ZeroMQ input:
13
7
 
14
- 2. Run a source code.
15
- > #!/usr/bin/env ruby
16
- > require 'zmq'
17
- > require 'msgpack'
18
- >
19
- > z = ZMQ::Context.new
20
- > s = z.socket(ZMQ::DOWNSTREAM)
21
- > s.connect("tcp://127.0.0.1:4444")
22
- > tag = "debug.test"
23
- > # echo '{"json":"message"}' | fluent-cat debug.test
24
- > array = ["key" => "value"]
25
- >
26
- > def write_impl(s, tag, array)
27
- > begin
28
- > s.send([tag, Time.now.to_s, array].to_msgpack)
29
- > rescue
30
- > $stderr.puts "write failed: #{$!}"
31
- > s.close
32
- > return false
33
- > end
34
- >
35
- > return true
36
- > end
37
- >
38
- > write_impl(s, tag, array)
39
- 3. Happy logging with zeromq and fluetnd!
8
+ ~~~~~
9
+ <source>
10
+ type zmq
11
+ port 4444
12
+ </source>
13
+ ~~~~~
40
14
 
15
+ Run a sample code.
41
16
 
17
+ ~~~~~
18
+ #!/usr/bin/env ruby
19
+ require 'zmq'
20
+ require 'msgpack'
21
+
22
+ z = ZMQ::Context.new
23
+ s = z.socket(ZMQ::DOWNSTREAM)
24
+ s.connect("tcp://127.0.0.1:4444")
25
+ tag = "debug.test"
26
+ # echo '{"json":"message"}' | fluent-cat debug.test
27
+ array = ["key" => "value"]
28
+
29
+ def write_impl(s, tag, array)
30
+ begin
31
+ s.send([tag, Time.now.to_s, array].to_msgpack)
32
+ rescue
33
+ $stderr.puts "write failed: #{$!}"
34
+ s.close
35
+ return false
36
+ end
37
+
38
+ return true
39
+ end
40
+
41
+ write_impl(s, tag, array)
42
+ ~~~~~
42
43
 
43
- TODO
44
- ------
44
+ That's done.
45
+ Happy logging with zeromq and fluetnd! :)
46
+
47
+ # TODO
45
48
  - ZeroMQ output
46
49
  - ZeroMQ forwarding
47
50
  - JSON support
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Fluent::Plugin::Zmq::VERSION
8
8
  s.authors = ["OZAWA Tsuyoshi"]
9
9
  s.email = ["ozawa.tsuyoshi@gmail.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/oza/fluent-plugin-zmq"
11
11
  s.summary = %q{zmq plugin for fluent, an event collector}
12
12
  s.description = %q{zmq plugin for fluent, an event collector}
13
13
 
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Plugin
3
3
  module Zmq
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -51,6 +51,12 @@ class ZMQInput < Input
51
51
  @server = @zmq.socket(ZMQ::UPSTREAM)
52
52
  @server.bind("tcp://" + @bind + ":" + @port.to_s)
53
53
  @thread = Thread.new(&method(:run))
54
+ @cached_unpacker = MessagePack::Unpacker.new
55
+ end
56
+
57
+ def shutdown
58
+ @server.close
59
+ @thread.join
54
60
  end
55
61
 
56
62
  def run
@@ -68,7 +74,7 @@ class ZMQInput < Input
68
74
  end
69
75
  end
70
76
 
71
-
77
+ protected
72
78
  # message Entry {
73
79
  # 1: long time
74
80
  # 2: object record
@@ -92,47 +98,37 @@ class ZMQInput < Input
92
98
  def on_message(msg)
93
99
  # TODO format error
94
100
  tag = msg[0].to_s
95
- time = msg[1]
96
- time = Engine.now if time == 0
97
- record = msg[2]
98
-
99
- # for debugging
101
+ entries = msg[1]
102
+
103
+ if entries.class == String
104
+ # PackedForward
105
+ es = MessagePackEventStream.new(entries, @cached_unpacker)
106
+ Engine.emit_stream(tag, es)
107
+
108
+ elsif entries.class == Array
109
+ # Forward
110
+ es = MultiEventStream.new
111
+ entries.each {|e|
112
+ time = e[0].to_i
113
+ time = (now ||= Engine.now) if time == 0
114
+ record = e[1]
115
+ es.add(time, record)
116
+ }
117
+ Engine.emit_stream(tag, es)
118
+ else
119
+ # Message
120
+ time = msg[1]
121
+ time = Engine.now if time == 0
122
+ record = msg[2]
123
+ Engine.emit(tag, time, record)
124
+ end
100
125
  #p tag
101
126
  #p time
102
127
  #p record
103
-
104
- Engine.emit(tag, time, record)
105
-
106
- # TODO : support other formats
107
- #if entries.class == String
108
- # # PackedForward
109
- # es = MessagePackEventStream.new(entries, @cached_unpacker)
110
- # Engine.emit_stream(tag, es)
111
-
112
- #elsif entries.class == Array
113
- # # Forward
114
- # es = MultiEventStream.new
115
- # entries.each {|e|
116
- # time = e[0].to_i
117
- # time = (now ||= Engine.now) if time == 0
118
- # record = e[1]
119
- # es.add(time, record)
120
- # }
121
- # Engine.emit_stream(tag, es)
122
-
123
- #else
124
- # # Message
125
- # time = msg[1]
126
- # time = Engine.now if time == 0
127
- # record = msg[2]
128
- # Engine.emit(tag, time, record)
129
- #end
130
128
  end
131
129
 
132
- def shutdown
133
- @server.close
134
- #@thread.join # TODO
135
- end
136
130
  end
137
131
 
132
+
138
133
  end
134
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-zmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.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: 2011-10-31 00:00:00.000000000Z
12
+ date: 2011-11-08 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: zmq plugin for fluent, an event collector
15
15
  email:
@@ -27,7 +27,7 @@ files:
27
27
  - fluent-plugin-zmq.gemspec
28
28
  - lib/fluent-plugin-zmq/version.rb
29
29
  - lib/fluent/plugin/in_zmq.rb
30
- homepage: ''
30
+ homepage: https://github.com/oza/fluent-plugin-zmq
31
31
  licenses: []
32
32
  post_install_message:
33
33
  rdoc_options: []