errbit_zmq_handler 0.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +46 -0
- data/Rakefile +8 -0
- data/bin/errbit_zmq_handler +27 -0
- data/errbit_zmq_handler.gemspec +32 -0
- data/lib/errbit_zmq_handler/configuration.rb +32 -0
- data/lib/errbit_zmq_handler/handler.rb +19 -0
- data/lib/errbit_zmq_handler/version.rb +3 -0
- data/lib/errbit_zmq_handler.rb +33 -0
- data/spec/fixtures/notice.xml +30 -0
- data/spec/lib/errbit_zmq_handler/configuration_spec.rb +28 -0
- data/spec/spec_helper.rb +9 -0
- metadata +133 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011, Nick Recobra
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= Errbit 0MQ Handler
|
2
|
+
|
3
|
+
Errbit notifier extension for handling notices over 0mq socket.
|
4
|
+
|
5
|
+
One should use this library to listen to Hoptoad 0MQ Notifier powered app (https://github.com/oruen/hoptoad_zmq_notifier)
|
6
|
+
|
7
|
+
Advantage of using Errbit 0MQ Handler is async notices processing. You could fire notices from the client and not depend on
|
8
|
+
timeouts, service unavailability and services errors.
|
9
|
+
|
10
|
+
== Requirements
|
11
|
+
|
12
|
+
Ruby 1.9 or JRuby. ffi-rzmq is not working with MRI (and REE) 1.8.7.
|
13
|
+
|
14
|
+
== Installation
|
15
|
+
|
16
|
+
Install zeromq 2.1 from http://www.zeromq.org or your favorite package system.
|
17
|
+
|
18
|
+
Get Errbit https://github.com/oruen/errbit (my fork is more stable and featured :)
|
19
|
+
|
20
|
+
Install the gem:
|
21
|
+
|
22
|
+
gem install errbit_zmq_handler
|
23
|
+
|
24
|
+
== Usage
|
25
|
+
|
26
|
+
Config 0MQ handler by defining it's address it <tt>config/initializers/errbit_zmq_handler.rb</tt>:
|
27
|
+
|
28
|
+
ErrbitZmqHandler.configure do |config|
|
29
|
+
# Address to bind to listen exception notifications
|
30
|
+
config.uri = "tcp://127.0.0.1:9998"
|
31
|
+
end
|
32
|
+
|
33
|
+
Starting handler daemon:
|
34
|
+
APP_ROOT=/path/to/app/root RAILS_ENV=production errbit_zmq_handler start
|
35
|
+
|
36
|
+
Stop handler daemon:
|
37
|
+
APP_ROOT=/path/to/app/root RAILS_ENV=production errbit_zmq_handler stop
|
38
|
+
|
39
|
+
Restart handler daemon:
|
40
|
+
APP_ROOT=/path/to/app/root RAILS_ENV=production errbit_zmq_handler restart
|
41
|
+
|
42
|
+
|
43
|
+
== License
|
44
|
+
|
45
|
+
HoptoadZmqNotifier is Copyright © 2011 oruen. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
46
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
app_root = ENV["APP_ROOT"] || "."
|
4
|
+
|
5
|
+
require 'daemon_spawn'
|
6
|
+
|
7
|
+
module ErrbitZmqHandler
|
8
|
+
class Daemon < DaemonSpawn::Base
|
9
|
+
def start(args)
|
10
|
+
puts "[#{Time.now}] Starting"
|
11
|
+
require File.expand_path('config/environment', working_dir)
|
12
|
+
Rails.logger = ActiveSupport::BufferedLogger.new log_file
|
13
|
+
Mongoid.logger = Rails.logger
|
14
|
+
ErrbitZmqHandler.handler.start!
|
15
|
+
end
|
16
|
+
|
17
|
+
def stop
|
18
|
+
puts "[#{Time.now}] Shutting down"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ErrbitZmqHandler::Daemon.spawn!(:log_file => "#{app_root}/log/errbit_zmq_handler.log",
|
24
|
+
:pid_file => "#{app_root}/tmp/pids/errbit_zmq_handler.pid",
|
25
|
+
:sync_log => true,
|
26
|
+
:singleton => true,
|
27
|
+
:working_dir => app_root)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "errbit_zmq_handler/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "errbit_zmq_handler"
|
7
|
+
s.version = ErrbitZmqHandler::VERSION
|
8
|
+
s.platform = RUBY_PLATFORM[/java/] || Gem::Platform::RUBY
|
9
|
+
s.authors = ["Nick Recobra"]
|
10
|
+
s.email = ["oruenu@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Errbit handler for 0MQ notices}
|
13
|
+
s.description = %q{Errbit extension providing handler for notices transfered via 0MQ}
|
14
|
+
|
15
|
+
s.rubyforge_project = "errbit_zmq_handler"
|
16
|
+
|
17
|
+
if s.platform.to_s == "java"
|
18
|
+
s.add_dependency "json", ">= 1.5"
|
19
|
+
else
|
20
|
+
s.add_dependency "ffi", ">= 0"
|
21
|
+
s.add_dependency "yajl-ruby", "> 0"
|
22
|
+
end
|
23
|
+
s.add_dependency "dripdrop", ">= 0.10.0.beta2"
|
24
|
+
s.add_dependency "daemon-spawn", ">= 0.4.0"
|
25
|
+
|
26
|
+
s.add_development_dependency 'rspec', '>= 2.5.0'
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ErrbitZmqHandler
|
3
|
+
# Used to set up and modify settings for the notifier.
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
OPTIONS = [:uri].freeze
|
7
|
+
|
8
|
+
# The uri to bind to (0MQ socket)
|
9
|
+
attr_accessor :uri
|
10
|
+
|
11
|
+
# Allows config options to be read like a hash
|
12
|
+
#
|
13
|
+
# @param [Symbol] option Key for a given attribute
|
14
|
+
def [](option)
|
15
|
+
send(option)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a hash of all configurable options
|
19
|
+
def to_hash
|
20
|
+
OPTIONS.inject({}) do |hash, option|
|
21
|
+
hash.merge(option.to_sym => send(option))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns a hash of all configurable options merged with +hash+
|
26
|
+
#
|
27
|
+
# @param [Hash] hash A set of configuration options that will take precedence over the defaults
|
28
|
+
def merge(hash)
|
29
|
+
to_hash.merge(hash)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'dripdrop'
|
3
|
+
module ErrbitZmqHandler
|
4
|
+
class Handler < DripDrop::Node
|
5
|
+
attr_accessor :uri
|
6
|
+
def action
|
7
|
+
self.uri = ErrbitZmqHandler.configuration.uri
|
8
|
+
route :exceptions, :zmq_subscribe, uri, :bind, :msg_format => :raw
|
9
|
+
|
10
|
+
exceptions.on_recv do |messages|
|
11
|
+
xml = messages.first.copy_out_string
|
12
|
+
puts "[#{Time.now}] got notice"
|
13
|
+
start = Time.now
|
14
|
+
Notice.from_xml(xml)
|
15
|
+
puts "Notice saved in #{Time.now - start} seconds\n\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Thread.abort_on_exception = true
|
4
|
+
|
5
|
+
module ErrbitZmqHandler
|
6
|
+
autoload :Configuration, 'errbit_zmq_handler/configuration'
|
7
|
+
autoload :Handler, 'errbit_zmq_handler/handler'
|
8
|
+
autoload :VERSION, 'errbit_zmq_handler/version'
|
9
|
+
class << self
|
10
|
+
# A Errbit ZMQ Handler configuration object. Must act like a hash and return sensible
|
11
|
+
# values for all Hoptoad ZMQ configuration options. See ErrbitZmqHandler::Configuration.
|
12
|
+
attr_accessor :configuration
|
13
|
+
|
14
|
+
# Call this method to modify defaults in your initializers.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# ErrbitZmqHandler.configure do |config|
|
18
|
+
# config.mailbox_size = 1000
|
19
|
+
# config.uri = 'tcp://errbit.home:9999'
|
20
|
+
# end
|
21
|
+
def configure
|
22
|
+
self.configuration ||= Configuration.new
|
23
|
+
yield(configuration)
|
24
|
+
end
|
25
|
+
|
26
|
+
# The handler object is responsible for delivering formatted data to the Hoptoad server.
|
27
|
+
# Must respond to #start!. See ErrbitZmqHandler::Handler.
|
28
|
+
def handler
|
29
|
+
@handler ||= Handler.new.tap {|h| h.uri = ErrbitZmqHandler.configuration.uri}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<notice version="2.0">
|
3
|
+
<api-key>76fdb93ab2cf276ec080671a8b3d3866</api-key>
|
4
|
+
<notifier>
|
5
|
+
<name>Hoptoad Notifier</name>
|
6
|
+
<version>1.2.4</version>
|
7
|
+
<url>http://hoptoadapp.com</url>
|
8
|
+
</notifier>
|
9
|
+
<error>
|
10
|
+
<class>RuntimeError</class>
|
11
|
+
<message>RuntimeError: I've made a huge mistake</message>
|
12
|
+
<backtrace>
|
13
|
+
<line method="public" file="/testapp/app/models/user.rb" number="53"/>
|
14
|
+
<line method="index" file="/testapp/app/controllers/users_controller.rb" number="14"/>
|
15
|
+
</backtrace>
|
16
|
+
</error>
|
17
|
+
<request>
|
18
|
+
<url>http://example.com</url>
|
19
|
+
<component/>
|
20
|
+
<action/>
|
21
|
+
<cgi-data>
|
22
|
+
<var key="SERVER_NAME">example.org</var>
|
23
|
+
<var key="HTTP_USER_AGENT">Mozilla</var>
|
24
|
+
</cgi-data>
|
25
|
+
</request>
|
26
|
+
<server-environment>
|
27
|
+
<project-root>/testapp</project-root>
|
28
|
+
<environment-name>production</environment-name>
|
29
|
+
</server-environment>
|
30
|
+
</notice>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ErrbitZmqHandler::Configuration do
|
5
|
+
it "should have an uri" do
|
6
|
+
assert_config_overridable :uri
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set handler uri" do
|
10
|
+
@uri = "tcp://localhost"
|
11
|
+
ErrbitZmqHandler.configure do |config|
|
12
|
+
config.uri = @uri
|
13
|
+
end
|
14
|
+
|
15
|
+
ErrbitZmqHandler.handler.uri.should == @uri
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_config_overridable(option, value = 'a value')
|
20
|
+
config = ErrbitZmqHandler::Configuration.new
|
21
|
+
config.send(:"#{option}=", value)
|
22
|
+
config.send(option).should == value
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_config_default(option, default_value, config = nil)
|
26
|
+
config ||= ErrbitZmqHandler::Configuration.new
|
27
|
+
config.send(option).should == default_value
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: errbit_zmq_handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: java
|
11
|
+
authors:
|
12
|
+
- Nick Recobra
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-03 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 5
|
30
|
+
version: "1.5"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dripdrop
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
- 10
|
43
|
+
- 0
|
44
|
+
- beta2
|
45
|
+
version: 0.10.0.beta2
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: daemon-spawn
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 4
|
58
|
+
- 0
|
59
|
+
version: 0.4.0
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 5
|
72
|
+
- 0
|
73
|
+
version: 2.5.0
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
description: Errbit extension providing handler for notices transfered via 0MQ
|
77
|
+
email:
|
78
|
+
- oruenu@gmail.com
|
79
|
+
executables:
|
80
|
+
- errbit_zmq_handler
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files: []
|
84
|
+
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- MIT-LICENSE
|
89
|
+
- README.rdoc
|
90
|
+
- Rakefile
|
91
|
+
- bin/errbit_zmq_handler
|
92
|
+
- errbit_zmq_handler.gemspec
|
93
|
+
- lib/errbit_zmq_handler.rb
|
94
|
+
- lib/errbit_zmq_handler/configuration.rb
|
95
|
+
- lib/errbit_zmq_handler/handler.rb
|
96
|
+
- lib/errbit_zmq_handler/version.rb
|
97
|
+
- spec/fixtures/notice.xml
|
98
|
+
- spec/lib/errbit_zmq_handler/configuration_spec.rb
|
99
|
+
- spec/spec_helper.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: ""
|
102
|
+
licenses: []
|
103
|
+
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project: errbit_zmq_handler
|
126
|
+
rubygems_version: 1.3.6
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Errbit handler for 0MQ notices
|
130
|
+
test_files:
|
131
|
+
- spec/fixtures/notice.xml
|
132
|
+
- spec/lib/errbit_zmq_handler/configuration_spec.rb
|
133
|
+
- spec/spec_helper.rb
|