lapin 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWUwNTdkZDVhOGE3NGVlNzg5MTdkMjU4OWZlNjg5MjQzZTZiYmYxYw==
5
+ data.tar.gz: !binary |-
6
+ Mjk4MDRmYzRmNzQyYWVmNzZmNGQyOWE1NzBkNjhkMGQxZjgxYmJlNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzViZmEyODczMzJkM2FiNTc2MWRiNGVlZDZkZGFhMTgxODFkZjJiYmRiNzFj
10
+ NGQ1ZWEwNjk1YzkyNWM5NDM5NjI3YjNkMGU3NWNlMGYyZmM4YWU2ZjUyZGE0
11
+ OWMyZDVjNjA5YTg2YmJhZThjYWFlYmI2ODYyMGI4ODkwYTZhMjI=
12
+ data.tar.gz: !binary |-
13
+ MjM1YjEyZmY2MGMxMWFmZTYwZTgzNDNiNDkwOTE5ODg3YmQ4NTllZDk4MjE0
14
+ MDA2YTg2ODk3YTAzNzZiZTU0MGE3YzcxNzRhZmYyNDQ4NGYzM2QzMzVjM2Nh
15
+ NmFjNDI1OGIzYjM3NjdiMzUwZGNkNDE3ZjM0MjdmNmY5OWRjMzE=
@@ -1,13 +1,13 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  # -*- encoding: utf-8 -*-
3
3
 
4
4
  require "amqp"
5
+ require "multi_json"
5
6
 
6
- AMQP.start(host: 'localhost') do |conn|
7
+ AMQP.start("amqp://localhost:5672/") do |conn|
7
8
  channel = AMQP::Channel.new(conn)
8
- exchange = channel.direct('amqp.direct')
9
- queue = channel.queue("", exclusive: true)
10
- queue.bind(exchange, routing_key: 'amqp.giraffi')
9
+ exchange = channel.fanout('logs')
10
+ queue = channel.queue("", :auto_delete => true).bind(exchange, :routing_key => 'amq.giraffi')
11
11
 
12
12
  Signal.trap("INT") do
13
13
  conn.close do
@@ -17,10 +17,7 @@ AMQP.start(host: 'localhost') do |conn|
17
17
 
18
18
  puts " [*] Waiting for logs. To exit press CTRL+C"
19
19
 
20
- i = 1
21
- queue.subscribe do |header, payload|
22
- #puts " [x] #{header}:#{payload}"
23
- puts " [x] #{header} ----- #{i}"
24
- i += 1
20
+ queue.subscribe do |metadata, payload|
21
+ puts " [x] #{MultiJson.load(payload)}"
25
22
  end
26
23
  end
@@ -19,12 +19,13 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "rack", "~> 1.4.0"
23
- s.add_dependency "bunny", "~> 0.8.0"
24
- s.add_dependency "multi_json", "~> 1.3.0"
25
- s.add_dependency "sinatra", "~> 1.3.0"
22
+ s.add_dependency "rack", "~> 1.5.2"
23
+ s.add_dependency "bunny", "~> 0.9.0.pre7"
24
+ s.add_dependency "multi_json", "~> 1.6.1"
25
+ s.add_dependency "sinatra", "~> 1.3.5"
26
26
 
27
27
  s.add_development_dependency "rake"
28
+ s.add_development_dependency "amqp"
28
29
  s.add_development_dependency "yajl-ruby"
29
30
  s.add_development_dependency "rack-test"
30
31
  s.add_development_dependency "shoulda"
@@ -21,9 +21,10 @@ module Lapin
21
21
 
22
22
  def client
23
23
  unless @client
24
- c = ::Bunny.new(Config.amqp_config)
25
- c.start
26
- @client = c
24
+ conn = Bunny.new(Config.amqp_config)
25
+ conn.start
26
+ conn.create_channel
27
+ @client = conn
27
28
  end
28
29
  @client
29
30
  end
@@ -6,7 +6,7 @@ module Lapin
6
6
 
7
7
  class << self
8
8
  attr_accessor :amqp_url, :vhost
9
- attr_accessor :exchange, :routing_key
9
+ attr_accessor :exchange, :routing_key, :queue
10
10
  attr_accessor :logging
11
11
 
12
12
  def amqp_config
@@ -15,8 +15,8 @@ module Lapin
15
15
  :user => uri.user,
