October 28, 2015 | Written by: Lovisa Johansson
Share this post:
RabbitMQ is an open source message broker. It receives and delivers messages from and to your applications. A message broker is (unlike databases and key-value store) purpose built to highly effectively and safely deliver information between your applications. Messages can be sent cross languages, platforms and OS—this way of handling messages decouples your processes and creates a highly scalable system.
CloudAMQP is today operating and providing support to the largest fleet of RabbitMQ clusters in the world! The CloudAMQP service is available in the Bluemix catalog.
If you are new to RabbitMQ, we recommend you read the guide RabbitMQ for beginners before continuing.
Step 1. Create a space and an app within that space
Let’s get started with a managed RabbitMQ server hosted in Bluemix!
- Register an account and log in to Bluemix
- Create the space for your organization
- Create an app within the space:
Step 2. Create a CloudAMQP service instance
- Open the dashboard for your app and select “ADD A SERVICE OR API”
- Find CloudAMQP in the list of services (direct link) and select a plan. We offer seven different plans, both dedicated clusters, individual servers and vhosts on shared clusters. Dedicated plans provides guaranteed isolation between instances, where as shared plans provides great performance but limits number of connections and number of messages sent per month.
Step 3. Cloud Foundry command line interface
Use the Cloud Foundry command line interface to deploy and modify applications and service instances. See Getting Started with the cf CLI as required.
Step 4. Start coding
All AMQP client libraries work with CloudAMQP and there are AMQP client libraries for almost every platform. Sample code, links to recommended libraries and further information about the client libraries can be found in the CloudAMQP documentation.
- Add the client library to your dependencies file. The library will be downloaded automatically when you deploy your app. CloudAMQP recommended client libraries for different languages can be found here: Ruby, Python, Celery, node.js, PHP, Java, Clojure, Go, Android, .NET, Perl and C. For example, in Ruby, open the Gemfile and add gem ‘bunny’.
- Copy code from the the same language-specific link as above. For example, in Ruby:
<code>require "bunny" # don't forget to put gem "bunny" in your Gemfile
services = JSON.parse(ENV['VCAP_SERVICES'])
cloudamqp_conf = services["cloudamqp"].first
uri = cloudamqp_conf["credentials"]["uri"]
b = Bunny.new uri
b.start # start a communication session with the amqp server
ch = b.create_channel # create a channel
q = ch.queue("test") # declare a queue
# declare a default direct exchange, which is bound to all queues
e = ch.exchange("")
# publish a message to the exchange, the message will be routed to the queue "test"
e.publish("Hello, everybody!", key: value)
# subscribe from the queue
q.subscribe(block: true) do |delivery_info, properties, payload|
puts "This is your message: " + payload + "\n\n"
b.stop # close the connection
- Set up connection Environment Variable: The connection and credential information for CloudAMQP is available in the Bluemix
VCAP_SERVICES environment variable. It’s a nested JSON objected with all service credentials.
Step 5. Push the App to Bluemix
When the code has been added it is time to deploy the App. Deploying the application into bluemix is easy, just run this command from the app directory:
<code>$ cf push --name your_app </code>
your_app to the application name you chose earlier. Once the application has finished deploying, your app will be connecting, publishing and subscribing via CloudAMQP:
You can write to log and tail your log via
<code>$ cf logs your_app </code>
Once the service is added to space, a link to CloudAMQP Control Panel will appear within Bluemix. Open the Bluemix Dashboard and press Services and “OPEN CLOUDAMQP DASHBOARD” to get to your CloudAMQP instance.
The instance details, such as connection URL, metrics, logs etc can be seen at the details page. You can also go to the RabbitMQ management interface from the detail page.
From the management interface it is possible to view, handle and delete connections, queues, message etc.
A full product overview, showing different tools and features to simplify the usage of your RabbitMQ instances can be found in the product overview page.
Various monitoring tools are also available. These tools will address performance issues promptly and automatically, before they impact your business. For more details, see CloudAMQP: Monitoring Tools.