If you’re familiar with developing and deploying in a cloud environment, a common practice is to bring up a cloud resource using a cloud provider’s APIs, use that resource, then remove it when you are done. This is all accomplished programmatically, avoiding the need to start or stop the resources manually using the cloud provider’s user interface.
For example, a common flow for testing an app would be to:
1. Bring up a cloud server (e.g., an AWS EC2) programmatically
2. Install and test your app on that cloud server
3. Tear down the cloud server when your testing is complete
Wouldn’t it be nice if you could do this with your messaging service too?
Now you can! Solace PubSub+ Cloud just introduced REST APIs and REST API token support (in beta). This means developers can use Solace Cloud’s REST APIs to create PubSub+ Cloud messaging services and extract information about them programmatically.
In this blog post, I’ll show you how you can:
1. Grab an API token from Solace Cloud using your account
2. Use that API token to create a messaging service via Solace Cloud’s REST APIs
3. Use the REST APIs to pull out the MQTT connection details for the new messaging service (which could be used in your apps to send/receive MQTT messages)
Let’s get started – it should only take about 15 minutes to set everything up and start using the API.
I’m assuming you know what REST is and kind of know how to send REST requests using your favorite tool.
But if you don’t, check out this REST intro and then come back.
- Sign up for Solace Cloud if you haven’t already (don’t worry it’s free)
- You need a way to send REST messages from your dev environment. Postman (6.1.3 or greater) is a good choice if you want a visual REST API Dev Tool
- Run this Postman collection by going to the link below, then hit the “Run in Postman” button
- This link will import the Postman collection for you and import the Postman Environment needed to run the collection
- If you don’t have Postman installed when you hit “Run in Postman”, it will prompt you to install it (which doesn’t take long). Once Postman is installed, you will need to shut it down and click on the “Run in Postman” link again to import the Postman collection.
- If you prefer using CURL, the Postman link above provides the sample CURL commands.
Create an API Token
You need an API token to authenticate and authorize REST requests. When creating an API token, you will configure what permissions it has (i.e., a subset of the permissions you have when you log in to Solace Cloud)
1. Login in to Solace Cloud
2. Navigate to Token Management (Click on your name in the right side of the menu bar)
a. Get My Services
b. Create Services
c. Delete My Services
5. Click the “Generate Token” button
6. Copy the token to your clip board by clicking the “Copy” button (Note: You will not see this again for security reasons. You can always regenerate the token or create a new one)
7. Set up Postman Collection Authorization – In order for Postman to send REST to Solace Cloud, you need to set the token you just created
a. Set the Postman Environment to Solace PubSub+ Cloud (its a drop down in the upper left part of the postman window)
Great! Now we have a token, and Postman is set up to use it!
Let’s use it to do some stuff.
Create a Messaging Service using the REST API
Now we have a token, we can use it call the service REST endpoint to create a messaging service.
1. In the Postman Collection “Solace Blogs – Create Messaging Service”, select the request “POST Create Messaging Service”
You should see a JSON response confirming that a messaging service was created.
Now go back to Solace Cloud and you should see your service.
Awesome! If you are here, you have just created a messaging service.
Get the Connection Details the Messaging services
Now let’s retrieve the messaging service connection details. The Solace PubSub+ Cloud Messaging Service supports almost all of the messaging protocols under the sun! Let’s pick MQTT for the sake of this exercise, but this API provides you with all supported protocols.
1. In the Postman Collection “Solace PubSub+ Cloud – Create Messaging Services”, select the request Get Messaging Service
You should be able to see the MQTT connection details in the JSON response.
Now you can use the connection details to start sending MQTT messages to your new messaging service from your app.
You now have everything you need to create Solace PubSub+ Cloud messaging services in a cloud stylie way.
These REST APIs are still BETA, so any feedback is welcome. Please use the feedback section of the Support tab in the Solace Cloud console to let us know what you think.