16
16
  :pass => uri.password,
17
17
  :host => uri.host,
18
- :port => (uri.port || 5672),
19
- :vhost => @vhost || uri.path ,
18
+ :port => uri.port || 5672,
19
+ :vhost => @vhost || uri.path,
20
20
  :logging => @logging || false
21
21
  }
22
22
  rescue Object => e
@@ -32,7 +32,7 @@ module Lapin
32
32
  end
33
33
 
34
34
  def exchange
35
- @exchange ||= "amq.direct"
35
+ @exchange ||= "amq.fanout"
36
36
  end
37
37
 
38
38
  def routing_key
@@ -42,7 +42,7 @@ module Lapin
42
42
 
43
43
  # Create an exchange from the current AMQP connection.
44
44
  def exchange
45
- @exchange ||= Lapin.client.exchange(Config.exchange, :type => 'direct')
45
+ @exchange ||= Lapin.client.fanout(Config.exchange)
46
46
  end
47
47
 
48
48
  # Recieve post data, validate and redirect it
@@ -52,14 +52,13 @@ module Lapin
52
52
 
53
53
  begin
54
54
  # Set routing key from headers
55
- Config.routing_key = request.env['HTTP_X_ROUTING_KEY']
55
+ Config.routing_key = request.env["HTTP_X_ROUTING_KEY"]
56
56
 
57
57
  # Set payload from bod
58
58
  payload = request.body.read
59
59
 
60
60
  if validate_json(payload)
61
- exchange.publish(payload, :key => Config.routing_key)
62
-
61
+ exchange.publish(payload, :routing_key => Config.routing_key)
63
62
  # No Content
64
63
  status 204
65
64
  else
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module Lapin
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -23,9 +23,11 @@ class ServerTest < Test::Unit::TestCase
23
23
  m = mock()
24
24
  Bunny.expects(:new).with(Lapin::Config.amqp_config).returns(m)
25
25
  m.expects(:start)
26
+ m.expects(:create_channel)
27
+ #m.stubs(:exchange).with(Lapin::Config.exchange, {:type => 'fanout'}).returns(e)
26
28
  e = mock("exchange")
27
- m.stubs(:exchange).with(Lapin::Config.exchange, {:type => 'direct'}).returns(e)
28
- e.stubs(:publish).with(@payload, {:key => 'giraffi.nagios'})
29
+ m.stubs(:fanout).with(Lapin::Config.exchange).returns(e)
30
+ e.stubs(:publish).with(@payload, {:routing_key => 'giraffi.nagios'})
29
31
 
30
32
  post "/publish.json", @payload, {"CONTENT_TYPE" => "application/json", "HTTP_X_ROUTING_KEY" => "giraffi.nagios"}
31
33
  assert_equal last_request.body.string, @payload
@@ -64,7 +66,7 @@ class ServerTest < Test::Unit::TestCase
64
66
  should "return 502 when the no connection and no socket are found" do
65
67
  m = mock()
66
68
  Bunny.expects(:new).with(Lapin::Config.amqp_config).returns(m)
67
- m.stubs(:start).raises(Bunny::ConnectionError.new)
69
+ m.stubs(:start).raises(Bunny::ConnectionError.new("No connection: socket is nil.", "localhost", 5762))
68
70
 
69
71
  post "/publish.json", @payload, {"CONTENT_TYPE" => "application/json"}
70
72
  assert_equal last_response.status, 502
@@ -73,7 +75,7 @@ class ServerTest < Test::Unit::TestCase
73
75
  should "return 502 when the broken pipe is catched" do
74
76
  m = mock()
75
77
  Bunny.expects(:new).with(Lapin::Config.amqp_config).returns(m)
76
- m.stubs(:start).raises(Bunny::ServerDownError.new)
78
+ m.stubs(:start).raises(Bunny::TCPConnectionFailed.new("Connection failure: connection is failed.", "localhost", 5762))
77
79
 
78
80
  post "/publish.json", @payload, {"CONTENT_TYPE" => "application/json"}
79
81
  assert_equal last_response.status, 502
