amqp_notifier 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ amqp_notifier.gemspec
5
+ lib/amqp_notifier.rb
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = AmqpNotifier
2
+
3
+ AmqpNotifier is a helper library to wrap Qusion with the AMQP gem.
4
+
5
+ == Installation
6
+
7
+ To use this version, add this to your Gemfile:
8
+
9
+ gem "amqp_notifier", "0.0.2", :git => "git://github.com/nosolopau/amqp_notifier.git"
10
+
11
+
12
+ == Use
13
+
14
+ AmqpNotifier defines a method for publishing and another for subscription:
15
+
16
+ === Publish
17
+
18
+ AmqpNotifier.new('exchange', 'queue').publish('routing_key', 'message')
19
+
20
+ === Subscribe
21
+
22
+ a = AmqpNotifier.new('exchange', 'queue').subscribe('routing_key') do |info, message|
23
+ puts message
24
+ end
25
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('amqp_notifier', '0.0.2') do |p|
6
+ p.description = "AMQP & Qusion helper class"
7
+ p.url = "http://nosolopau.com"
8
+ p.author = "Pau"
9
+ p.email = "pau@nosolopau.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{amqp_notifier}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Pau"]
9
+ s.date = %q{2011-04-18}
10
+ s.description = %q{AMQP & Qusion helper class}
11
+ s.email = %q{pau@nosolopau.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/amqp_notifier.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "amqp_notifier.gemspec", "lib/amqp_notifier.rb"]
14
+ s.homepage = %q{http://nosolopau.com}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Amqp_notifier", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{amqp_notifier}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{AMQP & Qusion helper class}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ class AmqpNotifier
2
+ DEFAULT_EXCHANGE = 'labs_tests_1'
3
+ DEFAULT_OPTIONS = {:durable => true, :nowait => false, :type => :topic}
4
+ DEFAULT_PREFIX = ''
5
+ DEFAULT_QUEUE = 'default'
6
+ RETRIES = 10
7
+
8
+ def initialize(exchange = DEFAULT_EXCHANGE, queue = DEFAULT_QUEUE, key_prefix = DEFAULT_PREFIX, options = DEFAULT_OPTIONS)
9
+ @key_prefix = key_prefix
10
+ @exchange = exchange
11
+ @options = options
12
+ @queue = queue
13
+ end
14
+
15
+ def publish(key = '', message = '')
16
+ Qusion.channel.topic(@exchange, @options).publish(message, :key => @key_prefix + key)
17
+ end
18
+
19
+ def subscribe(key = '', &block)
20
+ Qusion.channel.prefetch(1).queue(@queue, :durable => true).bind(Qusion.channel.topic(@exchange, @options), :key => key).subscribe(:ack => true) do |info, message|
21
+ for i in (0..RETRIES)
22
+ begin
23
+ yield info, message
24
+ info.ack
25
+ break
26
+ rescue
27
+ if i == RETRIES
28
+ AmqpNotifier.new("#{@exchange}_errors").publish(key, message)
29
+ info.reject(:requeue => false)
30
+ else
31
+ sleep(1)
32
+ next
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amqp_notifier
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Pau
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-18 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: AMQP & Qusion helper class
22
+ email: pau@nosolopau.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ - lib/amqp_notifier.rb
30
+ files:
31
+ - Manifest
32
+ - README.rdoc
33
+ - Rakefile
34
+ - amqp_notifier.gemspec
35
+ - lib/amqp_notifier.rb
36
+ has_rdoc: true
37
+ homepage: http://nosolopau.com
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --line-numbers
43
+ - --inline-source
44
+ - --title
45
+ - Amqp_notifier
46
+ - --main
47
+ - README.rdoc
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 1
65
+ - 2
66
+ version: "1.2"
67
+ requirements: []
68
+
69
+ rubyforge_project: amqp_notifier
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: AMQP & Qusion helper class
74
+ test_files: []
75
+