amqp 0.5.3 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -51,7 +51,7 @@ AMQP resources:
51
51
  RabbitMQ (Rabbit Technologies, Erlang/OTP, MPL) - http://rabbitmq.com
52
52
  ZeroMQ (iMatrix/FastMQ/Intel, C++, GPL3) - http://www.zeromq.org
53
53
  OpenAMQ (iMatrix, C, GPL2) - http://openamq.org
54
- ActiveMQ (Apache Foundation, Java, apache2) - http://activemq.apache.org/
54
+ ActiveMQ (Apache Foundation, Java, apache2) - http://activemq.apache.org
55
55
 
56
56
  Steve Vinoski explains AMQP in his column, Towards Integration
57
57
  http://steve.vinoski.net/pdf/IEEE-Advanced_Message_Queuing_Protocol.pdf
@@ -59,6 +59,9 @@ AMQP resources:
59
59
  John O'Hara on the history of AMQP
60
60
  http://www.acmqueue.org/modules.php?name=Content&pa=showpage&pid=485
61
61
 
62
+ Dmitriy's presentation on RabbitMQ/AMQP
63
+ http://somic-org.homelinux.org/blog/2008/07/31/slides-for-my-amqprabbitmq-talk/
64
+
62
65
  ZeroMQ's analysis of the messaging technology market
63
66
  http://www.zeromq.org/whitepapers:market-analysis
64
67
 
@@ -91,6 +94,11 @@ AMQP resources:
91
94
  http://jaikoo.com/2008/2/29/friday-round-up-2008-02-29
92
95
  http://jaikoo.com/2007/9/4/didn-t-you-get-the-memo
93
96
 
97
+ Open Enterprise's series on messaging middleware and AMQP
98
+ http://www1.interopsystems.com/analysis/can-amqp-break-ibms-mom-monopoly-part-1.html
99
+ http://www1.interopsystems.com/analysis/can-amqp-break-ibms-mom-monopoly-part-2.html
100
+ http://www1.interopsystems.com/analysis/can-amqp-break-ibms-mom-monopoly-part-3.html
101
+
94
102
  Messaging and distributed systems resources:
95
103
 
96
104
  A Critique of the Remote Procedure Call Paradigm
@@ -72,6 +72,8 @@ module SimpleClient
72
72
  end
73
73
  end
74
74
 
75
- AMQP.logging = true
76
- AMQP.client = SimpleClient
77
- AMQP.start
75
+ EM.run{
76
+ AMQP.logging = true
77
+ AMQP.client = SimpleClient
78
+ AMQP.start
79
+ }
@@ -98,7 +98,7 @@ EM.run{
98
98
  log = Logger.new(:webserver, :timestamp, :hostname, &log.printer)
99
99
  log.info 'Request for /', :GET, :session => 'abc'
100
100
 
101
- AMQP.stop
101
+ AMQP.stop{ EM.stop_event_loop }
102
102
 
103
103
  end
104
104
  }
@@ -3,14 +3,17 @@ require 'mq'
3
3
  require 'pp'
4
4
 
5
5
  EM.run do
6
+
7
+ # connect to the amqp server
8
+ connection = AMQP.connect(:host => 'dev.rabbitmq.com', :logging => false)
6
9
 
7
10
  # open a channel on the AMQP connection
8
- channel = MQ.new
11
+ channel = MQ.new(connection)
9
12
 
10
13
  # declare a queue on the channel
11
14
  queue = MQ::Queue.new(channel, 'queue name')
12
15
 
13
- # use the default fanout exchange
16
+ # create a fanout exchange
14
17
  exchange = MQ::Exchange.new(channel, :fanout, 'all queues')
15
18
 
16
19
  # bind the queue to the exchange
@@ -19,10 +22,10 @@ EM.run do
19
22
  # publish a message to the exchange
20
23
  exchange.publish('hello world')
21
24
 
