celldee-bunny 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -31,20 +31,17 @@ There is a Google Group for discussing bunny - [bunny-amqp](http://groups.google
31
31
  # declare a queue
32
32
  q = b.queue('test1')
33
33
 
34
- # create a direct exchange
35
- exch = b.exchange(:direct, 'test_ex')
36
-
37
- # bind the queue to the exchange
38
- q.bind(exch)
39
-
40
- # publish a message to the exchange
41
- exch.publish('Hello everybody!')
34
+ # publish a message to the queue
35
+ q.publish('Hello everybody!')
42
36
 
43
37
  # get message from the queue
44
38
  msg = q.pop
45
39
 
46
40
  puts 'This is the message: ' + msg + "\n\n"
47
41
 
42
+ # close the connection
43
+ b.close
44
+
48
45
  ## Acknowledgements
49
46
 
50
47
  This project has borrowed heavily from the following two projects and owes their respective creators and collaborators a whole lot of gratitude:
data/lib/amqp.rb CHANGED
@@ -2,4 +2,14 @@ module AMQP
2
2
  %w[ spec buffer protocol frame client ].each do |file|
3
3
  require "amqp/#{file}"
4
4
  end
5
+
6
+ # constants
7
+ CONNECTED = 'CONNECTED'
8
+ NOT_CONNECTED = 'NOT CONNECTED'
9
+
10
+ # specific error definitions
11
+ class ProtocolError < StandardError; end
12
+ class ServerDown < StandardError; end
13
+ class Overflow < StandardError; end
14
+ class InvalidType < StandardError; end
5
15
  end
data/lib/amqp/buffer.rb CHANGED
@@ -10,8 +10,6 @@ end
10
10
 
11
11
  module AMQP
12
12
  class Buffer #:nodoc: all
13
- class Overflow < StandardError; end
14
- class InvalidType < StandardError; end
15
13
 
16
14
  def initialize data = ''
17
15
  @data = data
data/lib/amqp/client.rb CHANGED
@@ -6,9 +6,6 @@ module AMQP
6
6
  attr_reader :status
7
7
  attr_accessor :channel, :host, :logging, :exchanges, :queues, :port, :ticket
8
8
 
9
- class ServerDown < StandardError; end
10
- class ProtocolError < StandardError; end
11
-
12
9
  def initialize(opts = {})
13
10
  @host = opts[:host] || 'localhost'
14
11
  @port = opts[:port] || AMQP::PORT
@@ -17,7 +14,7 @@ module AMQP
17
14
  @vhost = opts[:vhost] || '/'
18
15
  @logging = opts[:logging] || false
19
16
  @insist = opts[:insist]
20
- @status = 'NOT CONNECTED'
17
+ @status = NOT_CONNECTED
21
18
  end
22
19
 
23
20
  def exchanges
@@ -148,7 +145,7 @@ module AMQP
148
145
  if Socket.constants.include? 'TCP_NODELAY'
149
146
  @socket.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
150
147
  end
151
- @status = 'CONNECTED'
148
+ @status = CONNECTED
152
149
  rescue SocketError, SystemCallError, IOError, Timeout::Error => e
153
150
  raise ServerDown, e.message
154
151
  end
@@ -160,14 +157,14 @@ module AMQP
160
157
  # Close the socket. The server is not considered dead.
161
158
  @socket.close if @socket and not @socket.closed?
162
159
  @socket = nil
163
- @status = "NOT CONNECTED"
160
+ @status = NOT_CONNECTED
164
161
  end
165
162
 
166
163
  def log(*args)
167
164
  return unless logging
168
165
  require 'pp'
169
166
  pp args
170
- puts
167
+ puts
171
168
  end
172
169
 
173
170
  end
data/lib/amqp/frame.rb CHANGED
@@ -29,8 +29,6 @@ module AMQP
29
29
  end
30
30
  end
31
31
 
32
- class Invalid < StandardError; end
33
-
34
32
  class Method
35
33
  def initialize payload = nil, channel = 0
36
34
  super
data/lib/bunny.rb CHANGED
@@ -12,8 +12,6 @@ class Bunny
12
12
 
13
13
  attr_reader :client
14
14
 
15
- class Error < StandardError; end
16
-
17
15
  def initialize(opts = {})
18
16
  @client = AMQP::Client.new(opts)
19
17
  end
@@ -5,6 +5,9 @@ class Exchange
5
5
  attr_reader :client, :type, :name, :opts, :key
6
6
 
7
7
  def initialize(client, type, name, opts = {})
8
+ # check connection to server
9
+ raise 'Not connected to server' if client.status == NOT_CONNECTED
10
+
8
11
  @client, @type, @name, @opts = client, type, name, opts
9
12
  @key = opts[:key]
10
13
  @client.exchanges[@name] ||= self
data/lib/bunny/queue.rb CHANGED
@@ -6,6 +6,9 @@
6
6
  attr_accessor :delivery_tag
7
7
 
8
8
  def initialize(client, name, opts = {})
9
+ # check connection to server
10
+ raise 'Not connected to server' if client.status == NOT_CONNECTED
11
+
9
12
  @client = client
10
13
  @opts = opts
11
14
  @name = name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celldee-bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan