IronMQ Documentation

Connect your applications and processes with an elastic message queue. Decouple your processes and create a highly scalable system by passing messages.

The Post/Get/Delete Paradigm

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—the default is one minute—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.

1. Get a project ID and auth token

You can retrieve your project ID and token from the HUD by clicking on a project then clicking the little key icon.

2. Post a Message to a Queue

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:

POST https://mq-aws-us-east-1.iron.io:443/1/projects/{PROJECT_ID}/queues/test_queue/messages

Request

Headers

  • Authorization: OAuth {TOKEN}
  • Content-Type: application/json

Body

{"messages":[{"body":"hello world!"}]}

Response

{"ids":["5824513078343549739"],"msg":"Messages put on queue."}

Curl Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

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"

Ruby Example

Make sure you've set up your configuration file.

@ironmq = IronMQ::Client.new()
@queue = @ironmq.queue("test_queue")
@queue.post("hello world!")

PHP Example

Make sure you've set up your configuration file.

<?php
$ironmq = new IronMQ();
$ironmq->postMessage("test_queue", "Hello world!");

Python Example

Make sure you've set up your configuration file.

ironmq = IronMQ()
queue = ironmq.queue("test_queue")
queue.post("hello world!")

Node.js Example

Make sure you've set up your configuration file.

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);
});

Go Example

Make sure you've set up your configuration file.

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)
}

Java Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

Client client = new Client("{PROJECT_ID}", "{TOKEN}", Cloud.IronAWSUSEast);
Queue queue = client.queue("test_queue");
queue.push("Hello world!");

Clojure Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

(def client (mq/create-client "{TOKEN}" "{PROJECT_ID}"))
(mq/post-message client "test_queue" "Hello world!")

.NET Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

Client client = new Client("{PROJECT_ID}", "{TOKEN}");
Queue queue = client.queue("test_queue");
queue.push("Hello world!");

3. Get a Message off the Queue

Getting a message off the queue is simple:

GET https://mq-aws-us-east-1.iron.io:443/1/projects/{PROJECT_ID}/queues/test_queue/messages

Request

Headers

  • Authorization: OAuth {TOKEN}
  • Content-Type: application/json

Response

{"messages":[{"id":"5824513078343549739","body":"hello","timeout":60}]}

Curl Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

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"

Ruby Example

Make sure you've set up your configuration file.

@ironmq = IronMQ::Client.new()
@queue = @ironmq.queue("test_queue")
msg = @queue.get()

PHP Example

Make sure you've set up your configuration file.

<?php
$ironmq = new IronMQ();
$ironmq->getMessage("test_queue");

Python Example

Make sure you've set up your configuration file.

ironmq = IronMQ()
queue = ironmq.queue("test_queue")
msg = queue.get()

Node.js Example

Make sure you've set up your configuration file.

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);
});

Go Example

Make sure you've set up your configuration file.

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)
}

Java Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

Client client = new Client("{PROJECT_ID}", "{TOKEN}", Cloud.IronAWSUSEast);
Queue queue = client.queue("test_queue");
Message msg = queue.get();

Clojure Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

(def client (mq/create-client "{TOKEN}" "{PROJECT_ID}"))
(let [msg (mq/get-message client "test_queue")])

.NET Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

Client client = new Client("{PROJECT_ID}", "{TOKEN}");
Queue queue = client.queue("test_queue");
Message msg = queue.get();

4. Delete a Message from the Queue

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:

DELETE https://mq-aws-us-east-1.iron.io:443/1/projects/{PROJECT_ID}/queues/test_queue/messages/{MESSAGE_ID}

Request

Headers

  • Authorization: OAuth {TOKEN}
  • Content-Type: application/json

Response

{"msg":"Deleted"}

Curl Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

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}"

Ruby Example

Make sure you've set up your configuration file.

@ironmq = IronMQ::Client.new()
@queue = @ironmq.queue("test_queue")
msg = @queue.get()
msg.delete

PHP Example

Make sure you've set up your configuration file.

$ironmq = new IronMQ();
$msg = $ironmq->getMessage("test_queue");
$ironmq->deleteMessage($msg->id);

Python Example

Make sure you've set up your configuration file.

ironmq = IronMQ()
queue = ironmq.queue("test_queue")
response = queue.get()
queue.delete(response["messages"][0]["id"])

Node.js Example

Make sure you've set up your configuration file.

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);
});

Go Example

Make sure you've set up your configuration file.

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()
                }
        }
}

Java Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

Client client = new Client("{PROJECT_ID}", "{TOKEN}", Cloud.IronAWSUSEast);
Queue queue = client.queue("test_queue");
Message msg = queue.get();
queue.deleteMessage(msg);

Clojure Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

(def client (mq/create-client "{TOKEN}" "{PROJECT_ID}"))
(let [msg (mq/get-message client "test_queue")]
  (mq.delete-message client "test_queue" msg))

.NET Example

Replace {TOKEN} and {PROJECT_ID} with your credentials obtained from HUD.

Client client = new Client("{PROJECT_ID}", "{TOKEN}");
Queue queue = client.queue("test_queue");
Message msg = queue.get();
queue.deleteMessage(msg);

Next Steps

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 Beanstalk support. Check out our reference material 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 solutions.