Permalink
Browse files

adding aman's amqp code

  • Loading branch information...
1 parent a9e3116 commit c240263c0d6a3851c27051e8c4a06ab70807371e Amos Elliston committed Mar 21, 2009
Showing with 8,810 additions and 0 deletions.
  1. +109 −0 lib/amqp.rb
  2. +395 −0 lib/amqp/buffer.rb
  3. +189 −0 lib/amqp/client.rb
  4. +124 −0 lib/amqp/frame.rb
  5. +212 −0 lib/amqp/protocol.rb
  6. +99 −0 lib/amqp/server.rb
  7. +832 −0 lib/amqp/spec.rb
  8. +7 −0 lib/ext/blankslate.rb
  9. +51 −0 lib/ext/em.rb
  10. +69 −0 lib/ext/emfork.rb
  11. +809 −0 lib/mq.rb
  12. +295 −0 lib/mq/exchange.rb
  13. +29 −0 lib/mq/header.rb
  14. +89 −0 lib/mq/logger.rb
  15. +422 −0 lib/mq/queue.rb
  16. +100 −0 lib/mq/rpc.rb
  17. +617 −0 protocol/amqp-0.8.json
  18. +3,908 −0 protocol/amqp-0.8.xml
  19. +173 −0 protocol/codegen.rb
  20. +281 −0 protocol/doc.txt
View
@@ -0,0 +1,109 @@
+module AMQP
+ VERSION = '0.5.9'
+
+ DIR = File.expand_path(File.dirname(File.expand_path(__FILE__)))
+ $:.unshift DIR
+
+ require 'ext/em'
+ require 'ext/blankslate'
+
+ %w[ buffer spec protocol frame client ].each do |file|
+ require "amqp/#{file}"
+ end
+
+ class << self
+ @logging = false
+ attr_accessor :logging
+ attr_reader :conn, :closing
+ alias :closing? :closing
+ alias :connection :conn
+ end
+
+ def self.connect *args
+ Client.connect *args
+ end
+
+ def self.settings
+ @settings ||= {
+ # server address
+ :host => '127.0.0.1',
+ :port => PORT,
+
+ # login details
+ :user => 'guest',
+ :pass => 'guest',
+ :vhost => '/',
+
+ # connection timeout
+ :timeout => nil,
+
+ # logging
+ :logging => false
+ }
+ end
+
+ # Must be called to startup the connection to the AMQP server.
+ #
+ # The method takes several arguments and an optional block.
+ #
+ # This takes any option that is also accepted by EventMachine::connect.
+ # Additionally, there are several AMQP-specific options.
+ #
+ # * :user => String (default 'guest')
+ # The username as defined by the AMQP server.
+ # * :pass => String (default 'guest')
+ # The password for the associated :user as defined by the AMQP server.
+ # * :vhost => String (default '/')
+ # The virtual host as defined by the AMQP server.
+ # * :timeout => Numeric (default nil)
+ # Measured in seconds.
+ # * :logging => true | false (default false)
+ # Toggle the extremely verbose logging of all protocol communications
+ # between the client and the server. Extremely useful for debugging.
+ #
+ # AMQP.start do
+ # # default is to connect to localhost:5672
+ #
+ # # define queues, exchanges and bindings here.
+ # # also define all subscriptions and/or publishers
+ # # here.
+ #
+ # # this block never exits unless EM.stop_event_loop
+ # # is called.
+ # end
+ #
+ # Most code will use the MQ api. Any calls to MQ.direct / MQ.fanout /
+ # MQ.topic / MQ.queue will implicitly call #start. In those cases,
+ # it is sufficient to put your code inside of an EventMachine.run
+ # block. See the code examples in MQ for details.
+ #
+ def self.start *args, &blk
+ @conn ||= connect *args
+ @conn.callback(&blk) if blk
+ end
+
+ class << self
+ alias :run :start
+ end
+
+ def self.stop
+ if @conn and not @closing
+ @closing = true
+ @conn.close{
+ yield if block_given?
+ @conn = nil
+ @closing = false
+ }
+ end
+ end
+
+ def self.fork workers
+ EM.fork(workers) do
+ # clean up globals in the fork
+ Thread.current[:mq] = nil
+ AMQP.instance_variable_set('@conn', nil)
+
+ yield
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit c240263

Please sign in to comment.