metadata CHANGED
@@ -1,84 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lapin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.1.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - azukiwasher
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
11
+ date: 2013-03-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 1.4.0
19
+ version: 1.5.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: 1.4.0
26
+ version: 1.5.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bunny
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: 0.8.0
33
+ version: 0.9.0.pre7
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: 0.8.0
40
+ version: 0.9.0.pre7
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: multi_json
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: 1.3.0
47
+ version: 1.6.1
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: 1.3.0
54
+ version: 1.6.1
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sinatra
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
69
- version: 1.3.0
61
+ version: 1.3.5
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
77
- version: 1.3.0
68
+ version: 1.3.5
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,20 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: amqp
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
90
93
  requirements:
91
94
  - - ! '>='
92
95
  - !ruby/object:Gem::Version
@@ -94,7 +97,6 @@ dependencies:
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: yajl-ruby
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
101
  - - ! '>='
100
102
  - !ruby/object:Gem::Version
@@ -102,7 +104,6 @@ dependencies:
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
108
  - - ! '>='
108
109
  - !ruby/object:Gem::Version
@@ -110,7 +111,6 @@ dependencies:
110
111
  - !ruby/object:Gem::Dependency
111
112
  name: rack-test
112
113
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
114
  requirements:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
@@ -118,7 +118,6 @@ dependencies:
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
121
  requirements:
123
122
  - - ! '>='
124
123
  - !ruby/object:Gem::Version
@@ -126,7 +125,6 @@ dependencies:
126
125
  - !ruby/object:Gem::Dependency
127
126
  name: shoulda
128
127
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
129
  - - ! '>='
132
130
  - !ruby/object:Gem::Version
@@ -134,7 +132,6 @@ dependencies:
134
132
  type: :development
135
133
  prerelease: false
136
134
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
135
  requirements:
139
136
  - - ! '>='
140
137
  - !ruby/object:Gem::Version
@@ -142,7 +139,6 @@ dependencies:
142
139
  - !ruby/object:Gem::Dependency
143
140
  name: simplecov
144
141
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
142
  requirements:
147
143
  - - ! '>='
148
144
  - !ruby/object:Gem::Version
@@ -150,7 +146,6 @@ dependencies:
150
146
  type: :development
151
147
  prerelease: false
152
148
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
149
  requirements:
155
150
  - - ! '>='
156
151
  - !ruby/object:Gem::Version
@@ -158,7 +153,6 @@ dependencies:
158
153
  - !ruby/object:Gem::Dependency
159
154
  name: mocha
160
155
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
156
  requirements:
163
157
  - - ! '>='
164
158
  - !ruby/object:Gem::Version
@@ -166,7 +160,6 @@ dependencies:
166
160
  type: :development
167
161
  prerelease: false
168
162
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
163
  requirements:
171
164
  - - ! '>='
172
165
  - !ruby/object:Gem::Version
@@ -174,7 +167,6 @@ dependencies:
174
167
  - !ruby/object:Gem::Dependency
175
168
  name: thin
176
169
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
170
  requirements:
179
171
  - - ! '>='
180
172
  - !ruby/object:Gem::Version
@@ -182,7 +174,6 @@ dependencies:
182
174
  type: :development
183
175
  prerelease: false
184
176
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
177
  requirements:
187
178
  - - ! '>='
188
179
  - !ruby/object:Gem::Version
@@ -211,31 +202,29 @@ files:
211
202
  - test/test_helper.rb
212
203
  homepage: https://github.com/giraffi/lapin.git
213
204
  licenses: []
205
+ metadata: {}
214
206
  post_install_message:
215
207
  rdoc_options: []
216
208
  require_paths:
217
209
  - lib
218
210
  required_ruby_version: !ruby/object:Gem::Requirement
219
- none: false
220
211
  requirements:
221
212
  - - ! '>='
222
213
  - !ruby/object:Gem::Version
223
214
  version: '0'
224
215
  required_rubygems_version: !ruby/object:Gem::Requirement
225
- none: false
226
216
  requirements:
227
217
  - - ! '>='
228
218
  - !ruby/object:Gem::Version
229
219
  version: '0'
230
220
  requirements: []
231
221
  rubyforge_project: lapin
232
- rubygems_version: 1.8.25
222
+ rubygems_version: 2.0.3
233
223
  signing_key:
234
- specification_version: 3
224
+ specification_version: 4
235
225
  summary: A sinatra-based app that redirects data received via HTTP to an AMQP message
236
226
  broker
237
227
  test_files:
238
228
  - test/config_test.rb
239
229
  - test/server_test.rb
240
230
  - test/test_helper.rb
241
- has_rdoc: