iron_mq 5.0.1 → 6.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +19 -17
- data/README.md +420 -70
- data/iron_mq.gemspec +2 -1
- data/lib/iron_mq/client.rb +38 -14
- data/lib/iron_mq/messages.rb +22 -8
- data/lib/iron_mq/queues.rb +105 -66
- data/lib/iron_mq/response.rb +2 -2
- data/lib/iron_mq/subscribers.rb +7 -2
- data/lib/iron_mq/version.rb +1 -1
- data/test/Rakefile +33 -0
- data/test/quick_run.rb +4 -4
- data/test/quick_run2.rb +2 -2
- data/test/test_alerts.rb +79 -32
- data/test/test_base.rb +6 -4
- data/test/test_bulk.rb +1 -1
- data/test/test_iron_mq.rb +183 -141
- data/test/test_mq_worker_subscribers.rb +2 -2
- data/test/test_performance.rb +29 -0
- data/test/test_push_queues.rb +85 -116
- data/test/tmp.rb +2 -0
- metadata +48 -32
- data/test/test_beanstalkd.rb +0 -243
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0885b055e2350a138614235f9ebb4e37b6492dba
|
4
|
+
data.tar.gz: ab9ee84981142ea6aaeca329e684450feeca04b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11bd3d9f14934a8505d666600decf915512338a2a5b03837c35a3daa90dd2ea985a5202b30fe87b5f44571cf5b8b90e259288456b9fc2973427341ccf639c64
|
7
|
+
data.tar.gz: 3b1fc1c17f4e08eaa05401108b28e3ae1ebe25a00f401465d96841abe3695091e09416433452afe37ca79a28c5827d9f5b9918e5935de7d2ad11c92e01542e2e
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iron_mq (5.0.
|
4
|
+
iron_mq (5.0.2)
|
5
5
|
iron_core (>= 0.5.1)
|
6
6
|
|
7
7
|
GEM
|
@@ -9,33 +9,34 @@ GEM
|
|
9
9
|
specs:
|
10
10
|
beanstalk-client (1.1.1)
|
11
11
|
concur (2.1.1)
|
12
|
-
ethon (0.
|
12
|
+
ethon (0.7.1)
|
13
13
|
ffi (>= 1.3.0)
|
14
|
-
|
15
|
-
ffi (1.9.3)
|
14
|
+
ffi (1.9.5)
|
16
15
|
go (1.1.0)
|
17
16
|
concur
|
18
|
-
iron_core (1.0.
|
17
|
+
iron_core (1.0.5)
|
19
18
|
rest (>= 2.6.4)
|
20
|
-
iron_worker_ng (1.
|
19
|
+
iron_worker_ng (1.5.0)
|
21
20
|
bundler
|
22
21
|
iron_core (>= 1.0.0)
|
23
|
-
rubyzip (
|
24
|
-
|
25
|
-
minitest (5.2.3)
|
22
|
+
rubyzip (= 0.9.9)
|
23
|
+
minitest (5.4.2)
|
26
24
|
net-http-persistent (2.9.4)
|
27
25
|
netrc (0.7.7)
|
26
|
+
parallel (1.3.2)
|
27
|
+
power_assert (0.1.4)
|
28
28
|
quicky (0.4.0)
|
29
|
-
rake (10.
|
30
|
-
rest (2.7.
|
29
|
+
rake (10.3.2)
|
30
|
+
rest (2.7.2)
|
31
31
|
net-http-persistent (>= 2.9.1)
|
32
32
|
rest_client (>= 1.7.1)
|
33
|
-
rest_client (1.7.
|
33
|
+
rest_client (1.7.3)
|
34
34
|
netrc (~> 0.7.7)
|
35
|
-
rubyzip (
|
36
|
-
test-unit (
|
37
|
-
|
38
|
-
|
35
|
+
rubyzip (0.9.9)
|
36
|
+
test-unit (3.0.1)
|
37
|
+
power_assert
|
38
|
+
typhoeus (0.6.9)
|
39
|
+
ethon (>= 0.7.1)
|
39
40
|
uber_config (1.1.1)
|
40
41
|
|
41
42
|
PLATFORMS
|
@@ -46,8 +47,9 @@ DEPENDENCIES
|
|
46
47
|
go
|
47
48
|
iron_mq!
|
48
49
|
iron_worker_ng
|
49
|
-
minitest
|
50
|
+
minitest (>= 5.0)
|
50
51
|
net-http-persistent
|
52
|
+
parallel
|
51
53
|
quicky
|
52
54
|
rake
|
53
55
|
test-unit
|
data/README.md
CHANGED
@@ -7,13 +7,30 @@ much as possible so if you see an option in the API docs, you can use it in the
|
|
7
7
|
**WARNING: Version 5+ has some small breaking changes. Version 4 ignored 404's on delete operations, Version
|
8
8
|
5 will now raise exceptions.
|
9
9
|
|
10
|
+
[Important Notes](#important-notes).
|
11
|
+
|
10
12
|
## Getting Started
|
11
13
|
|
12
14
|
1\. Install the gem:
|
13
15
|
|
16
|
+
<!---
|
17
|
+
|
14
18
|
```ruby
|
15
19
|
gem install iron_mq
|
16
20
|
```
|
21
|
+
-->
|
22
|
+
|
23
|
+
We don't have v3 in rubygems yet, but you can use Bundler to easily use this gem. Add this to your Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'iron_mq', git: 'https://github.com/iron-io/iron_mq_ruby.git', branch: 'v3'
|
27
|
+
```
|
28
|
+
|
29
|
+
Then do a `bundle update` and when executing, be sure to use `bundle exec` like so:
|
30
|
+
|
31
|
+
```
|
32
|
+
bundle exec ruby script.rb
|
33
|
+
```
|
17
34
|
|
18
35
|
2\. [Setup your Iron.io credentials](http://dev.iron.io/mq/reference/configuration/)
|
19
36
|
|
@@ -26,15 +43,48 @@ ironmq = IronMQ::Client.new
|
|
26
43
|
Or pass in credentials if you don't want to use an iron.json file or set ENV variables:
|
27
44
|
|
28
45
|
```ruby
|
29
|
-
ironmq = IronMQ::Client.new(:
|
46
|
+
ironmq = IronMQ::Client.new(token: 'MY_TOKEN',
|
47
|
+
project_id: 'MY_PROJECT_ID')
|
30
48
|
```
|
31
49
|
You can also change the host if you want to use a different cloud or region, for example, to use Rackspace ORD:
|
32
50
|
|
33
51
|
```ruby
|
34
|
-
ironmq = IronMQ::Client.new(:
|
52
|
+
ironmq = IronMQ::Client.new(host: 'mq-rackspace-ord.iron.io',
|
53
|
+
token:'MY_TOKEN',
|
54
|
+
project_id: 'MY_PROJECT_ID')
|
35
55
|
```
|
36
56
|
The default host is AWS us-east-1 zone (mq-aws-us-east-1.iron.io). [See all available hosts/clouds/regions](http://dev.iron.io/mq/reference/clouds/).
|
37
57
|
|
58
|
+
### Keystone Authentication
|
59
|
+
|
60
|
+
#### Via Configuration File
|
61
|
+
|
62
|
+
Add `keystone` section to your iron.json file:
|
63
|
+
|
64
|
+
```javascript
|
65
|
+
{
|
66
|
+
"project_id": "57a7b7b35e8e331d45000001",
|
67
|
+
"keystone": {
|
68
|
+
"server": "http://your.keystone.host/v2.0/",
|
69
|
+
"tenant": "some-group",
|
70
|
+
"username": "name",
|
71
|
+
"password": "password"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
```
|
75
|
+
|
76
|
+
#### In Code
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
keystone = {
|
80
|
+
server: "http://your.keystone.host/v2.0/",
|
81
|
+
tenant: "some-gorup",
|
82
|
+
username: "name",
|
83
|
+
password: "password"
|
84
|
+
}
|
85
|
+
client = IronMQ::Client.new(project_id: "57a7b7b35e8e331d45000001", keystone: keystone)
|
86
|
+
```
|
87
|
+
|
38
88
|
## The Basics
|
39
89
|
|
40
90
|
### Get Queues List
|
@@ -50,7 +100,7 @@ list_queues = ironmq.queues # => [#<IronMQ::Queue:...>, ...]
|
|
50
100
|
You can have as many queues as you want, each with their own unique set of messages.
|
51
101
|
|
52
102
|
```ruby
|
53
|
-
queue = ironmq.queue(
|
103
|
+
queue = ironmq.queue('my_queue')
|
54
104
|
```
|
55
105
|
|
56
106
|
Now you can use it.
|
@@ -63,7 +113,7 @@ Messages are placed on the queue in a FIFO arrangement.
|
|
63
113
|
If a queue does not exist, it will be created upon the first posting of a message.
|
64
114
|
|
65
115
|
```ruby
|
66
|
-
queue.post(
|
116
|
+
queue.post('hello world!')
|
67
117
|
```
|
68
118
|
|
69
119
|
--
|
@@ -71,20 +121,23 @@ queue.post("hello world!")
|
|
71
121
|
### Retrieve Queue Information
|
72
122
|
|
73
123
|
```ruby
|
74
|
-
queue.info
|
75
|
-
|
124
|
+
queue.info
|
125
|
+
# => {"id"=>"5127bf043264140e863e2283", "name"=>"my_queue", ...}
|
126
|
+
queue.id
|
127
|
+
# => "5127bf043264140e863e2283"
|
76
128
|
```
|
77
129
|
|
78
130
|
--
|
79
131
|
|
80
|
-
### Get a Message
|
132
|
+
### Reserve/Get a Message from a Queue
|
81
133
|
|
82
134
|
```ruby
|
83
|
-
msg = queue.
|
84
|
-
msg.body
|
135
|
+
msg = queue.reserve
|
136
|
+
msg.body
|
137
|
+
# => "hello world!"
|
85
138
|
```
|
86
139
|
|
87
|
-
When you
|
140
|
+
When you reserve a message from the queue, it is no longer on the queue but it still exists within the system.
|
88
141
|
You have to explicitly delete the message or else it will go back onto the queue after the `timeout`.
|
89
142
|
The default `timeout` is 60 seconds. Minimal `timeout` is 30 seconds.
|
90
143
|
|
@@ -100,6 +153,13 @@ queue.delete(msg.id)
|
|
100
153
|
|
101
154
|
Be sure to delete a message from the queue when you're done with it.
|
102
155
|
|
156
|
+
```ruby
|
157
|
+
messages = queue.reserve(n: 3)
|
158
|
+
queue.delete_reserved_messages(messages)
|
159
|
+
```
|
160
|
+
|
161
|
+
Delete reserved messages when you're done with it.
|
162
|
+
|
103
163
|
--
|
104
164
|
|
105
165
|
|
@@ -108,25 +168,30 @@ Be sure to delete a message from the queue when you're done with it.
|
|
108
168
|
`IronMQ::Client` is based on `IronCore::Client` and provides easy access to the queues.
|
109
169
|
|
110
170
|
```ruby
|
111
|
-
ironmq = IronMQ::Client.new(:
|
171
|
+
ironmq = IronMQ::Client.new(token: 'MY_TOKEN',
|
172
|
+
project_id: 'MY_PROJECT_ID')
|
112
173
|
```
|
113
174
|
|
114
175
|
### List Queues
|
115
176
|
|
116
177
|
```ruby
|
117
|
-
all_queues = ironmq.queues.list
|
178
|
+
all_queues = ironmq.queues.list
|
179
|
+
# => [#<IronMQ::Queue:...>, ...]
|
118
180
|
# or
|
119
|
-
all_queues = ironmq.queues.all
|
181
|
+
all_queues = ironmq.queues.all
|
182
|
+
# => [#<IronMQ::Queue:...>, ...]
|
120
183
|
```
|
121
184
|
|
122
185
|
**Optional parameters:**
|
123
186
|
|
124
|
-
* `
|
125
|
-
* `
|
187
|
+
* `per_page`: number of elements in response, default is 30.
|
188
|
+
* `previous`: this is the last queue on the previous page, it will start from the next one. If queue with specified
|
189
|
+
name doesn’t exist result will contain first per_page queues that lexicographically greater than previous
|
190
|
+
* `prefix`: an optional queue prefix to search on. e.g., prefix=ca could return queues `["cars", "cats", etc.]`
|
126
191
|
* `raw`: Set it to true to obtain data in raw format. The default is false.
|
127
192
|
|
128
193
|
```ruby
|
129
|
-
queues = ironmq.queues.all(:
|
194
|
+
queues = ironmq.queues.all(per_page: 10, previous: 'test_queue')
|
130
195
|
```
|
131
196
|
|
132
197
|
--
|
@@ -134,7 +199,8 @@ queues = ironmq.queues.all(:page => 1, :per_page => 10)
|
|
134
199
|
### Get Queue by Name
|
135
200
|
|
136
201
|
```ruby
|
137
|
-
queue = ironmq.queue
|
202
|
+
queue = ironmq.queue('my_queue')
|
203
|
+
# => #<IronMQ::Queue:...>
|
138
204
|
```
|
139
205
|
|
140
206
|
**Note:** if queue with desired name does not exist it returns fake queue.
|
@@ -144,10 +210,101 @@ Queue will be created automatically on post of first message or queue configurat
|
|
144
210
|
|
145
211
|
## Queues
|
146
212
|
|
213
|
+
### Create a Queue
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
ironmq = IronMQ::Client.new
|
217
|
+
options = {
|
218
|
+
message_timeout: 120,
|
219
|
+
message_expiration: 24 * 3600,
|
220
|
+
push: {
|
221
|
+
subscribers: [
|
222
|
+
{
|
223
|
+
name: 'subscriber_name',
|
224
|
+
url: 'http://rest-test.iron.io/code/200?store=key1',
|
225
|
+
headers: {
|
226
|
+
'Content-Type' => 'application/json'
|
227
|
+
}
|
228
|
+
}
|
229
|
+
],
|
230
|
+
retries: 3,
|
231
|
+
retries_delay: 30,
|
232
|
+
error_queue: 'error_queue_name'
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
ironmq.create_queue(options)
|
237
|
+
```
|
238
|
+
|
239
|
+
**Options:**
|
240
|
+
|
241
|
+
* `type`: String or symbol. Queue type. `:pull`, `:multicast`, `:unicast`. Field required and static.
|
242
|
+
* `message_timeout`: Integer. Number of seconds before message back to queue if it will not be deleted or touched.
|
243
|
+
* `message_expiration`: Integer. Number of seconds between message post to queue and before message will be expired.
|
244
|
+
|
245
|
+
**Push queues only:**
|
246
|
+
|
247
|
+
* `push: subscribers`: An array of subscriber hashes containing a `name` and a `url` required fields,
|
248
|
+
and optional `headers` hash. `headers`'s keys are names and values are means of HTTP headers.
|
249
|
+
This set of subscribers will replace the existing subscribers.
|
250
|
+
To add or remove subscribers, see the add subscribers endpoint or the remove subscribers endpoint.
|
251
|
+
See below for example json.
|
252
|
+
* `push: retries`: How many times to retry on failure. Default is 3. Maximum is 100.
|
253
|
+
* `push: retries_delay`: Delay between each retry in seconds. Default is 60.
|
254
|
+
* `push: error_queue`: String. Queue name to post push errors to.
|
255
|
+
|
256
|
+
--
|
257
|
+
|
258
|
+
### Add subscribers to a push queue
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
subscribers = [
|
262
|
+
{
|
263
|
+
name: 'first',
|
264
|
+
url: 'http://first.endpoint.xx/process',
|
265
|
+
headers: {
|
266
|
+
Content-Type: 'application/json'
|
267
|
+
}
|
268
|
+
},
|
269
|
+
{
|
270
|
+
name: 'second',
|
271
|
+
url: 'http://second.endpoint.xx/process',
|
272
|
+
}
|
273
|
+
]
|
274
|
+
queue.add_subscribers(subscribers)
|
275
|
+
```
|
276
|
+
|
277
|
+
### Replace subscribers on a push queue
|
278
|
+
|
279
|
+
Sets list of subscribers to a queue. Older subscribers will be removed.
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
subscribers = [
|
283
|
+
{
|
284
|
+
name: 'the_only',
|
285
|
+
url: 'http://my.over9k.host.com/push'
|
286
|
+
}
|
287
|
+
]
|
288
|
+
queue.replace_subscribers(subscribers);
|
289
|
+
```
|
290
|
+
|
291
|
+
### Remove subscribers by a name from a push queue
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
subscribers = [
|
295
|
+
{
|
296
|
+
name: 'the_only'
|
297
|
+
}
|
298
|
+
]
|
299
|
+
queue.remove_subscribers(subscribers)
|
300
|
+
```
|
301
|
+
--
|
302
|
+
|
147
303
|
### Retrieve Queue Information
|
148
304
|
|
149
305
|
```ruby
|
150
|
-
info = queue.info
|
306
|
+
info = queue.info
|
307
|
+
# => {"id"=>"5127bf043264140e863e2283", "name"=>"my_queue", ...}
|
151
308
|
```
|
152
309
|
|
153
310
|
Shortcuts for `queue.info[key]`:
|
@@ -158,7 +315,8 @@ id = queue.id # => "5127bf043264140e863e2283"
|
|
158
315
|
size = queue.size # => 7
|
159
316
|
name = queue.name # => "my_queue"
|
160
317
|
overall_messages = queue.total_messages # => 13
|
161
|
-
subscribers = queue.subscribers
|
318
|
+
subscribers = queue.subscribers
|
319
|
+
# => [{"url" => "http://..."}, ...]
|
162
320
|
|
163
321
|
push_type = queue.push_type # => "multicast"
|
164
322
|
# Does queue Push Queue? Alias for `queue.push_type.nil?`
|
@@ -174,7 +332,7 @@ In this case you may prefer to use `queue.info` to have `Hash` with all availabl
|
|
174
332
|
### Delete a Message Queue
|
175
333
|
|
176
334
|
```ruby
|
177
|
-
response = queue.
|
335
|
+
response = queue.delete # => #<IronMQ::ResponseBase:...>
|
178
336
|
```
|
179
337
|
|
180
338
|
--
|
@@ -184,9 +342,10 @@ response = queue.delete_queue # => #<IronMQ::ResponseBase:...>
|
|
184
342
|
**Single message:**
|
185
343
|
|
186
344
|
```ruby
|
187
|
-
response = queue.post(
|
345
|
+
response = queue.post('something helpful') # => #<IronMQ::ResponseBase:...>
|
188
346
|
# or
|
189
|
-
response = queue.post(
|
347
|
+
response = queue.post('with parameteres', timeout: 300)
|
348
|
+
# => #<IronMQ::ResponseBase:...>
|
190
349
|
|
191
350
|
message_id = response.id # => "5847899158098068288"
|
192
351
|
status_message = response.msg # => "Messages put on queue."
|
@@ -195,12 +354,14 @@ http_code = response.code # => 200
|
|
195
354
|
|
196
355
|
**Multiple messages:**
|
197
356
|
```ruby
|
198
|
-
# [{:
|
199
|
-
messages = [{:
|
357
|
+
# [{body: VALUE}, ...] format is required
|
358
|
+
messages = [{body: 'first'}, {body: 'second'}]
|
200
359
|
|
201
|
-
response = queue.post(messages)
|
360
|
+
response = queue.post(messages)
|
361
|
+
# => {"ids" => ["5847899158098068288", ...], "msg" => "Messages put on queue."}
|
202
362
|
# or
|
203
|
-
response = queue.post(messages, :
|
363
|
+
response = queue.post(messages, timeout: 300)
|
364
|
+
# => {"ids" => ["5847899158098068288", ...], "msg" => "Messages put on queue."}
|
204
365
|
```
|
205
366
|
|
206
367
|
**Optional parameters:**
|
@@ -220,23 +381,25 @@ Default is 604,800 seconds (7 days). Maximum is 2,592,000 seconds (30 days).
|
|
220
381
|
### Get Messages from a Queue
|
221
382
|
|
222
383
|
```ruby
|
223
|
-
message = queue.
|
384
|
+
message = queue.reserve # => #<IronMQ::Message:...>
|
224
385
|
|
225
386
|
# or N messages
|
226
|
-
messages = queue.
|
387
|
+
messages = queue.reserve(n: 7) # => [#<IronMQ::Message:...>, ...]
|
227
388
|
|
228
389
|
# or message by ID
|
229
|
-
message = queue.
|
390
|
+
message = queue.get_message '5127bf043264140e863e2283'
|
391
|
+
# => #<IronMQ::Message:...>
|
230
392
|
```
|
231
393
|
|
232
394
|
**Optional parameters:**
|
233
395
|
|
234
396
|
* `n`: The maximum number of messages to get. Default is 1. Maximum is 100.
|
235
|
-
|
236
397
|
* `timeout`: After timeout (in seconds), item will be placed back onto queue.
|
237
398
|
You must delete the message from the queue to ensure it does not go back onto the queue.
|
238
399
|
If not set, value from POST is used. Default is 60 seconds. Minimum is 30 seconds.
|
239
400
|
Maximum is 86,400 seconds (24 hours).
|
401
|
+
* `wait`: : Time in seconds to wait for a message to become available. This enables long polling. Default is 0 (does not wait), maximum is 30.
|
402
|
+
* `delete`: true/false. This will delete the message on get. Be careful though, only use this if you are ok with losing a message if something goes wrong after you get it. Default is false.
|
240
403
|
|
241
404
|
When `n` parameter is specified and greater than 1 method returns `Array` of `Message`s.
|
242
405
|
Otherwise, `Message` object would be returned.
|
@@ -248,7 +411,7 @@ Otherwise, `Message` object would be returned.
|
|
248
411
|
Touching a reserved message extends its timeout by the duration specified when the message was created, which is 60 seconds by default.
|
249
412
|
|
250
413
|
```ruby
|
251
|
-
message = queue.
|
414
|
+
message = queue.reserve # => #<IronMQ::Message:...>
|
252
415
|
|
253
416
|
message.touch # => #<IronMQ::ResponseBase:...>
|
254
417
|
```
|
@@ -258,11 +421,11 @@ message.touch # => #<IronMQ::ResponseBase:...>
|
|
258
421
|
### Release Message
|
259
422
|
|
260
423
|
```ruby
|
261
|
-
message = queue.
|
424
|
+
message = queue.reserve # => #<IronMQ::Message:...>
|
262
425
|
|
263
426
|
response = message.release # => #<IronMQ::ResponseBase:...>
|
264
427
|
# or
|
265
|
-
response = message.release(:
|
428
|
+
response = message.release(delay: 42) # => #<IronMQ::ResponseBase:...>
|
266
429
|
```
|
267
430
|
|
268
431
|
**Optional parameters:**
|
@@ -275,7 +438,7 @@ Default is 0 seconds. Maximum is 604,800 seconds (7 days).
|
|
275
438
|
### Delete a Message from a Queue
|
276
439
|
|
277
440
|
```ruby
|
278
|
-
message = queue.
|
441
|
+
message = queue.reserve # => #<IronMQ::Queue:...>
|
279
442
|
|
280
443
|
message.delete # => #<IronMQ::ResponseBase:...>
|
281
444
|
```
|
@@ -289,7 +452,8 @@ Peeking at a queue returns the next messages on the queue, but it does not reser
|
|
289
452
|
```ruby
|
290
453
|
message = queue.peek # => #<IronMQ::Message:...>
|
291
454
|
# or multiple messages
|
292
|
-
messages = queue.peek(:
|
455
|
+
messages = queue.peek(n: 13)
|
456
|
+
# => [#<IronMQ::Message:...>, ...]
|
293
457
|
```
|
294
458
|
|
295
459
|
**Optional parameters:**
|
@@ -313,6 +477,36 @@ Polling will automatically delete the message at the end of the block.
|
|
313
477
|
```ruby
|
314
478
|
queue.clear # => #<IronMQ::ResponseBase:...>
|
315
479
|
```
|
480
|
+
### Add an Alert to a Queue
|
481
|
+
|
482
|
+
[Check out our Blog Post on Queue Alerts](http://blog.iron.io).
|
483
|
+
|
484
|
+
Alerts have now been incorporated into IronMQ. This feature lets developers control actions based on the activity within a queue. With alerts, actions can be triggered when the number of messages in a queue reach a certain threshold. These actions can include things like auto-scaling, failure detection, load-monitoring, and system health.
|
485
|
+
|
486
|
+
You may add up to 5 alerts per queue.
|
487
|
+
|
488
|
+
**Required parameters:**
|
489
|
+
* `type`: required - "fixed" or "progressive". In case of alert's type set to "fixed", alert will be triggered when queue size pass value set by trigger parameter. When type set to "progressive", alert will be triggered when queue size pass any of values, calculated by trigger * N where N >= 1. For example, if trigger set to 10, alert will be triggered at queue sizes 10, 20, 30, etc.
|
490
|
+
* `direction`: required - "asc" or "desc". Set direction in which queue size must be changed when pass trigger value. If direction set to "asc" queue size must growing to trigger alert. When direction is "desc" queue size must decreasing to trigger alert.
|
491
|
+
* `trigger`: required. It will be used to calculate actual values of queue size when alert must be triggered. See type field description. Trigger must be integer value greater than 0.
|
492
|
+
* `queue`: required. Name of queue which will be used to post alert messages.
|
493
|
+
|
494
|
+
**Optional parameters:**
|
495
|
+
|
496
|
+
* `snooze`: Number of seconds between alerts. If alert must be triggered but snooze is still active, alert will be omitted. Snooze must be integer value greater than or equal to 0.
|
497
|
+
|
498
|
+
```ruby
|
499
|
+
queue.add_alert({
|
500
|
+
type: 'progressive',
|
501
|
+
trigger: 10,
|
502
|
+
queue: 'my_alert_queue',
|
503
|
+
direction: 'asc',
|
504
|
+
snooze: 0
|
505
|
+
})
|
506
|
+
queue.clear
|
507
|
+
# => #<IronMQ::ResponseBase:0x007f95d3b25438 @raw={"msg"=>"Updated"}, @code=200>
|
508
|
+
```
|
509
|
+
|
316
510
|
|
317
511
|
--
|
318
512
|
|
@@ -325,36 +519,65 @@ IronMQ push queues allow you to setup a queue that will push to an endpoint, rat
|
|
325
519
|
### Update a Message Queue
|
326
520
|
|
327
521
|
```ruby
|
328
|
-
|
522
|
+
options = {
|
523
|
+
message_timeout: 120,
|
524
|
+
message_expiration: 24 * 3600,
|
525
|
+
push: {
|
526
|
+
subscribers: [
|
527
|
+
{
|
528
|
+
name: 'subscriber_name',
|
529
|
+
url: 'http://rest-test.iron.io/code/200?store=key1',
|
530
|
+
headers: {
|
531
|
+
'Content-Type' => 'application/json'
|
532
|
+
}
|
533
|
+
}
|
534
|
+
],
|
535
|
+
retries: 3,
|
536
|
+
retries_delay: 30,
|
537
|
+
error_queue: 'error_queue_name'
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
541
|
+
queue.update(options)
|
329
542
|
```
|
330
543
|
|
331
544
|
**The following parameters are all related to Push Queues:**
|
332
545
|
|
333
|
-
* `subscribers`: An array of subscriber hashes containing a
|
546
|
+
* `push: subscribers`: An array of subscriber hashes containing a `name` and a `url` required fields,
|
547
|
+
and optional `headers` hash. `headers`'s keys are names and values are means of HTTP headers.
|
334
548
|
This set of subscribers will replace the existing subscribers.
|
335
549
|
To add or remove subscribers, see the add subscribers endpoint or the remove subscribers endpoint.
|
336
550
|
See below for example json.
|
337
|
-
* `
|
338
|
-
* `
|
339
|
-
* `
|
551
|
+
* `push: retries`: How many times to retry on failure. Default is 3. Maximum is 100.
|
552
|
+
* `push: retries_delay`: Delay between each retry in seconds. Default is 60.
|
553
|
+
* `push: error_queue`: String. Queue name to post push errors to.
|
554
|
+
|
555
|
+
**Note:** queue type cannot be changed.
|
340
556
|
|
341
557
|
--
|
342
558
|
|
343
559
|
### Set Subscribers on a Queue
|
344
560
|
|
345
|
-
Subscribers can be any HTTP endpoint. `
|
561
|
+
Subscribers can be any HTTP endpoint. push `type` is one of:
|
346
562
|
|
347
563
|
* `multicast`: will push to all endpoints/subscribers
|
348
564
|
* `unicast`: will push to one and only one endpoint/subscriber
|
349
565
|
|
350
566
|
```ruby
|
351
|
-
|
352
|
-
subscribers =
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
567
|
+
ironmq = IronMQ::Client.new
|
568
|
+
subscribers =
|
569
|
+
[
|
570
|
+
{
|
571
|
+
name: 'key-one-sub',
|
572
|
+
url: 'http://rest-test.iron.io/code/200?store=key1'
|
573
|
+
},
|
574
|
+
{
|
575
|
+
name: 'key-two-sub',
|
576
|
+
url: 'http://rest-test.iron.io/code/200?store=key2'
|
577
|
+
}
|
578
|
+
]
|
579
|
+
ironmq.create_queue('queue_name', type: :multicast,
|
580
|
+
push: {subscribers: subscribers})
|
358
581
|
```
|
359
582
|
|
360
583
|
--
|
@@ -362,20 +585,26 @@ queue.update(:subscribers => subscribers, :push_type => ptype)
|
|
362
585
|
### Add/Remove Subscribers on a Queue
|
363
586
|
|
364
587
|
```ruby
|
365
|
-
queue.add_subscriber({
|
588
|
+
queue.add_subscriber({
|
589
|
+
name: 'nowhere',
|
590
|
+
url: 'http://nowhere.com/push'
|
591
|
+
})
|
366
592
|
|
367
593
|
queue.add_subscribers([
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
594
|
+
{
|
595
|
+
name: 'first',
|
596
|
+
url: 'http://first.endpoint.xx/process',
|
597
|
+
headers: {
|
598
|
+
'Content-Type': 'application/json'
|
599
|
+
}
|
600
|
+
},
|
601
|
+
{
|
602
|
+
name: 'second',
|
603
|
+
url: 'http://second.endpoint.xx/process'
|
604
|
+
}
|
605
|
+
])
|
606
|
+
|
607
|
+
queue.clear_subscribers
|
379
608
|
```
|
380
609
|
|
381
610
|
--
|
@@ -387,9 +616,11 @@ instead getting it by ID returned in API response. To do this just set `:instant
|
|
387
616
|
to `true`.
|
388
617
|
|
389
618
|
```ruby
|
390
|
-
message = queue.post('push me!', :
|
619
|
+
message = queue.post('push me!', instantiate: true)
|
620
|
+
# => #<IronMQ::Message:...>
|
391
621
|
|
392
|
-
msgs = queue([{:
|
622
|
+
msgs = queue.post([{body: 'push'}, {body: 'me'}], instantiate: true)
|
623
|
+
# => [#<IronMQ::Message:...>, ...]
|
393
624
|
```
|
394
625
|
|
395
626
|
This creates fake `Message` objects. They contain only IDs.
|
@@ -401,9 +632,12 @@ This creates fake `Message` objects. They contain only IDs.
|
|
401
632
|
After pushing a message:
|
402
633
|
|
403
634
|
```ruby
|
404
|
-
|
635
|
+
statuses = queue.get_message(msg.id).push_statuses
|
636
|
+
# => [#<IronMQ::Subscriber:...>, ...]
|
405
637
|
|
406
|
-
|
638
|
+
statuses.each do |s|
|
639
|
+
puts "#{s.subscriber_name}: #{(s.code == 200) ? 'Success' : 'Fail'}"
|
640
|
+
end
|
407
641
|
```
|
408
642
|
|
409
643
|
Returns an array of subscribers with status.
|
@@ -416,26 +650,142 @@ This creates fake `IronMQ::Message` instance on which you call for subscribers'
|
|
416
650
|
### Acknowledge / Delete Message Push Status
|
417
651
|
|
418
652
|
```ruby
|
419
|
-
subscribers = queue.
|
653
|
+
subscribers = queue.get_message(msg.id).subscribers
|
654
|
+
# => [#<IronMQ::Subscriber:...>, ...]
|
420
655
|
|
421
656
|
subscribers.each do |ss|
|
422
657
|
ss.delete
|
423
|
-
# ss.acknowledge # This is `delete` alias
|
658
|
+
# ss.acknowledge # This is `delete`'s alias
|
424
659
|
end
|
425
660
|
```
|
426
661
|
|
427
662
|
--
|
428
663
|
|
429
|
-
|
664
|
+
## Queue Alerts
|
665
|
+
|
666
|
+
Queue Alerts allow you to set queue's size levels which are critical
|
667
|
+
for your application. For example, you want to start processing worker
|
668
|
+
when queue size grows from 0 to 1. Then add alert of `type` "fixed",
|
669
|
+
`direction` "asc", and `trigger` 1. In this case, if queue size changed
|
670
|
+
from 0 to 1 alert message will be put on queue, set by `queue`
|
671
|
+
parameter of alert's hash. If you want to prevent alerts to be put onto
|
672
|
+
alert queue in some time after previous alert message - use `snooze`
|
673
|
+
parameter. For example, to make alert silent in one hour, set `snooze`
|
674
|
+
to 3600 (seconds).
|
675
|
+
|
676
|
+
**Note:** alerts feature are only avalable for Pull (or regular) Queues.
|
677
|
+
|
678
|
+
See [Queue Alerts](http://dev.iron.io/mq/reference/queue_alerts/) to learn more.
|
679
|
+
|
680
|
+
### Alerts Parameters
|
681
|
+
|
682
|
+
Alerts can be configured with the following parameters:
|
683
|
+
|
684
|
+
* `type`: string, required. Type of alert. Available types are "fixed"
|
685
|
+
and "progressive".
|
686
|
+
* `direction`: string, optional. Direction of queue fluctuations.
|
687
|
+
Available directions are "asc" (alert will be triggered if queue
|
688
|
+
size grows) and "desc" (alert will be triggered if queue size
|
689
|
+
decreases). Defaults to "asc".
|
690
|
+
* `trigger`: integer, required. Value which is used to calculate
|
691
|
+
actual queue size when alert will be triggered. In case of "fixed"
|
692
|
+
type of alert `trigger` itself represents actual queue size. When
|
693
|
+
type of alert is "progressive", actual queue sizes are calculated by
|
694
|
+
`trigger * N`, where `N` is integer greater than 0. For example,
|
695
|
+
type is "progressive" and trigger is 100. Alert messages will be put
|
696
|
+
on queue at sizes 100, 200, 300, ...
|
697
|
+
* `queue`: string, required. Name of a queue which receives alert messages.
|
698
|
+
* `snooze`: integer, optional. Represents number of seconds alert will
|
699
|
+
be silent after latter message, put onto alert queue.
|
430
700
|
|
431
|
-
|
701
|
+
**Note:** IronMQ backend checks for alerts duplications each time you
|
702
|
+
add new alerts to a queue. It compares `type`, `direction`, and
|
703
|
+
`trigger` parameters to find duplicates. If one or more of new
|
704
|
+
alerts duplicates existing, backend return `HTTP 400` error, message
|
705
|
+
will be `{"msg": "At least one new alert duplicates current queue alerts."}`.
|
706
|
+
|
707
|
+
### Add Alerts to a Queue
|
708
|
+
|
709
|
+
To add single alert to a queue.
|
432
710
|
|
433
711
|
```ruby
|
434
|
-
queue.
|
712
|
+
queue.add_alert({
|
713
|
+
type: 'fixed',
|
714
|
+
direction: 'asc',
|
715
|
+
trigger: 1,
|
716
|
+
queue: 'alerts-queue',
|
717
|
+
snooze: 600
|
718
|
+
})
|
719
|
+
# => #<IronMQ::ResponseBase:0x007f8d22980420 @raw={"msg"=>"Alerts were added."}, @code=200>
|
435
720
|
```
|
436
721
|
|
437
|
-
|
722
|
+
To add multiple alerts at a time.
|
723
|
+
|
724
|
+
```ruby
|
725
|
+
queue.add_alerts([
|
726
|
+
{
|
727
|
+
type: 'fixed',
|
728
|
+
direction: 'desc',
|
729
|
+
trigger: 1,
|
730
|
+
queue: 'alerts-queue'
|
731
|
+
},
|
732
|
+
{
|
733
|
+
type: 'progressive',
|
734
|
+
trigger: 1000,
|
735
|
+
queue: 'critical-alerts-queue'
|
736
|
+
}
|
737
|
+
])
|
738
|
+
# => #<IronMQ::ResponseBase:0x00abcdf1980420 @raw={"msg"=>"Alerts were added."}, @code=200>
|
739
|
+
```
|
740
|
+
|
741
|
+
### Remove Alerts from a Queue
|
742
|
+
|
743
|
+
To remove single alert by its ID.
|
744
|
+
|
745
|
+
```ruby
|
746
|
+
queue.remove_alert({ id: '5eee546df4a4140e8638a7e5' })
|
747
|
+
# => #<IronMQ::ResponseBase:0x007f8d229a1878 @raw={"msg"=>"Alerts were deleted."}, @code=200>
|
748
|
+
```
|
749
|
+
|
750
|
+
Remove multiple alerts by IDs.
|
751
|
+
|
752
|
+
```ruby
|
753
|
+
queue.remove_alerts([
|
754
|
+
{ id: '53060b541185ab3eaf04c83f' },
|
755
|
+
{ id: '99a50b541185ab3eaf9bcfff' }
|
756
|
+
])
|
757
|
+
# => #<IronMQ::ResponseBase:0x093b8d229a18af @raw={"msg"=>"Alerts were deleted."}, @code=200>
|
758
|
+
```
|
759
|
+
|
760
|
+
### Replace and Clear Alerts on a Queue
|
761
|
+
|
762
|
+
Following code sample shows how to replace alerts on a queue.
|
763
|
+
|
764
|
+
```ruby
|
765
|
+
queue.replace_alerts([
|
766
|
+
{
|
767
|
+
type: 'fixed',
|
768
|
+
trigger: 100,
|
769
|
+
queue: 'alerts'
|
770
|
+
}
|
771
|
+
])
|
772
|
+
# => #<IronMQ::ResponseBase:0x00008d229a16bf @raw={"msg"=>"Alerts were replaced."}, @code=200>
|
773
|
+
```
|
774
|
+
|
775
|
+
To clear alerts on a queue.
|
776
|
+
|
777
|
+
```ruby
|
778
|
+
queue.clear_alerts
|
779
|
+
# => #<IronMQ::ResponseBase:0x87ad13ff3a18af @raw={"msg"=>"Alerts were replaced."}, @code=200>
|
780
|
+
```
|
781
|
+
|
782
|
+
**Note:** `Queue#clear_alerts` is a helper, which represents
|
783
|
+
`Queue#replace_alerts` call with empty `Array` of alerts.
|
784
|
+
|
785
|
+
## Important Notes
|
438
786
|
|
787
|
+
* [Ruby 1.8 is no more supported](https://www.ruby-lang.org/en/news/2013/06/30/we-retire-1-8-7/).
|
788
|
+
* Queue type is static now. Once it is set, it cannot be changed.
|
439
789
|
|
440
790
|
## Further Links
|
441
791
|
|