Consuming Messages from a Queue

In this tutorial you'll learn how to consume guaranteed messages from the queue you created in Creating Your First Queue. To consume guaranteed messages, you connect to the event broker service and choose the queue to consume from.

The Try-Me! in the Cloud Console doesn't include the ability to connect to a queue, so you'll use the Try Me! feature in Broker Manager.

This tutorial shows you how to: 

  1. Obtain Credentials to Connect to an Event Broker Service

  2. Connect to Broker Manager and Consume Messages 

  3. Understand How Queues Store Messages 

Before You Begin

Complete the previous tutorial, Creating Your First Queue.

Obtain Credentials to Connect to an Event Broker Service

Applications that publish or consume messages through an event broker service need credentials to establish a connection to send and receive messages.

  1. Log in to the Cloud Console if you have not done so yet. The URL to access the Cloud Console differs based on your authentication scheme. For more information, see Logging into the Cloud Console.

  2. From the navigation bar, select Cluster Manager .
  3. Select the event broker service that you want to configure.
  4. On the Service Details page, select the Connect tab.
  5. In the Solace Web Messaging section, click Expand to view the connection information you need to connect to the event broker service. You can copy the credentials by clicking Copy .
  6. Using the obtained information, we'll connect to the event broker service to consume messages from the queue.

Connect to Broker Manager and Consume Messages

To try out consuming messages from a queue, we'll use the Try-Me! tool in Broker Manager to connect to the event broker and bind to the queue.

  1. Click Open Broker Manager in the top right of the page.
  2. In Broker Manager, on the left navigation bar, select Try Me!.
  3. In the Publisher panel, in the Establish Connection section, click the expand icon .
  4. Connect to the event broker service by entering the connection information you obtained in the previous task (Obtain Credentials to Connect to an Event Broker Service).
    1. Copy the value for Secured Web Messaging Host into the Broker URL field.
    2. Copy the value for Message VPN into the Message VPN field.
    3. Copy the value for Username into Client Username field.
    4. Copy the value for Password into Client Password field.
  5. In the Subscriber panel, make sure that Same as Publisher is selected for each field.
  6. Under the Publisher panel, click Connect. Once the connection is established, in the Subscriber panel, click Connect.
  7. In the Subscriber panel, click Bind to an endpoint to receive guaranteed messages to expand the section.
  8. To consume guaranteed messages from a Queue, type the name of the queue (Creating Your First Queue) and click Start Consume.
  9. Under Publisher, click Publish. The messages appear at the bottom of the Subscriber panel.
  10. To stop consuming messages from the queue, click Stop Consume.

Understand How Queues Store Messages

When a subscriber is not connected to the queue, the queue stores any messages it receives to send them to the subscriber when it reconnects. Guaranteed messages are not lost because the queue retains the message until the subscriber can receive them.

In the last step of the previous task, you stopped consuming messages, which simulates the subscriber stopping the connection to the queue. To see how queues store messages, perform these steps: 

  1. In Broker Manager, in the left navigation bar, select Queues, then select the Queues tab to see the status of your queue. You should see in the Consumers column that there are zero consumers.

  2. In the left navigation bar, select Try Me!
  3. If necessary, re-establish a connection for the publisher, and then publish three persistent messages.
  4. Return to the queue by selecting Queues in the left navigation bar. You should see that there are now three messages shown in the Messaged Queued (msgs) column.
  5. Restore the connection between the queue and the subscriber. On left navigation, select the Try Me! tab, and under Subscriber, expand Bind to an endpoint to receive guaranteed messages and click Start Consume.
  6. The stored messages in the queue are immediately sent and consumed by the subscriber.

  7. Return to the queue again by selecting Queues in the left navigation bar. You should see: 
    • The Messages Queued (msgs) column displays zero because the messages have been sent to the subscriber.
    • The Consumers column displays 1 because the subscriber is consuming messages.

Next Steps

You learned how to obtain the credentials to connect to event broker service, how to consume messages, and how messages are queued. After, you learned how the queue prevents the loss of messages, and the behaviors associated with it.