22
- # subscribe to messages from the queue
25
+ # subscribe to messages in the queue
23
26
  queue.subscribe do |headers, msg|
24
27
  pp [:got, headers, msg]
25
- AMQP.stop
28
+ connection.close{ EM.stop_event_loop }
26
29
  end
27
30
 
28
31
  end
@@ -30,12 +33,17 @@ end
30
33
  __END__
31
34
 
32
35
  [:got,
33
- #<AMQP::Protocol::Header:0x118a438
36
+ #<AMQP::Protocol::Header:0x1186270
34
37
  @klass=AMQP::Protocol::Basic,
35
38
  @properties=
36
39
  {:priority=>0,
40
+ :exchange=>"all queues",
41
+ :consumer_tag=>"queue name",
42
+ :delivery_tag=>1,
37
43
  :delivery_mode=>1,
38
- :content_type=>"application/octet-stream"},
44
+ :redelivered=>false,
45
+ :content_type=>"application/octet-stream",
46
+ :routing_key=>""},
39
47
  @size=11,
40
48
  @weight=0>,
41
49
  "hello world"]
data/lib/amqp.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module AMQP
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.5'
3
3
 
4
4
  DIR = File.expand_path(File.dirname(File.expand_path(__FILE__)))
5
5
  $:.unshift DIR
@@ -14,42 +14,31 @@ module AMQP
14
14
  class << self
15
15
  @logging = false
16
16
  attr_accessor :logging
17
- attr_reader :stopping
17
+ end
18
+
19
+ def self.connect *args
20
+ Client.connect *args
18
21
  end
19
22
 
20
23
  def self.settings
21
24
  @settings ||= {
22
25
  :user => 'guest',
23
26
  :pass => 'guest',
24
- :vhost => '/'
27
+ :vhost => '/',
28
+ :logging => false
25
29
  }
26
30
  end
27
31
 
28
32
  def self.start *args
29
- @conn ||= Client.connect *args
33
+ @conn ||= connect *args
30
34
  end
31
35
 
32
- def self.stop stop_reactor = true, &on_stop
36
+ def self.stop
33
37
  if @conn
34
- @conn.callback{ |c|
35
- if c.channels.keys.any?
36
- c.channels.each do |_, mq|
37
- mq.close
38
- end
39
- else
40
- c.close
41
- end
42
- }
43
- @on_stop = proc{
38
+ @conn.close{
39
+ yield if block_given?
44
40
  @conn = nil
45
- on_stop.call if on_stop
46
- EM.stop_event_loop if stop_reactor
47
41
  }
48
42
  end
49
43
  end
50
-
51
- def self.stopped
52
- @on_stop.call if @on_stop
53
- @on_stop = nil
54
- end
55
44
  end
data/lib/amqp/client.rb CHANGED
@@ -33,13 +33,13 @@ module AMQP
33
33
  :insist => false)
34
34
 
35
35
  when Protocol::Connection::OpenOk
36
- @dfr.succeed(self)
36
+ succeed(self)
37
37
 
38
38
  when Protocol::Connection::Close
39
39
  raise Error, "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]}"
40
40
 
41
41
  when Protocol::Connection::CloseOk
42
- AMQP.stopped
42
+ @on_disconnect.call if @on_disconnect
43
43
  end
44
44
  end
45
45
  end
@@ -55,8 +55,9 @@ module AMQP
55
55
  end
56
56
 
57
57
  module Client
58
- def initialize dfr, opts = {}
59
- @dfr = dfr
58
+ include EM::Deferrable
59
+
60
+ def initialize opts = {}
60
61
  @settings = opts
61
62
  extend AMQP.client
62
63
  end
@@ -96,6 +97,7 @@ module AMQP
96
97
  channel = opts[:channel] ||= 0
97
98
  data = data.to_frame(channel) unless data.is_a? Frame
98
99
  data.channel = channel
