Click the Create Service button to create a service.
Click the Connect tab.
Open the Solace Web Messaging section.
Copy the connection details to the application-properties.js file, add ‘solace/chat’ as the Publish and Subscribe topics, and save the file.
Note: Since we need the secure WebSocket connection, make sure that you use Secured Web Messaging Host as the sBROKERURL, not Web Messaging Host.
Type mvn spring-boot:run to run the application.
In your Web browser, type localhost:8081 to view the application.
You should see a message that says you are connected to your PubSub+ Cloud service.
Publish and Receive Messages
Though the application is connected to your PubSub+ Cloud service, it cannot yet publish and subscribe. In this section, you will modify the sample code to publish the messages to the Solace broker so that people who connect to it can receive them.
Under the script directory, open the pubsubplusbroker.js file.
Type the code lines as shown below to create the message, define the topic destination, and set the delivery mode and the message body.
Type the code line shown below to call the broker session and send the message.
Uncomment the oResultCallback and console.debug command lines so that you can see if the message is actually published.
Run the application.
Log in to your Solace PubSub+ Cloud and click the Try Me! tab.
In the Subscriber section, click the Connect button, add the topic “solace/chat”, and click the Subscribe button.
In your Web browser, type localhost:8081 or refresh the browser if you are already there.
In the application, type “Hello World” and click the arrow.
You should see that the subscriber has received the message.
In the establishing the subscription section of the pubsubplusbroker.js file, type the following code lines to create a topic, generate an event, pass in a correlation key for the event, and define the number of milliseconds it will wait before stopping to add the subscription to the connection.
Run the application.
In the application in the browser, type a message and send it out.
Open another browser at localhost:8081.
You should see that the message has been received.
You have just created a chat application with Solace and sent and received messages via it. In the next part, you will learn how to modify the sample code so that the application consumes messages from a queue instead of via a direct topic subscription.
Hong is the Senior Community Content Manager at Solace, where he is responsible for helping build the Solace community and creating developer-focused content. Prior to Solace, he spent over 10 years at Adobe managing the Adobe Developer Connection portals and planning, creating, and sourcing content for them. Before Adobe, he was a senior technical writer at Nortel and a technical writer at Cognos (now IBM).