secure_carrot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/LICENSE +20 -0
- data/README.markdown +34 -0
- data/Rakefile +42 -0
- data/VERSION.yml +5 -0
- data/lib/amqp/buffer.rb +401 -0
- data/lib/amqp/exchange.rb +51 -0
- data/lib/amqp/frame.rb +121 -0
- data/lib/amqp/header.rb +27 -0
- data/lib/amqp/protocol.rb +209 -0
- data/lib/amqp/queue.rb +144 -0
- data/lib/amqp/server.rb +187 -0
- data/lib/amqp/spec.rb +820 -0
- data/lib/carrot.rb +92 -0
- data/lib/examples/simple_pop.rb +13 -0
- data/protocol/amqp-0.8.json +617 -0
- data/protocol/amqp-0.8.xml +3908 -0
- data/protocol/codegen.rb +173 -0
- data/protocol/doc.txt +281 -0
- data/test/carrot_test.rb +25 -0
- data/test/test_helper.rb +18 -0
- metadata +102 -0
data/lib/carrot.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
class Carrot
|
2
|
+
module AMQP
|
3
|
+
HEADER = "AMQP".freeze
|
4
|
+
VERSION_MAJOR = 8
|
5
|
+
VERSION_MINOR = 0
|
6
|
+
PORT = 5672
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
$:.unshift File.expand_path(File.dirname(File.expand_path(__FILE__)))
|
11
|
+
require 'amqp/spec'
|
12
|
+
require 'amqp/buffer'
|
13
|
+
require 'amqp/exchange'
|
14
|
+
require 'amqp/frame'
|
15
|
+
require 'amqp/header'
|
16
|
+
require 'amqp/queue'
|
17
|
+
require 'amqp/server'
|
18
|
+
require 'amqp/protocol'
|
19
|
+
require 'encrypted_strings'
|
20
|
+
|
21
|
+
class Carrot
|
22
|
+
@logging = false
|
23
|
+
class << self
|
24
|
+
attr_accessor :logging
|
25
|
+
end
|
26
|
+
def self.logging?
|
27
|
+
@logging
|
28
|
+
end
|
29
|
+
class Error < StandardError; end
|
30
|
+
|
31
|
+
def initialize(opts = {})
|
32
|
+
@opts = opts
|
33
|
+
end
|
34
|
+
|
35
|
+
def queue(name, opts = {})
|
36
|
+
queues[name] ||= AMQP::Queue.new(self, name, opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
def server
|
40
|
+
@server ||= AMQP::Server.new(@opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
def stop
|
44
|
+
server.close
|
45
|
+
@server = nil
|
46
|
+
end
|
47
|
+
alias :reset :stop
|
48
|
+
|
49
|
+
def queues
|
50
|
+
@queues ||= {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def direct(name = 'amq.direct', opts = {})
|
54
|
+
exchanges[name] ||= AMQP::Exchange.new(self, :direct, name, opts)
|
55
|
+
end
|
56
|
+
|
57
|
+
def topic(name = 'amq.topic', opts = {})
|
58
|
+
exchanges[name] ||= AMQP::Exchange.new(self, :topic, name, opts)
|
59
|
+
end
|
60
|
+
|
61
|
+
def headers(name = 'amq.match', opts = {})
|
62
|
+
exchanges[name] ||= AMQP::Exchange.new(self, :headers, name, opts)
|
63
|
+
end
|
64
|
+
|
65
|
+
def exchanges
|
66
|
+
@exchanges ||= {}
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def log(*args)
|
72
|
+
return unless Carrot.logging?
|
73
|
+
pp args
|
74
|
+
puts
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#-- convenience wrapper (read: HACK) for thread-local Carrot object
|
79
|
+
|
80
|
+
class Carrot
|
81
|
+
def Carrot.default
|
82
|
+
#-- XXX clear this when connection is closed
|
83
|
+
Thread.current[:carrot] ||= Carrot.new
|
84
|
+
end
|
85
|
+
|
86
|
+
# Allows for calls to all Carrot instance methods. This implicitly calls
|
87
|
+
# Carrot.new so that a new channel is allocated for subsequent operations.
|
88
|
+
def Carrot.method_missing(meth, *args, &blk)
|
89
|
+
Carrot.default.__send__(meth, *args, &blk)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(File.expand_path(__FILE__)) + '/../carrot'
|
2
|
+
|
3
|
+
#Carrot.logging = true
|
4
|
+
q = Carrot.queue('carrot', :durable => true)
|
5
|
+
100.times do
|
6
|
+
q.publish('foo', :persistent => true)
|
7
|
+
end
|
8
|
+
puts "count: #{q.message_count}"
|
9
|
+
while msg = q.pop(:ack => true)
|
10
|
+
puts msg
|
11
|
+
q.ack
|
12
|
+
end
|
13
|
+
Carrot.stop
|