100
+
99
101
  log 'send', data
100
102
  send_data data.to_s
101
103
  end
@@ -105,11 +107,21 @@ module AMQP
105
107
  # super
106
108
  # end
107
109
 
108
- def close
109
- send Protocol::Connection::Close.new(:reply_code => 200,
110
- :reply_text => 'Goodbye',
111
- :class_id => 0,
112
- :method_id => 0)
110
+ def close &on_disconnect
111
+ @on_disconnect = on_disconnect if on_disconnect
112
+
113
+ callback{ |c|
114
+ if c.channels.keys.any?
115
+ c.channels.each do |_, mq|
116
+ mq.close
117
+ end
118
+ else
119
+ send Protocol::Connection::Close.new(:reply_code => 200,
120
+ :reply_text => 'Goodbye',
121
+ :class_id => 0,
122
+ :method_id => 0)
123
+ end
124
+ }
113
125
  end
114
126
 
115
127
  def unbind
@@ -118,22 +130,16 @@ module AMQP
118
130
 
119
131
  def self.connect opts = {}
120
132
  opts = AMQP.settings.merge(opts)
121
- opts[:host] ||= 'localhost'
133
+ opts[:host] ||= '127.0.0.1'
122
134
  opts[:port] ||= PORT
123
135
 
124
- dfr = EM::DefaultDeferrable.new
125
-
126
- EM.run{
127
- EM.connect opts[:host], opts[:port], self, dfr, opts
128
- }
129
-
130
- dfr
136
+ EM.connect opts[:host], opts[:port], self, opts
131
137
  end
132
138
 
133
139
  private
134
140
 
135
141
  def log *args
136
- return unless AMQP.logging
142
+ return unless @settings[:logging] or AMQP.logging
137
143
  require 'pp'
138
144
  pp args
139
145
  puts
data/lib/mq.rb CHANGED
@@ -18,7 +18,11 @@ class MQ
18
18
  include AMQP
19
19
  include EM::Deferrable
20
20
 
21
- def initialize
21
+ def initialize connection = nil
22
+ raise 'MQ can only be used from within EM.run{}' unless EM.reactor_running?
23
+
24
+ @connection = connection || AMQP.start
25
+
22
26
  conn.callback{ |c|
23
27
  @channel = c.add_channel(self)
24
28
  send Protocol::Channel::Open.new
@@ -137,12 +141,7 @@ class MQ
137
141
  puts
138
142
  end
139
143
 
140
- # create a class level connection on demand
141
-
142
- def connection
143
- raise 'MQ can only be used within EM.run{}' unless EM.reactor_running?
144
- @@connection ||= AMQP.start
145
- end
144
+ attr_reader :connection
146
145
  alias :conn :connection
147
146
  end
148
147
 
data/lib/mq/rpc.rb CHANGED
@@ -24,7 +24,8 @@ class MQ
24
24
  }
25
25
  else
26
26
  @callbacks ||= {}
27
- @queue = @mq.queue(@name = 'some random identifier for me').subscribe{|info, msg|
27
+ # XXX implement and use queue(nil)
28
+ @queue = @mq.queue(@name = "random identifier #{::Kernel.rand(999_999_999_999)}").subscribe{|info, msg|
28
29
  if blk = @callbacks.delete(info.message_id)
29
30
  blk.call ::Marshal.load(msg)
30
31
  end
@@ -34,6 +35,7 @@ class MQ
34
35
  end
35
36
 
36
37
  def method_missing meth, *args, &blk
38
+ # XXX use uuids instead
37
39
  message_id = "random message id #{::Kernel.rand(999_999_999_999)}"
38
40
  @callbacks[message_id] = blk if blk
39
41
  @remote.publish(::Marshal.dump([meth, *args]), :reply_to => blk ? @name : nil, :message_id => message_id)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aman Gupta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-29 00:00:00 -07:00
12
+ date: 2008-08-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency