In an earlier blog post, I explained how to build a simple chat browser application that consumes messages via a direct topic subscription. In this follow-up to that tutorial, I’ll explain how to modify the sample code to get that application consuming messages from a queue.

Specifically, you will create a queue, add a subscription to the queue and create the queue consumer.

Prerequisites:

Level: Beginner

Create a Queue

  1. In your code editor, check out the developer-exercise-2 branch or in your command line, enter git checkout remotes/origin/developer-exercise-2 -f
  2. Open the scripts directory under src > main > resources > static.
  3. Open the pubsubplusbroker.js file, comment out the direct topic subscription that was added in Part 1 and save the file.
  4. Log in to Solace PubSub+ Cloud, open your service, and click Manage Service.
  5. Click the Queues tab on the left.
  6. Click the + Create button to create a queue.
  7. In the Create Queue dialog box, give the queue a name and click the Create button.

  8. Click Apply to use the default settings.

Add a Subscription to the Queue

  1. Click on the queue you just created and click the Subscriptions tab.
  2. Click the + Subscription button to open the Create Subscription dialog box.
  3. In the Create Subscription dialog box, add the topic subscription, press Enter, and click Create.
  4. In your code editor, type mvn spring-boot:run to run the application. Make sure you are in the \web-app-server directory.
  5. In your Web browser, type localhost:8081 to open the application if it is not already open.
  6. Send a few messages in the application.
  7. In the queue you created at Step 3, click Summary to see the queued messages.

Create the Queue Consumer

Now that the messages are in the queue, you need to create the consumer that consumes the messages in the queue. To create the consumer, follow the steps below:

  1. Open the application-properties.js file under static > resources and add ‘SOLACE_CHAT’ to sReceiveQueue.
  2. Open the pubsubplusbroker.js file, specify the queue descriptor, including the name and type of the queue, and set the acknowledge mode.
  3. Add the following code to connect the message consumer.
  4. In your code editor, type mvn spring-boot:run to run the application.
  5. Refresh the chat application in your browser.
    You should be able to see the received messages from the broker.
  6. In the queue that you created earlier, click Summary and then Refresh Data in the bottom right corner. You should see that the messages are no longer in the queue because of auto acknowledgement.

Congratulations! You have just created a queue, added a subscription to the queue, and created the queue consumer. In Part 3 of the series, you will learn how to send a REST POST request from a login page to a dummy authentication service.

Related

Solace logo
Solace

Solace helps large enterprises become modern and real-time by giving them everything they need to make their business operations and customer interactions event-driven. With PubSub+, the market’s first and only event management platform, the company provides a comprehensive way to create, document, discover and stream events from where they are produced to where they need to be consumed – securely, reliably, quickly, and guaranteed.

Behind Solace technology is the world’s leading group of data movement experts, with nearly 20 years of experience helping global enterprises solve some of the most demanding challenges in a variety of industries – from capital markets, retail, and gaming to space, aviation, and automotive.

Established enterprises such as SAP, Barclays and the Royal Bank of Canada, multinational automobile manufacturers such as Renault and Groupe PSA, and industry disruptors such as Jio use Solace’s advanced event broker technologies to modernize legacy applications, deploy modern microservices, and build an event mesh to support their hybrid cloud, multi-cloud and IoT architectures.