rabbitmq-jruby-client 0.1.7 → 0.6.0
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 +5 -9
- data/lib/rabbitmq-client.jar +0 -0
- data/lib/rabbitmq_client.rb +16 -2
- data/spec/rabbitmq_client_spec.rb +27 -8
- metadata +1 -1
data/README
CHANGED
|
@@ -5,13 +5,12 @@ See more at http://www.rabbitmq.com
|
|
|
5
5
|
|
|
6
6
|
Getting Started
|
|
7
7
|
===============
|
|
8
|
-
1.
|
|
9
|
-
2. Install
|
|
10
|
-
3. Install JRuby RabbitMQ Client: jruby -S gem install jerryluk-rabbitmq-jruby-client
|
|
8
|
+
1. Install and start RabbitMQ (see below)
|
|
9
|
+
2. Install JRuby RabbitMQ Client: jruby -S gem install rabbitmq-jruby-client
|
|
11
10
|
|
|
12
11
|
Example Usage
|
|
13
12
|
=============
|
|
14
|
-
gem '
|
|
13
|
+
gem 'rabbitmq-jruby-client'
|
|
15
14
|
require 'rabbitmq_client'
|
|
16
15
|
|
|
17
16
|
# Initializes the new client and connect to the server
|
|
@@ -46,10 +45,7 @@ end
|
|
|
46
45
|
Installing RabbitMQ on OS X
|
|
47
46
|
===========================
|
|
48
47
|
1. Install MacPorts
|
|
49
|
-
2. sudo port install
|
|
50
|
-
3. wget http://www.rabbitmq.com/releases/rabbitmq-server/v1.5.3/rabbitmq-server-generic-unix-1.5.3.tar.gz
|
|
51
|
-
4. tar zxvf rabbitmq-server-1.5.3.tar.gz
|
|
52
|
-
5. sudo mv rabbitmq_server-1.5.3 /opt/local/lib/erlang/lib
|
|
48
|
+
2. sudo port install rabbitmq-server
|
|
53
49
|
|
|
54
50
|
To run RabbitMQ
|
|
55
|
-
|
|
51
|
+
3. sudo rabbitmq-server
|
data/lib/rabbitmq-client.jar
CHANGED
|
Binary file
|
data/lib/rabbitmq_client.rb
CHANGED
|
@@ -45,13 +45,17 @@ class RabbitMQClient
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def bind(exchange, routing_key='')
|
|
48
|
+
raise RabbitMQClientError, "queue and exchange has different durable property" unless @durable == exchange.durable
|
|
48
49
|
@routing_key = routing_key
|
|
49
50
|
@exchange = exchange
|
|
50
|
-
raise RabbitMQClientError, "queue and exchange has different durable property" unless @durable == exchange.durable
|
|
51
51
|
@channel.queue_bind(@name, @exchange.name, @routing_key)
|
|
52
52
|
self
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
def unbind
|
|
56
|
+
@channel.queue_unbind(@name, @exchange.name, @routing_key) if @exchange
|
|
57
|
+
end
|
|
58
|
+
|
|
55
59
|
# Set props for different type of message. Currently they are:
|
|
56
60
|
# RabbitMQClient::MessageProperties::MINIMAL_BASIC
|
|
57
61
|
# RabbitMQClient::MessageProperties::MINIMAL_PERSISTENT_BASIC
|
|
@@ -106,6 +110,14 @@ class RabbitMQClient
|
|
|
106
110
|
end
|
|
107
111
|
end
|
|
108
112
|
|
|
113
|
+
def purge
|
|
114
|
+
@channel.queue_purge(@name)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def delete
|
|
118
|
+
@channel.queue_delete(@name)
|
|
119
|
+
end
|
|
120
|
+
|
|
109
121
|
protected
|
|
110
122
|
def auto_bind
|
|
111
123
|
unless @exchange
|
|
@@ -124,7 +136,8 @@ class RabbitMQClient
|
|
|
124
136
|
@type = type
|
|
125
137
|
@durable = durable
|
|
126
138
|
@channel = channel
|
|
127
|
-
|
|
139
|
+
# Declare a non-passive, auto-delete exchange
|
|
140
|
+
@channel.exchange_declare(@name, type.to_s, false, durable, true, nil)
|
|
128
141
|
self
|
|
129
142
|
end
|
|
130
143
|
end
|
|
@@ -169,6 +182,7 @@ class RabbitMQClient
|
|
|
169
182
|
end
|
|
170
183
|
|
|
171
184
|
def disconnect
|
|
185
|
+
@queues.values.each { |q| q.unbind }
|
|
172
186
|
@channel.close
|
|
173
187
|
@connection.close
|
|
174
188
|
@connection = nil
|
|
@@ -24,21 +24,32 @@ describe RabbitMQClient do
|
|
|
24
24
|
exchange.should_not be_nil
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Commented out because it does not return in RSpec
|
|
28
|
+
# it "should be able to delete the queue" do
|
|
29
|
+
# client = RabbitMQClient.new
|
|
30
|
+
# queue = client.queue('test_queue')
|
|
31
|
+
# exchange = client.exchange('test_exchange', 'direct')
|
|
32
|
+
# queue.delete
|
|
33
|
+
# lambda {
|
|
34
|
+
# queue.publish('Hello World')
|
|
35
|
+
# }.should raise_error
|
|
36
|
+
# end
|
|
37
|
+
|
|
27
38
|
describe Queue, "Basic non-persistent queue" do
|
|
28
39
|
before(:each) do
|
|
29
40
|
@queue = @client.queue('test_queue')
|
|
30
41
|
@exchange = @client.exchange('test_exchange', 'direct')
|
|
31
42
|
end
|
|
32
43
|
|
|
33
|
-
it "should able to create a queue" do
|
|
44
|
+
it "should be able to create a queue" do
|
|
34
45
|
@queue.should_not be_nil
|
|
35
46
|
end
|
|
36
47
|
|
|
37
|
-
it "should able to bind to an exchange" do
|
|
48
|
+
it "should be able to bind to an exchange" do
|
|
38
49
|
@queue.bind(@exchange).should_not be_nil
|
|
39
50
|
end
|
|
40
51
|
|
|
41
|
-
it "should able to publish and retrieve a message" do
|
|
52
|
+
it "should be able to publish and retrieve a message" do
|
|
42
53
|
@queue.bind(@exchange)
|
|
43
54
|
@queue.publish('Hello World')
|
|
44
55
|
@queue.retrieve.should == 'Hello World'
|
|
@@ -46,6 +57,14 @@ describe RabbitMQClient do
|
|
|
46
57
|
@queue.retrieve.should == '人大'
|
|
47
58
|
end
|
|
48
59
|
|
|
60
|
+
it "should be able to purge the queue" do
|
|
61
|
+
@queue.publish('Hello World')
|
|
62
|
+
@queue.publish('Hello World')
|
|
63
|
+
@queue.publish('Hello World')
|
|
64
|
+
@queue.purge
|
|
65
|
+
@queue.retrieve.should == nil
|
|
66
|
+
end
|
|
67
|
+
|
|
49
68
|
it "should able to subscribe with a callback function" do
|
|
50
69
|
a = 0
|
|
51
70
|
@queue.bind(@exchange)
|
|
@@ -58,7 +77,7 @@ describe RabbitMQClient do
|
|
|
58
77
|
a.should == 3
|
|
59
78
|
end
|
|
60
79
|
|
|
61
|
-
it "should able to subscribe to a queue using loop_subscribe" do
|
|
80
|
+
it "should be able to subscribe to a queue using loop_subscribe" do
|
|
62
81
|
a = 0
|
|
63
82
|
@queue.bind(@exchange)
|
|
64
83
|
Thread.new do
|
|
@@ -96,21 +115,21 @@ describe RabbitMQClient do
|
|
|
96
115
|
@exchange = @client.exchange('test_durable_exchange', 'fanout', true)
|
|
97
116
|
end
|
|
98
117
|
|
|
99
|
-
it "should able to create a queue" do
|
|
118
|
+
it "should be able to create a queue" do
|
|
100
119
|
@queue.should_not be_nil
|
|
101
120
|
end
|
|
102
121
|
|
|
103
|
-
it "should able to bind to an exchange" do
|
|
122
|
+
it "should be able to bind to an exchange" do
|
|
104
123
|
@queue.bind(@exchange).should_not be_nil
|
|
105
124
|
end
|
|
106
125
|
|
|
107
|
-
it "should able to publish and retrieve a message" do
|
|
126
|
+
it "should be able to publish and retrieve a message" do
|
|
108
127
|
@queue.bind(@exchange)
|
|
109
128
|
@queue.persistent_publish('Hello World')
|
|
110
129
|
@queue.retrieve.should == 'Hello World'
|
|
111
130
|
end
|
|
112
131
|
|
|
113
|
-
it "should able to subscribe with a callback function" do
|
|
132
|
+
it "should be able to subscribe with a callback function" do
|
|
114
133
|
a = 0
|
|
115
134
|
@queue.bind(@exchange)
|
|
116
135
|
@queue.subscribe do |v|
|