fmq 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.3.3 2008-09-02
2
+
3
+ * 1 minor change:
4
+ * added round robin queue
5
+ * 1 tiny fix:
6
+ * fixed bug on QueueException handling
7
+
1
8
  == 0.3.2 2008-08-28
2
9
 
3
10
  * 3 minor changes:
data/README.txt CHANGED
@@ -25,8 +25,8 @@ The client apis are implemented using the HTTP protocol, so that you can
25
25
  use even curl to receive messages. A client library for ruby is implemented
26
26
  right now, other languages will follow.
27
27
 
28
- The queue itself is a RESTful url like @http://localhost:5884/myQueueName/@
29
- or @http://localhost:5884/myApplication/myQueueName/@. If you do a GET request
28
+ The queue itself is a RESTful url like http://localhost:5884/myQueueName/
29
+ or http://localhost:5884/myApplication/myQueueName/. If you do a GET request
30
30
  to this url with a web browser you will receive one message from the queue.
31
31
 
32
32
  == FEATURES/PROBLEMS:
@@ -0,0 +1,91 @@
1
+ #
2
+ # Copyright (c) 2008 Vincent Landgraf
3
+ #
4
+ # This file is part of the Free Message Queue.
5
+ #
6
+ # Free Message Queue is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Free Message Queue is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Free Message Queue. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ require File.dirname(__FILE__) + '/base'
20
+
21
+ module FreeMessageQueue
22
+ # This queue distributes the polls and puts to different queues. It uses a round robin, so each queue
23
+ # will be called in order every time. E.g. if you have three queues specified in the redirect_to
24
+ # statement and use the poll method it will poll the first queue. If you poll the second time the RoundRobinQueue
25
+ # will poll the second queue and if you poll the fourth time the RoundRobinQueue will again poll the first queue.
26
+ #
27
+ # queue_manager = FreeMessageQueue::QueueManager.new(true) do
28
+ # setup_queue "/fmq_test/test1", FreeMessageQueue::RoundRobinQueue do |q|
29
+ # q.redirect_to ["/fmq_test/test1", "/fmq_test/test2"]
30
+ # # one can optionally configure what methods are allowed
31
+ # # by default it is [:put, :poll]
32
+ # q.allow :poll
33
+ # end
34
+ # end
35
+ class RoundRobinQueue < BaseQueue
36
+ def initialize(manager)
37
+ super(manager)
38
+ @allow = [:poll, :put]
39
+ @queue_index = -1 # as starting point will be 0 later by using next_queue
40
+ end
41
+
42
+ def poll
43
+ if allowed? :poll
44
+ manager.poll(@redirect_to[next_queue])
45
+ else
46
+ raise QueueException.new("[RoundRobinQueue] you can't poll from this queue", caller)
47
+ end
48
+ end
49
+
50
+ def put(message)
51
+ if allowed? :put
52
+ manager.put(@redirect_to[next_queue], message)
53
+ else
54
+ raise QueueException.new("[RoundRobinQueue] you can't put to this queue", caller)
55
+ end
56
+ end
57
+
58
+ # *CONFIGURATION* *OPTION*
59
+ # allow actions *:put* or *:poll*. You can pass and array for both (*[:poll, :put]*) or just one *:put*
60
+ def allow(val)
61
+ @allow = val
62
+ end
63
+
64
+ # *CONFIGURATION* *OPTION*
65
+ # specifiy the queues that should be used (must be an array)
66
+ def redirect_to(val)
67
+ @redirect_to = val
68
+ end
69
+
70
+ private
71
+
72
+ # returns the index of the next queue
73
+ # (this is the round robin)
74
+ def next_queue
75
+ if @queue_index + 1 < @redirect_to.size
76
+ @queue_index += 1
77
+ else
78
+ @queue_index = 0
79
+ end
80
+ end
81
+
82
+ # is this method (put, poll) allowed
83
+ def allowed? (method)
84
+ if @allow.respond_to? :each
85
+ @allow.include method
86
+ else
87
+ @allow == method
88
+ end
89
+ end
90
+ end
91
+ end
data/lib/fmq/server.rb CHANGED
@@ -41,6 +41,8 @@ module FreeMessageQueue
41
41
  response = client_exception(request, queue_path,
42
42
  ArgumentError.new("[Server] Method is not supported '#{method}'"))
43
43
  end
44
+ rescue QueueException => ex
45
+ response = client_exception(request, queue_path, ex)
44
46
  rescue QueueManagerException => ex
45
47
  response = client_exception(request, queue_path, ex)
46
48
  end
data/lib/fmq/version.rb CHANGED
@@ -20,7 +20,7 @@ module FreeMessageQueue
20
20
  module VERSION #:nodoc:
21
21
  MAJOR = 0
22
22
  MINOR = 3
23
- TINY = 2
23
+ TINY = 3
24
24
 
25
25
  STRING = [MAJOR, MINOR, TINY].join('.')
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Landgraf
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-28 00:00:00 +02:00
12
+ date: 2008-09-02 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -74,6 +74,7 @@ files:
74
74
  - lib/fmq/queues/load_balanced.rb
75
75
  - lib/fmq/queues/syncronized.rb
76
76
  - lib/fmq/queues/file_persistent.rb
77
+ - lib/fmq/queues/round_robin.rb
77
78
  - lib/fmq/version.rb
78
79
  - test/test_basic.rb
79
80
  - test/test_fmq_client.rb