Message Queue: Getting Started

Obtaining your API credentials

After placing an order for the Message Queue service, the API endpoints for the datacenter you selected during the order process can be located in the SoftLayer Customer Portal alongside your user name, account ID, and API, using the following steps:

  • Open https://control.softlayer.com/ in your web browser and log in with your user name and password
  • From the Services menu, click on Message Queue
  • In the Message Queue account list, click on the account in the list you wish to use. In most cases, you will have one account to select from
  • Your Account ID can be found near the top of the account detail page:intro-part1-account-detail.jpg
  • Directly underneath your account ID, click the View Credentials link
  • Your user name and API key will be displayed in the credentials dialog:
    intro-part1-account-credentials.jpg

    Note: if you have more than one user account in your SoftLayer customer account, and you wish to use a specific account for interacting with the Message Queue API, simply repeat these steps by logging in as that user account.

In the above examples, our account information for this example is as follows:

  • Account ID: 5yc2z
  • User name: happycustomer
  • API key: 98b0c8158e633d5c5ed63ad24584cadfa0e6e047c4c9e7e3adb3368aaa029640

These three items will be required when we authenticate to the service.

Authenticating

Now that we have our credentials, we can begin writing our application. For this example series, we'll use PHP.

<?php
require('softlayer-queue-php-client/src/SoftLayer/Messaging.php');
 
// Replace these values with your own.
define('QUEUE_ACCOUNT', '5yc2z');
define('QUEUE_USERNAME', 'happycustomer');
define('QUEUE_API_KEY', '98b0c8158e633d5c5ed63ad24584cadfa0e6e047c4c9e7e3adb3368aaa029640');
 
$messaging = new SoftLayer_Messaging();
 
if ($messaging->authenticate(QUEUE_ACCOUNT, QUEUE_USERNAME, QUEUE_API_KEY)) {
    echo "Welcome to the SoftLayer Message Queue!" . PHP_EOL;
}

In this example, we simply attempt authentication. If successful, we should see the welcome message.

Listing Queues

Now that we've successfully authenticated, we should be able to perform a simple operation against our account, such as getting a list of all the queues created on our account thus far:

$queues = $messaging->queues();
echo "There are " . count($queues) . " queues on your account." . PHP_EOL;

Since this is the first time we've used the queue service, this will simply tell us we have zero queues so far--but is a simple way to test the API.

Check out Message Queue: Exploring Topics we'll explore queues in much greater depth, and Message Queue: Exploring Queues will explain more advanced use cases through the use of topics.

Was this helpful?