-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.html
473 lines (346 loc) · 14.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
---
title: IronMQ Documentation
summary: "Connect your applications and processes with an elastic message queue. Decouple your processes and create a highly scalable system by passing messages."
layout: default
section: mq
languages:
- name: curl
slug: curl
default: true
- name: Ruby
slug: ruby
- name: PHP
slug: php
- name: Python
slug: python
- name: "Node.js"
slug: nodejs
- name: Go
slug: go
- name: Java
slug: java
- name: Clojure
slug: clojure
- name: ".NET"
slug: dotnet
---
<div class="flow-steps">
<div class="step">
<a class="number" href="#configure">1</a>
<a class="title" href="#configure">Configure Your Client</a>
</div>
<i class="icon-long-arrow-right icon-2x"></i>
<div class="step">
<a class="number" href="#post">2</a>
<a class="title" href="#post">Post a Message to the Queue</a>
</div>
<i class="icon-long-arrow-right icon-2x"></i>
<div class="step">
<a class="number" href="#get">3</a>
<a class="title" href="#get">Get a Message off the Queue</a>
</div>
<i class="icon-long-arrow-right icon-2x"></i>
<div class="step">
<a class="number" href="#delete">4</a>
<a class="title" href="#delete">Delete a Message from the Queue</a>
</div>
</div>
<h2>The Post/Get/Delete Paradigm</h2>
<p>IronMQ was designed to be fault-tolerant while still maintaining an only-delivered-once promise. It accomplishes this through a special Post/Get/Delete paradigm for messages. Essentially, messages are posted to a queue. Clients then get the messages off the queue; each get "reserves" the message for a configurable amount of time—<a href="/mq/reference/environment">the default is one minute</a>—after which the message is returned to the queue. While the client has the message reserved, it should complete its operation, then delete the message from the queue. This paradigm ensures that failures while processing a message simply return the message to the queue to be reprocessed and that only one client will ever be processing a message at any given point. Assuming the client deletes the message (as it should), the message will only ever be processed once.</p>
<h2 id="configure">1. Get a project ID and auth token</h2>
<p>You can retrieve your project ID and token from the <a href="https://hud.iron.io">HUD</a> by clicking on a project then clicking the little key icon.
</p>
<h2 id="post">2. Post a Message to a Queue</h2>
<p>All the Iron.io APIs are REST-based with JSON bodies and use OAuth2 for authentication. Here's an example HTTP request for posting to a queue:</p>
<div class="grey-box">
POST https://mq-aws-us-east-1.iron.io:443/1/projects/{PROJECT_ID}/queues/test_queue/messages
</div>
<h3>Request</h3>
<h4>Headers</h4>
<ul>
<li>Authorization: OAuth {TOKEN}</li>
<li>Content-Type: application/json</li>
</ul>
<h4>Body</h4>
{% highlight js%}
{"messages":[{"body":"hello world!"}]}
{% endhighlight %}
<h3>Response</h3>
{% highlight js%}
{"ids":["5824513078343549739"],"msg":"Messages put on queue."}
{% endhighlight %}
<div class="language curl"><h3>Curl Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight bash %}
curl -i -H "Content-Type: application/json" -H "Authorization: OAuth {TOKEN}" -X POST -d '{"messages":[{"body":"hello world!"}]}' "https://mq-aws-us-east-1.iron.io/1/projects/{PROJECT_ID}/queues/test_queue/messages"
{% endhighlight %}</div>
<div class="language ruby"><h3>Ruby Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight ruby %}
@ironmq = IronMQ::Client.new()
@queue = @ironmq.queue("test_queue")
@queue.post("hello world!")
{% endhighlight %}</div>
<div class="language php"><h3>PHP Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight php %}
<?php
$ironmq = new IronMQ();
$ironmq->postMessage("test_queue", "Hello world!");
{% endhighlight %}</div>
<div class="language python"><h3>Python Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight python %}
ironmq = IronMQ()
queue = ironmq.queue("test_queue")
queue.post("hello world!")
{% endhighlight %}</div>
<div class="language nodejs"><h3>Node.js Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight js %}
var iron_mq = require('iron_mq');
var imq = new iron_mq.Client();
var queue = imq.queue("test_queue");
queue.post("Hello, IronMQ!", function(error, body) {
console.log(error, body);
});
{% endhighlight %}</div>
<div class="language go"><h3>Go Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight go %}
package main
import (
"fmt"
"github.com/iron-io/iron_go/mq"
)
func main() {
queue := mq.New("hello_queue")
id, err := queue.PushString("Hello, world!")
fmt.Println(id, err)
}
{% endhighlight %}</div>
<div class="language java"><h3>Java Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight java %}
Client client = new Client("{PROJECT_ID}", "{TOKEN}", Cloud.IronAWSUSEast);
Queue queue = client.queue("test_queue");
queue.push("Hello world!");
{% endhighlight %}</div>
<div class="language clojure"><h3>Clojure Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight clojure %}
(def client (mq/create-client "{TOKEN}" "{PROJECT_ID}"))
(mq/post-message client "test_queue" "Hello world!")
{% endhighlight %}</div>
<div class="language dotnet"><h3>.NET Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight c# %}
Client client = new Client("{PROJECT_ID}", "{TOKEN}");
Queue queue = client.queue("test_queue");
queue.push("Hello world!");
{% endhighlight %}</div>
<h2 id="get">3. Get a Message off the Queue</h2>
<p>Getting a message off the queue is simple:</p>
{% highlight bash %}
GET https://mq-aws-us-east-1.iron.io:443/1/projects/{PROJECT_ID}/queues/test_queue/messages
{% endhighlight %}
<h3>Request</h3>
<h4>Headers</h4>
<ul>
<li>Authorization: OAuth {TOKEN}</li>
<li>Content-Type: application/json</li>
</ul>
<h3>Response</h3>
{% highlight js%}
{"messages":[{"id":"5824513078343549739","body":"hello","timeout":60}]}
{% endhighlight %}
<div class="language curl"><h3>Curl Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight bash %}
curl -i -H "Content-Type: application/json" -H "Authorization: OAuth {TOKEN}" "https://mq-aws-us-east-1.iron.io/1/projects/{PROJECT_ID}/queues/test_queue/messages"
{% endhighlight %}</div>
<div class="language ruby"><h3>Ruby Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight ruby %}
@ironmq = IronMQ::Client.new()
@queue = @ironmq.queue("test_queue")
msg = @queue.get()
{% endhighlight %}</div>
<div class="language php"><h3>PHP Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight php %}
<?php
$ironmq = new IronMQ();
$ironmq->getMessage("test_queue");
{% endhighlight %}</div>
<div class="language python"><h3>Python Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight python %}
ironmq = IronMQ()
queue = ironmq.queue("test_queue")
msg = queue.get()
{% endhighlight %}</div>
<div class="language nodejs"><h3>Node.js Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight js %}
var iron_mq = require('iron_mq');
var imq = new iron_mq.Client();
var queue = imq.queue("test_queue");
queue.get({n: 1}, function(error, body) {
console.log(error, body);
});
{% endhighlight %}</div>
<div class="language go"><h3>Go Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight go %}
package main
import (
"fmt"
"github.com/iron-io/iron_go/mq"
)
func main() {
queue := mq.New("hello_queue")
msg, err := queue.Get()
fmt.Println(msg, err)
}
{% endhighlight %}</div>
<div class="language java"><h3>Java Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight java %}
Client client = new Client("{PROJECT_ID}", "{TOKEN}", Cloud.IronAWSUSEast);
Queue queue = client.queue("test_queue");
Message msg = queue.get();
{% endhighlight %}</div>
<div class="language clojure"><h3>Clojure Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight clojure %}
(def client (mq/create-client "{TOKEN}" "{PROJECT_ID}"))
(let [msg (mq/get-message client "test_queue")])
{% endhighlight %}</div>
<div class="language dotnet"><h3>.NET Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight c# %}
Client client = new Client("{PROJECT_ID}", "{TOKEN}");
Queue queue = client.queue("test_queue");
Message msg = queue.get();
{% endhighlight %}</div>
<h2 id="delete">4. Delete a Message from the Queue</h2>
<p>Once you've gotten a message off the queue and have processed it, you need to delete the message from the queue. This
ensures that the message is only processed once, but that it will not be lost if the processor fails during
processing. Deleting is as simple as posting and getting:</p>
{% highlight bash %}
DELETE https://mq-aws-us-east-1.iron.io:443/1/projects/{PROJECT_ID}/queues/test_queue/messages/{MESSAGE_ID}
{% endhighlight %}
<h3>Request</h3>
<h4>Headers</h4>
<ul>
<li>Authorization: OAuth {TOKEN}</li>
<li>Content-Type: application/json</li>
</ul>
<h3>Response</h3>
{% highlight js%}
{"msg":"Deleted"}
{% endhighlight %}
<div class="language curl"><h3>Curl Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight bash %}
curl -i -H "Content-Type: application/json" -H "Authorization: OAuth {TOKEN}" -X DELETE "https://mq-aws-us-east-1.iron.io/1/projects/{PROJECT_ID}/queues/test_queue/messages/{MESSAGE_ID}"
{% endhighlight %}</div>
<div class="language ruby"><h3>Ruby Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight ruby %}
@ironmq = IronMQ::Client.new()
@queue = @ironmq.queue("test_queue")
msg = @queue.get()
msg.delete
{% endhighlight %}</div>
<div class="language php"><h3>PHP Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight php %}
$ironmq = new IronMQ();
$msg = $ironmq->getMessage("test_queue");
$ironmq->deleteMessage($msg->id);
{% endhighlight %}</div>
<div class="language python"><h3>Python Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight python %}
ironmq = IronMQ()
queue = ironmq.queue("test_queue")
response = queue.get()
queue.delete(response["messages"][0]["id"])
{% endhighlight %}</div>
<div class="language nodejs"><h3>Node.js Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight js %}
var iron_mq = require('iron_mq');
var imq = new iron_mq.Client();
var queue = imq.queue("test_queue");
queue.post("Hello, IronMQ!", function(error, body) {
console.log(error, body);
});
var message_id;
queue.get({n: 1}, function(error, body) {
console.log(error, body);
if (error == null) {
message_id = body.id;
}
});
queue.del(message_id, function(error, body) {
console.log(error, body);
});
{% endhighlight %}</div>
<div class="language go"><h3>Go Example</h3>
<p>Make sure you've <a href="/mq/reference/configuration">set up your configuration file</a>.</p>
{% highlight go %}
package main
import (
"fmt"
"github.com/iron-io/iron_go/mq"
)
func main() {
queue := mq.New("hello_queue")
ids, err := queue.PushStrings("Hello", "world", "!")
fmt.Println(ids, err)
msg, err := queue.Get()
fmt.Println(msg, err)
if err == nil {
m.Delete()
}
msgs, err := queue.Get(2)
fmt.Println(msgs, err)
if err != nil {
for _, m := range append(msgs, msg) {
m.Delete()
}
}
}
{% endhighlight %}</div>
<div class="language java"><h3>Java Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight java %}
Client client = new Client("{PROJECT_ID}", "{TOKEN}", Cloud.IronAWSUSEast);
Queue queue = client.queue("test_queue");
Message msg = queue.get();
queue.deleteMessage(msg);
{% endhighlight %}</div>
<div class="language clojure"><h3>Clojure Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight clojure %}
(def client (mq/create-client "{TOKEN}" "{PROJECT_ID}"))
(let [msg (mq/get-message client "test_queue")]
(mq.delete-message client "test_queue" msg))
{% endhighlight %}</div>
<div class="language dotnet"><h3>.NET Example</h3>
<p>Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from <a href="http://hud.iron.io">HUD</a>.</p>
{% highlight c# %}
Client client = new Client("{PROJECT_ID}", "{TOKEN}");
Queue queue = client.queue("test_queue");
Message msg = queue.get();
queue.deleteMessage(msg);
{% endhighlight %}</div>
<h2>Next Steps</h2>
<p>You should be well-grounded in the post/get/delete paradigm now—now you need to build something cool! To get up
and running quickly, you may want to look into our <a href="/mq/reference/beanstalk">Beanstalk</a> support. Check
out our <a href="/mq/reference">reference material</a> to explore the boundaries of IronMQ's system. If you need
ideas for what you can accomplish with IronMQ, you may want to take a look at our <a href="/solutions">solutions</a>.
</p>