This add-on is operated by Iron.io
Serverless, High Performance, Lightning Fast Message Queue
IronMQ Message Queue as a Service
Last updated July 12, 2023
Table of Contents
IronMQ is a massively scalable, hosted message queue. It makes managing data and event flow within your application simple, with support for multiple clients and a managed environment that frees you from needing to manage servers, allowing you to focus on your application instead.
IronMQ Setup on Heroku
1) Install the IronMQ addon for Heroku
$ heroku addons:create iron_mq:developer
-----> Adding iron_mq to cold-winter-5462... done, v10 (free)
2) Install the IronMQ client library (Ruby Example)
$ gem install iron_mq
3) Configuration: retrieve Token and Project ID
$ heroku config | grep IRON
IRON_WORKER_PROJECT_ID => 123456789
IRON_WORKER_TOKEN => aslkdjflaksuilaks
4) Use the installed client lib to interact with your queues (create a queue, post/get/delete a message, etc.). Client lib is a wrapper over the rest api. Below you can find examples for different programming languages.
Language support
IronMQ has clients for a lot of languages, and you can always use the REST API (or write your own!). This means your existing Heroku stack should work without any changes.
Ruby
We’re going to need to install the Ruby gem, for development purposes:
$ gem install iron_mq
Fetching: iron_mq-3.0.2.gem (100%)
Successfully installed iron_mq-3.0.2
If you’re building for a Rails application or anything that uses Bundler, add the following to your Gemfile:
gem 'iron_mq'
Now you have a simple helper that allows you to interact with your queues:
# Create an IronMQ::Client object
@ironmq = IronMQ::Client.new()
# Get a queue (if it doesn't exist, it will be created when you first post a message)
@queue = @ironmq.queue("my_queue")
# Post a message
@queue.post("hello world!")
# Get a message
msg = @queue.get()
p msg
# Delete a message (you must delete a message when you're done with it or it will go back on the queue after a timeout)
msg.delete # or @queue.delete(msg.id)
Java
You can use Maven to install the official IronMQ Java library or download the jar file. More details are here.
Once you have the jar file added as a dependency, you have a simple wrapper that allows you to interact with your queues:
import io.iron.ironmq.*;
...
// Get your Iron.io credentials from the environment
Map<String, String> env = System.getenv();
// Create a Client object
Client client = new Client(env.get("IRON_MQ_PROJECT_ID"), env.get("IRON_MQ_TOKEN"), Cloud.IronAWSUSEast);
// Get a queue (if it doesn't exist, it will be created when you first post a message)
Queue queue = client.queue("my_queue");
// Post a message
queue.Push("hello world!");
// Get a message
Message msg = queue.get();
System.out.println(msg.getBody());
// Delete a message (you must delete a message when you're done with it or it will go back on the queue after a timeout)
queue.deleteMessage(msg);
Python
We’re going to have to install the Python client library for IronMQ. You can do this using pip install iron_mq
or easy_install iron_mq
.
Once the package is installed, you have a simple wrapper that allows you to interact with your queues:
# Create an IronMQ client object
mq = IronMQ()
# Get a queue (if it doesn't exist, it will be created when you first post a message)
queue = mq.queue("my_queue")
# Post a message
queue.post("hello world!")
# Get a message
msg = queue.get()
print msg
# Delete a message (you must delete a message when you're done with it or it will go back on the queue after a timeout)
queue.delete(msg["messages"][0]["id"])
Clojure
We’re going to need to add the IronMQ Clojure client to your project.clj:
[iron_mq_clojure "1.0.3"]
Use these to create a client that allows you to interact with your queues:
(require '[iron-mq-clojure.client :as mq])
(def client (mq/create-client (System/getenv "IRON_MQ_TOKEN") (System/getenv "IRON_MQ_PROJECT_ID")))
; Post a message
(mq/post-message client "my_queue" "Hello world!")
; Get a message
(let [msg (mq/get-message client "my_queue")]
(println (get msg "body"))
; Delete a message (you must delete a message when you're done with it or it will go back on the queue after a timeout)
(mq/delete-message client "my_queue" msg))
Node.js
We’re going to need to the IronMQ Node.js client to interact with our queues. You can get it using npm install iron_mq
or by downloading the source from Github (though you’ll need iron_core_node, too).
Once that’s done, you can require it to get a simple wrapper for the API:
var iron_mq = require("iron_mq");
var client = new iron_mq.Client({"queue_name": "my_queue"});
// Post a message
client.post("test message", function(error, body) {
console.log(body);
console.log(error);
});
// Get a message
client.get({}, function(error, body) {
console.log(error);
console.log(body);
if(error == null) {
// Delete a message
client.del(body["id"], function(error, body) {
console.log(error);
console.log(body);
});
}
});
Next steps
To get into more advanced uses of IronMQ, you may want to check out the API docs or check out an example Sinatra application that ties in IronWorker at https://github.com/iron-io/heroku_sinatra_example.
Support
Issues should get logged with Heroku Support. You can also find more resources at the Iron.io Dev Center.