RabbitMQ on CloudAMQP

The www.cloudamqp.com website is not exactly a PaaS cloud platform, but we need to introduce it to understand the next recipe.

CloudAMQP is a RabbitMQ service. You can use this service to avoid management and hardware costs. There are five plans available at http://www.cloudamqp.com/plans.html that you can choose from. The Little Lemur plan is free and is perfect for trying this service.

Getting ready

You require the following software:

  • Java 1.6+
  • Apache Maven

How to do it...

To try this recipe, you need to register an account on CloudAMQP; the registration is free.

  1. Register an account at https://customer.cloudamqp.com/login.
  2. Create a RabbitMQ instance; choose the Data center and the Plan:
    How to do it...
  3. Go to the instance's details to see all your RabbitMQ connection parameters.
  4. Create a Java Maven program and add the following dependency:
    <dependency>
    <groupId>com.rabbitmq</groupId>
    <artifactId>amqp-client</artifactId>
    <version>2.8.1</version>
    </dependency>
  5. Create a Java Producer class that creates and uses the queue called myorders_11.
  6. Create a Java Consumer class that creates and uses the queue called myorders_11.

You can find the source code at Chapter11/Recipe01/.

How it works...

After creating your account (step 1), you can start using a RabbitMQ instance.

CloudAMQP service, by default, runs on Amazon AWS, and you have to choose the AWS data center (as we have seen in the previous chapter).

Go to the Instance Details page to see your connection parameters:

How it works...

In the source code example, we had created a producer and a consumer, bound to the queue myorders_11. The example sends a simple message to the queue, using the producer, and receives the message using the consumer.

Tip

To test this example, you can pass the CloudAMQP URL as a parameter in the following manner:

java -cp   rabbitmq-client.jar:Recipe01-0.0.1-SNAPSHOT.jar rmqexample.Consumer amqp://oxxx:[email protected]/oibyfhxg

There's more...

CloudAMQP is a very complete RabbitMQ service cloud. You can find all the clients and other cloud integrations at http://www.cloudamqp.com/docs.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset