qusion 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile.lock +7 -15
- data/README.md +152 -0
- data/Rakefile +2 -25
- data/lib/qusion/channel_pool.rb +7 -1
- data/lib/qusion/version.rb +3 -0
- data/qusion.gemspec +25 -66
- data/spec/unit/channel_pool_spec.rb +31 -1
- metadata +24 -22
- data/README.rdoc +0 -132
- data/VERSION +0 -1
data/Gemfile.lock
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qusion (0.1.
|
5
|
-
amqp (
|
6
|
-
|
7
|
-
rake (>= 0.8.7)
|
4
|
+
qusion (0.1.8)
|
5
|
+
amqp (>= 0.7)
|
6
|
+
eventmachine (>= 0.12)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: http://rubygems.org/
|
@@ -13,24 +12,18 @@ GEM
|
|
13
12
|
amqp (0.7.1)
|
14
13
|
eventmachine (>= 0.12.4)
|
15
14
|
builder (3.0.0)
|
16
|
-
cucumber (0.10.
|
15
|
+
cucumber (0.10.3)
|
17
16
|
builder (>= 2.1.2)
|
18
17
|
diff-lcs (>= 1.1.2)
|
19
|
-
gherkin (>= 2.3.
|
18
|
+
gherkin (>= 2.3.8)
|
20
19
|
json (>= 1.4.6)
|
21
20
|
term-ansicolor (>= 1.0.5)
|
22
21
|
diff-lcs (1.1.2)
|
23
22
|
eventmachine (0.12.10)
|
24
|
-
gherkin (2.3.
|
23
|
+
gherkin (2.3.9)
|
25
24
|
json (>= 1.4.6)
|
26
|
-
git (1.2.5)
|
27
|
-
jeweler (1.5.2)
|
28
|
-
bundler (~> 1.0.0)
|
29
|
-
git (>= 1.2.5)
|
30
|
-
rake
|
31
25
|
json (1.5.1)
|
32
|
-
|
33
|
-
rspec (1.3.1)
|
26
|
+
rspec (1.3.2)
|
34
27
|
term-ansicolor (1.0.5)
|
35
28
|
|
36
29
|
PLATFORMS
|
@@ -38,6 +31,5 @@ PLATFORMS
|
|
38
31
|
|
39
32
|
DEPENDENCIES
|
40
33
|
cucumber (>= 0.9.4)
|
41
|
-
jeweler (~> 1.5.1)
|
42
34
|
qusion!
|
43
35
|
rspec (~> 1.3.0)
|
data/README.md
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# Qusion
|
2
|
+
|
3
|
+
Qusion makes [AMQP](https://github.com/ruby-amqp/amqp) work with your
|
4
|
+
web server with no fuss. It offers three features:
|
5
|
+
|
6
|
+
* It sets up the required callbacks and/or worker threads so that AMQP will
|
7
|
+
work with Passenger, Thin, or Mongrel. WEBrick, SCGI, and Evented Mongrel
|
8
|
+
are experimentally supported, but not heavily tested.
|
9
|
+
* A Channel Pool. You can cause problems for yourself if you create new
|
10
|
+
channels (with MQ.new) for every request. The pool sets up a few of these
|
11
|
+
when your app starts and reuses them.
|
12
|
+
* YAML configuration files. In Rails, create config/amqp.yml then fill in the
|
13
|
+
details for development, test and production. Use Qusion.start() in your
|
14
|
+
environment.rb file (or an initializer) and you're good to go.
|
15
|
+
|
16
|
+
## This fork of Qusion
|
17
|
+
|
18
|
+
This is a fork of James Tucker's [fork](https://github.com/raggi/qusion) of
|
19
|
+
Dan DeLeo's original [version](https://github.com/danielsdeleo/qusion). Tucker
|
20
|
+
did a fair amount of cleanup, mostly to the threading logic, so I went with his
|
21
|
+
fork. Improvements I've made include:
|
22
|
+
|
23
|
+
* Conversion from a Rails plugin to this gem.
|
24
|
+
* Support for Rails 3.
|
25
|
+
* Removed support for Merb (it complicated the code and tests; just use Rails 3).
|
26
|
+
|
27
|
+
## Before You Start
|
28
|
+
|
29
|
+
Qusion makes it easy to just install and start using AMQP in your application.
|
30
|
+
But there are many ways to use background jobs within a Rails app, so it's
|
31
|
+
worth taking some time to consider the tradeoffs of each approach.
|
32
|
+
|
33
|
+
* If your background job needs are simple and you're using a relational
|
34
|
+
database, [Delayed::Job](http://github.com/tobi/delayed_job/) lets you
|
35
|
+
schedule background tasks through the database. You won't need to run
|
36
|
+
another application (the AMQP Broker) to keep your app running.
|
37
|
+
* It may make more sense to run your AMQP subscriber(s) as a
|
38
|
+
[daemon](https://rubygems.org/gems/daemons) instead of via Qusion. This way
|
39
|
+
it's easy to monitor/restart it if it goes down. Some prefer to publish
|
40
|
+
messages using [Bunny](https://github.com/ruby-amqp/bunny), a synchronous
|
41
|
+
gem. This is a fairly common
|
42
|
+
[approach](http://pivotallabs.com/users/will/blog/articles/966-how-to-not-test-rabbitmq-part-1).
|
43
|
+
* Qusion runs EventMachine in a separate thread on Phusion Passenger, Mongrel,
|
44
|
+
and other non-evented servers. There are some inefficiencies in Ruby 1.8's
|
45
|
+
threading model that make running EM in a thread quite slow. Joe Damato and
|
46
|
+
Aman Gupta have created a
|
47
|
+
[patch](http://github.com/ice799/matzruby/tree/heap_stacks) for the problem
|
48
|
+
which is included in an experimental branch of REE. You can learn more about
|
49
|
+
the patch from Phusion's
|
50
|
+
[Blog](http://blog.phusion.nl/2009/12/15/google-tech-talk-on-ruby-enterprise-edition/).
|
51
|
+
|
52
|
+
## Getting Started
|
53
|
+
|
54
|
+
First you'll need the amqp library and a working RabbitMQ installation. This
|
55
|
+
entails:
|
56
|
+
|
57
|
+
* Install Erlang for your platform
|
58
|
+
* Install RabbitMQ for your platform
|
59
|
+
* On OSX, use [Homebrew](https://github.com/mxcl/homebrew) to install Erlang
|
60
|
+
and RabbitMQ: `brew install rabbitmq`
|
61
|
+
* Install bundler: http://gembundler.com/
|
62
|
+
* Include the qusion gem in your Rails project's Gemfile: `gem "qusion"`
|
63
|
+
|
64
|
+
Create an initializer (e.g. config/initializers/qusion.rb) and add:
|
65
|
+
|
66
|
+
Qusion.start
|
67
|
+
|
68
|
+
EM.next_tick do
|
69
|
+
# do some AMQP stuff
|
70
|
+
end
|
71
|
+
|
72
|
+
And that's it! This will set up AMQP for any ruby app server (tested on
|
73
|
+
mongrel, thin, and passenger). Now, you can use all of AMQP's functionality as
|
74
|
+
normal. In your controllers or models, you might have:
|
75
|
+
|
76
|
+
MQ.new.queue("my-work-queue").publish("do work, son!")
|
77
|
+
|
78
|
+
and it should just work.
|
79
|
+
|
80
|
+
## Channel Pools
|
81
|
+
|
82
|
+
It's considered bad practice to use MQ.new over and over, as it creates a new
|
83
|
+
AMQP channel, and that creates a new Erlang process in RabbitMQ. Erlang
|
84
|
+
processes are super light weight, but you'll be wasting them and causing the
|
85
|
+
Erlang VM GC headaches if you create them wantonly. So don't do that. Instead,
|
86
|
+
use the channel pool provided by Qusion. It's simple: wherever you'd normally
|
87
|
+
put MQ.new, just replace it with Qusion.channel. Examples:
|
88
|
+
|
89
|
+
# Create a queue:
|
90
|
+
Qusion.channel.queue("my-worker-queue")
|
91
|
+
# Topics:
|
92
|
+
Qusion.channel.topic("my-topic-exchange")
|
93
|
+
# etc.
|
94
|
+
|
95
|
+
This feature is a bit experimental, so the optimal pool size isn't known yet.
|
96
|
+
The default is 5. You can change it by adding something like the following to
|
97
|
+
your environment.rb:
|
98
|
+
|
99
|
+
Qusion.channel_pool_size(3)
|
100
|
+
|
101
|
+
## Configuration
|
102
|
+
|
103
|
+
You can put your AMQP server details in config/amqp.yml and Qusion will load
|
104
|
+
it when you call Qusion.start(). Example:
|
105
|
+
|
106
|
+
# Put this in config/amqp.yml
|
107
|
+
default: &default
|
108
|
+
host: localhost
|
109
|
+
port: 5672
|
110
|
+
user: guest
|
111
|
+
pass: guest
|
112
|
+
vhost: /
|
113
|
+
timeout: 3600 # seconds
|
114
|
+
logging: false
|
115
|
+
ssl: false
|
116
|
+
|
117
|
+
development:
|
118
|
+
<<: *default
|
119
|
+
|
120
|
+
test:
|
121
|
+
<<: *default
|
122
|
+
|
123
|
+
If you're too hardcore for Rails (maybe you're using Sinatra or Ramaze), you
|
124
|
+
can still use a YAML config file, but there's no support for different
|
125
|
+
environments. So do something like this:
|
126
|
+
|
127
|
+
# Tell Qusion where your config file is:
|
128
|
+
Qusion.start("/path/to/amqp.yml")
|
129
|
+
|
130
|
+
# Your configuration looks like this:
|
131
|
+
application:
|
132
|
+
host: localhost
|
133
|
+
port: 5672
|
134
|
+
...
|
135
|
+
|
136
|
+
If you just want to get started without configuring anything, Qusion.start()
|
137
|
+
will use the default options if it can't find a config file. And, finally, you
|
138
|
+
can give options directly to Qusion.start() like this:
|
139
|
+
|
140
|
+
Qusion.start(:host => "my-amqp-broker.mydomain.com", :user => "me", :pass => "am_I_really_putting_this_in_VCS?")
|
141
|
+
|
142
|
+
## Bugs? Hacking?
|
143
|
+
|
144
|
+
If you find any bugs, or feel the need to add a feature, fork away. Pull
|
145
|
+
requests are very welcome. You can also report an issues via Github.
|
146
|
+
|
147
|
+
## Shouts
|
148
|
+
* Qusion's code for Phusion Passenger's starting\_worker\_process event was originally posted by Aman Gupta (tmm1[http://github.com/tmm1]) on the AMQP list[http://groups.google.com/group/ruby-amqp]
|
149
|
+
* Brightbox's Warren[http://github.com/brightbox/warren] library provides some similar functionality. It doesn't support webserver-specific EventMachine setup, but it does have built-in encryption and support for the synchronous (non-EventMachine) Bunny[http://github.com/celldee/bunny] AMQP client.
|
150
|
+
|
151
|
+
Original author: dan@kallistec.com
|
152
|
+
Forked by: chmurph2+git@gmail.com
|
data/Rakefile
CHANGED
@@ -1,34 +1,11 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/rdoctask'
|
3
|
-
require 'rubygems'
|
4
1
|
require 'bundler'
|
2
|
+
require 'rake/rdoctask'
|
5
3
|
require "spec/rake/spectask"
|
6
4
|
|
7
5
|
desc 'Default: run specs.'
|
8
6
|
task :default => :spec
|
9
7
|
|
10
|
-
|
11
|
-
Bundler.setup(:default, :development)
|
12
|
-
rescue Bundler::BundlerError => e
|
13
|
-
$stderr.puts e.message
|
14
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
15
|
-
exit e.status_code
|
16
|
-
end
|
17
|
-
|
18
|
-
begin
|
19
|
-
require 'jeweler'
|
20
|
-
Jeweler::Tasks.new do |gem|
|
21
|
-
gem.name = "qusion"
|
22
|
-
gem.summary = "Makes AMQP work with Ruby on Rails with no fuss."
|
23
|
-
gem.description = %Q{Makes AMQP work with Ruby on Rails with no fuss.}
|
24
|
-
gem.email = "cmurphy@customink.com"
|
25
|
-
gem.homepage = "http://github.com/customink/qusion"
|
26
|
-
gem.authors = ["Dan DeLeo", "Christopher R. Murphy"]
|
27
|
-
end
|
28
|
-
rescue LoadError
|
29
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
30
|
-
end
|
31
|
-
Jeweler::RubygemsDotOrgTasks.new
|
8
|
+
Bundler::GemHelper.install_tasks
|
32
9
|
|
33
10
|
desc "Run all of the specs"
|
34
11
|
Spec::Rake::SpecTask.new do |t|
|
data/lib/qusion/channel_pool.rb
CHANGED
data/qusion.gemspec
CHANGED
@@ -1,73 +1,32 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "qusion/version"
|
5
|
+
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
7
|
+
s.name = %q{qusion}
|
8
|
+
s.version = Qusion::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Dan DeLeo", "James Tucker", "Christopher R. Murphy"]
|
11
|
+
s.email = %q{chmurph2+git@gmail.com}
|
12
|
+
s.homepage = "https://github.com/customink/qusion"
|
13
|
+
s.summary = %q{Makes AMQP work with Ruby on Rails with no fuss.}
|
14
|
+
s.description = s.summary
|
9
15
|
|
10
|
-
s.
|
11
|
-
s.authors = ["Dan DeLeo", "Christopher R. Murphy"]
|
12
|
-
s.date = %q{2011-03-25}
|
13
|
-
s.description = %q{Makes AMQP work with Ruby on Rails with no fuss.}
|
14
|
-
s.email = %q{cmurphy@customink.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gemtest",
|
21
|
-
"Gemfile",
|
22
|
-
"Gemfile.lock",
|
23
|
-
"LICENSE",
|
24
|
-
"README.rdoc",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"lib/qusion.rb",
|
28
|
-
"lib/qusion/amqp_config.rb",
|
29
|
-
"lib/qusion/channel_pool.rb",
|
30
|
-
"qusion.gemspec",
|
31
|
-
"spec/fixtures/framework-amqp.yml",
|
32
|
-
"spec/fixtures/hardcoded-amqp.yml",
|
33
|
-
"spec/spec.opts",
|
34
|
-
"spec/spec_helper.rb",
|
35
|
-
"spec/stub_rails.rb",
|
36
|
-
"spec/unit/amqp_config_spec.rb",
|
37
|
-
"spec/unit/channel_pool_spec.rb",
|
38
|
-
"spec/unit/qusion_spec.rb"
|
39
|
-
]
|
40
|
-
s.homepage = %q{http://github.com/customink/qusion}
|
41
|
-
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.5.0}
|
43
|
-
s.summary = %q{Makes AMQP work with Ruby on Rails with no fuss.}
|
44
|
-
s.test_files = [
|
45
|
-
"spec/spec_helper.rb",
|
46
|
-
"spec/stub_rails.rb",
|
47
|
-
"spec/unit/amqp_config_spec.rb",
|
48
|
-
"spec/unit/channel_pool_spec.rb",
|
49
|
-
"spec/unit/qusion_spec.rb"
|
50
|
-
]
|
16
|
+
s.rubyforge_project = "qusion"
|
51
17
|
|
52
|
-
|
53
|
-
|
18
|
+
# files
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
54
23
|
|
55
|
-
|
56
|
-
|
57
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
58
|
-
s.add_development_dependency(%q<cucumber>, [">= 0.9.4"])
|
59
|
-
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<qusion>, [">= 0"])
|
62
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
63
|
-
s.add_dependency(%q<cucumber>, [">= 0.9.4"])
|
64
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
65
|
-
end
|
66
|
-
else
|
67
|
-
s.add_dependency(%q<qusion>, [">= 0"])
|
68
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
69
|
-
s.add_dependency(%q<cucumber>, [">= 0.9.4"])
|
70
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
71
|
-
end
|
72
|
-
end
|
24
|
+
# RDoc
|
25
|
+
s.extra_rdoc_files = ["LICENSE", "README.md"]
|
73
26
|
|
27
|
+
#Dependencies
|
28
|
+
s.add_dependency "amqp", ">= 0.7"
|
29
|
+
s.add_dependency "eventmachine", ">= 0.12"
|
30
|
+
s.add_development_dependency "cucumber", ">= 0.9.4"
|
31
|
+
s.add_development_dependency "rspec", "~> 1.3.0"
|
32
|
+
end
|
@@ -36,7 +36,21 @@ describe ChannelPool do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should return a channel in a round-robin" do
|
39
|
-
|
39
|
+
class I
|
40
|
+
def initialize(i)
|
41
|
+
@i = i
|
42
|
+
end
|
43
|
+
def open?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
def reset
|
47
|
+
end
|
48
|
+
def ==(x)
|
49
|
+
@i == x
|
50
|
+
end
|
51
|
+
end
|
52
|
+
p = [1,2,3,4,5].map { |i| I.new(i) }
|
53
|
+
@channel_pool.instance_variable_set(:@pool,p)
|
40
54
|
@channel_pool.channel.should == 3
|
41
55
|
@channel_pool.channel.should == 4
|
42
56
|
@channel_pool.channel.should == 5
|
@@ -44,5 +58,21 @@ describe ChannelPool do
|
|
44
58
|
@channel_pool.channel.should == 2
|
45
59
|
@channel_pool.channel.should == 3
|
46
60
|
end
|
61
|
+
|
62
|
+
it "should reopen a closed channel" do
|
63
|
+
ChannelPool.pool_size = 1
|
64
|
+
mock_channel = mock('AMQP::Channel')
|
65
|
+
mock_channel.should_receive(:open?).exactly(1).times.and_return(false)
|
66
|
+
::AMQP::Channel.should_receive(:new).exactly(2).times.and_return(mock_channel)
|
67
|
+
@channel_pool.channel
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should reset a channel" do
|
71
|
+
mock_channel = mock('AMQP::Channel')
|
72
|
+
mock_channel.should_receive(:open?).and_return(true)
|
73
|
+
mock_channel.should_receive(:reset).exactly(1).times
|
74
|
+
::AMQP::Channel.should_receive(:new).at_least(:once).and_return(mock_channel)
|
75
|
+
@channel_pool.channel
|
76
|
+
end
|
47
77
|
|
48
78
|
end
|
metadata
CHANGED
@@ -2,42 +2,44 @@
|
|
2
2
|
name: qusion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dan DeLeo
|
9
|
+
- James Tucker
|
9
10
|
- Christopher R. Murphy
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
14
|
|
14
|
-
date: 2011-
|
15
|
+
date: 2011-05-25 00:00:00 -04:00
|
15
16
|
default_executable:
|
16
17
|
dependencies:
|
17
18
|
- !ruby/object:Gem::Dependency
|
18
|
-
name:
|
19
|
+
name: amqp
|
20
|
+
prerelease: false
|
19
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
22
|
none: false
|
21
23
|
requirements:
|
22
24
|
- - ">="
|
23
25
|
- !ruby/object:Gem::Version
|
24
|
-
version: "0"
|
26
|
+
version: "0.7"
|
25
27
|
type: :runtime
|
26
|
-
prerelease: false
|
27
28
|
version_requirements: *id001
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
30
|
+
name: eventmachine
|
31
|
+
prerelease: false
|
30
32
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
33
|
none: false
|
32
34
|
requirements:
|
33
|
-
- -
|
35
|
+
- - ">="
|
34
36
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
36
|
-
type: :
|
37
|
-
prerelease: false
|
37
|
+
version: "0.12"
|
38
|
+
type: :runtime
|
38
39
|
version_requirements: *id002
|
39
40
|
- !ruby/object:Gem::Dependency
|
40
41
|
name: cucumber
|
42
|
+
prerelease: false
|
41
43
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
44
|
none: false
|
43
45
|
requirements:
|
@@ -45,10 +47,10 @@ dependencies:
|
|
45
47
|
- !ruby/object:Gem::Version
|
46
48
|
version: 0.9.4
|
47
49
|
type: :development
|
48
|
-
prerelease: false
|
49
50
|
version_requirements: *id003
|
50
51
|
- !ruby/object:Gem::Dependency
|
51
52
|
name: rspec
|
53
|
+
prerelease: false
|
52
54
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
55
|
none: false
|
54
56
|
requirements:
|
@@ -56,28 +58,28 @@ dependencies:
|
|
56
58
|
- !ruby/object:Gem::Version
|
57
59
|
version: 1.3.0
|
58
60
|
type: :development
|
59
|
-
prerelease: false
|
60
61
|
version_requirements: *id004
|
61
62
|
description: Makes AMQP work with Ruby on Rails with no fuss.
|
62
|
-
email:
|
63
|
+
email: chmurph2+git@gmail.com
|
63
64
|
executables: []
|
64
65
|
|
65
66
|
extensions: []
|
66
67
|
|
67
68
|
extra_rdoc_files:
|
68
69
|
- LICENSE
|
69
|
-
- README.
|
70
|
+
- README.md
|
70
71
|
files:
|
71
72
|
- .gemtest
|
73
|
+
- .gitignore
|
72
74
|
- Gemfile
|
73
75
|
- Gemfile.lock
|
74
76
|
- LICENSE
|
75
|
-
- README.
|
77
|
+
- README.md
|
76
78
|
- Rakefile
|
77
|
-
- VERSION
|
78
79
|
- lib/qusion.rb
|
79
80
|
- lib/qusion/amqp_config.rb
|
80
81
|
- lib/qusion/channel_pool.rb
|
82
|
+
- lib/qusion/version.rb
|
81
83
|
- qusion.gemspec
|
82
84
|
- spec/fixtures/framework-amqp.yml
|
83
85
|
- spec/fixtures/hardcoded-amqp.yml
|
@@ -88,7 +90,7 @@ files:
|
|
88
90
|
- spec/unit/channel_pool_spec.rb
|
89
91
|
- spec/unit/qusion_spec.rb
|
90
92
|
has_rdoc: true
|
91
|
-
homepage:
|
93
|
+
homepage: https://github.com/customink/qusion
|
92
94
|
licenses: []
|
93
95
|
|
94
96
|
post_install_message:
|
@@ -101,9 +103,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
103
|
requirements:
|
102
104
|
- - ">="
|
103
105
|
- !ruby/object:Gem::Version
|
104
|
-
hash: 3007807995450840742
|
105
|
-
segments:
|
106
|
-
- 0
|
107
106
|
version: "0"
|
108
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
108
|
none: false
|
@@ -113,12 +112,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
112
|
version: "0"
|
114
113
|
requirements: []
|
115
114
|
|
116
|
-
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
115
|
+
rubyforge_project: qusion
|
116
|
+
rubygems_version: 1.6.2
|
118
117
|
signing_key:
|
119
118
|
specification_version: 3
|
120
119
|
summary: Makes AMQP work with Ruby on Rails with no fuss.
|
121
120
|
test_files:
|
121
|
+
- spec/fixtures/framework-amqp.yml
|
122
|
+
- spec/fixtures/hardcoded-amqp.yml
|
123
|
+
- spec/spec.opts
|
122
124
|
- spec/spec_helper.rb
|
123
125
|
- spec/stub_rails.rb
|
124
126
|
- spec/unit/amqp_config_spec.rb
|
data/README.rdoc
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
= Qusion
|
2
|
-
|
3
|
-
Qusion makes AMQP[http://github.com/tmm1/amqp] work with your webserver with
|
4
|
-
no fuss. It offers three features:
|
5
|
-
* It sets up the required callbacks and/or worker threads so that AMQP will work with Passenger, Thin, or Mongrel. WEBrick, SCGI, and Evented Mongrel are experimentally supported, but not heavily tested.
|
6
|
-
* A Channel Pool. You can cause problems for yourself if you create new channels (with MQ.new) for every request. The pool sets up a few of these when your app starts and reuses them.
|
7
|
-
* YAML configuration files. In Rails, create config/amqp.yml then fill in the details for development, test and production. Use Qusion.start() in your environment.rb file (or an initializer) and you're good to go.
|
8
|
-
|
9
|
-
= This fork of Qusion
|
10
|
-
|
11
|
-
This is a fork of James Tucker's fork[https://github.com/raggi/qusion] of
|
12
|
-
Dan DeLeo's original version[https://github.com/danielsdeleo/qusion]. Tucker
|
13
|
-
did a fair amount of cleanup, mostly to the threading logic, so I went with his
|
14
|
-
fork. Improvements I've made include:
|
15
|
-
* Conversion from a Rails plugin to this gem.
|
16
|
-
* Support for Rails 3.
|
17
|
-
* Removed support for Merb (it complicated the code and tests; just use Rails 3).
|
18
|
-
|
19
|
-
= Before You Start
|
20
|
-
|
21
|
-
Qusion makes it easy to just install and start using AMQP in your application.
|
22
|
-
But there are many ways to use background jobs within a Rails app, so it's
|
23
|
-
worth taking some time to consider the tradeoffs of each approach.
|
24
|
-
|
25
|
-
* If your background job needs are simple and you're using a relational database, Delayed::Job[http://github.com/tobi/delayed_job/] lets you schedule background tasks through the database. You won't need to run another application (the AMQP Broker) to keep your app running.
|
26
|
-
* The 0.6.x version of the Ruby amqp library may drop messages when the AMQP broker goes down. Pivotal Labs has discussed this problem on their blog[http://pivots.pivotallabs.com/users/will/blog/articles/966-how-to-not-test-rabbitmq-part-1]. This issue will likely be addressed in the 0.7.0 release of amqp, but can be avoided entirely using a synchronous amqp library such as bunny[http://github.com/celldee/bunny]. For a ready-made background job solution using Bunny to publish jobs to the queue, see Minion[http://github.com/orionz/minion/].
|
27
|
-
* Qusion runs EventMachine in a separate thread on Phusion Passenger, Mongrel, and other non-evented servers. There are some inefficiencies in Ruby 1.8's threading model that make running EM in a thread quite slow. Joe Damato and Aman Gupta have created a patch[http://github.com/ice799/matzruby/tree/heap_stacks] for the problem which is included in an experimental branch of REE. You can learn more about the patch from Phusion's Blog[http://blog.phusion.nl/2009/12/15/google-tech-talk-on-ruby-enterprise-edition/].
|
28
|
-
|
29
|
-
= Getting Started
|
30
|
-
|
31
|
-
First you'll need the amqp library and a working RabbitMQ installation. This
|
32
|
-
entails:
|
33
|
-
|
34
|
-
* Install Erlang for your platform
|
35
|
-
* Install RabbitMQ for your platform
|
36
|
-
* On OSX, use Homebrew to install Erlang and RabbitMQ: brew install rabbitmq
|
37
|
-
* Install bundler: http://gembundler.com/
|
38
|
-
== Install Qusion
|
39
|
-
Include the qusion gem in your Gemfile:
|
40
|
-
|
41
|
-
gem "qusion"
|
42
|
-
|
43
|
-
Create an initializer (e.g. config/initializers/qusion.rb) and add:
|
44
|
-
Qusion.start
|
45
|
-
|
46
|
-
EM.next_tick do
|
47
|
-
# do some AMQP stuff
|
48
|
-
end
|
49
|
-
|
50
|
-
And that's it! This will set up AMQP for any ruby app server (tested on
|
51
|
-
mongrel, thin, and passenger). Now, you can use all of AMQP's functionality as
|
52
|
-
normal. In your controllers or models, you might have:
|
53
|
-
|
54
|
-
MQ.new.queue("my-work-queue").publish("do work, son!")
|
55
|
-
|
56
|
-
and it should just work.
|
57
|
-
|
58
|
-
= Channel Pools
|
59
|
-
|
60
|
-
It's considered bad practice to use MQ.new over and over, as it creates a new
|
61
|
-
AMQP channel, and that creates a new Erlang process in RabbitMQ. Erlang
|
62
|
-
processes are super light weight, but you'll be wasting them and causing the
|
63
|
-
Erlang VM GC headaches if you create them wantonly. So don't do that. Instead,
|
64
|
-
use the channel pool provided by Qusion. It's simple: wherever you'd normally
|
65
|
-
put MQ.new, just replace it with Qusion.channel. Examples:
|
66
|
-
|
67
|
-
# Create a queue:
|
68
|
-
Qusion.channel.queue("my-worker-queue")
|
69
|
-
# Topics:
|
70
|
-
Qusion.channel.topic("my-topic-exchange")
|
71
|
-
# etc.
|
72
|
-
|
73
|
-
This feature is a bit experimental, so the optimal pool size isn't known yet.
|
74
|
-
The default is 5. You can change it by adding something like the following to
|
75
|
-
your environment.rb:
|
76
|
-
|
77
|
-
Qusion.channel_pool_size(3)
|
78
|
-
|
79
|
-
= Configuration
|
80
|
-
|
81
|
-
You can put your AMQP server details in config/amqp.yml and Qusion will load
|
82
|
-
it when you call Qusion.start(). Example:
|
83
|
-
|
84
|
-
# Put this in config/amqp.yml
|
85
|
-
default: &default
|
86
|
-
host: localhost
|
87
|
-
port: 5672
|
88
|
-
user: guest
|
89
|
-
pass: guest
|
90
|
-
vhost: /
|
91
|
-
timeout: 3600 # seconds
|
92
|
-
logging: false
|
93
|
-
ssl: false
|
94
|
-
|
95
|
-
development:
|
96
|
-
<<: *default
|
97
|
-
|
98
|
-
test:
|
99
|
-
<<: *default
|
100
|
-
|
101
|
-
If you're too hardcore for Rails (maybe you're using Sinatra or Ramaze), you
|
102
|
-
can still use a YAML config file, but there's no support for different
|
103
|
-
environments. So do something like this:
|
104
|
-
|
105
|
-
# Tell Qusion where your config file is:
|
106
|
-
Qusion.start("/path/to/amqp.yml")
|
107
|
-
|
108
|
-
# Your configuration looks like this:
|
109
|
-
application:
|
110
|
-
host: localhost
|
111
|
-
port: 5672
|
112
|
-
...
|
113
|
-
|
114
|
-
If you just want to get started without configuring anything, Qusion.start()
|
115
|
-
will use the default options if it can't find a config file. And, finally, you
|
116
|
-
can give options directly to Qusion.start() like this:
|
117
|
-
|
118
|
-
Qusion.start(:host => "my-amqp-broker.mydomain.com", :user => "me", :pass => "am_I_really_putting_this_in_VCS?")
|
119
|
-
|
120
|
-
|
121
|
-
= Bugs? Hacking?
|
122
|
-
|
123
|
-
If you find any bugs, or feel the need to add a feature, fork away. You can
|
124
|
-
also contact me directly via the email address in my profile if you have any
|
125
|
-
questions.
|
126
|
-
|
127
|
-
= Shouts
|
128
|
-
* Qusion's code for Phusion Passenger's starting_worker_process event was originally posted by Aman Gupta (tmm1[http://github.com/tmm1]) on the AMQP list[http://groups.google.com/group/ruby-amqp]
|
129
|
-
* Brightbox's Warren[http://github.com/brightbox/warren] library provides some similar functionality. It doesn't support webserver-specific EventMachine setup, but it does have built-in encryption and support for the synchronous (non-EventMachine) Bunny[http://github.com/celldee/bunny] AMQP client.
|
130
|
-
|
131
|
-
Original author: dan@kallistec.com
|
132
|
-
Forked by: cmurphy@customink.com
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.7
|