How to use  Solace PubSub+ Event Broker and Postman for RESTful Request/Reply
Tags: solace, postman, rest
Published: 2019-12-04 13:11:18

---
title: How to use  Solace PubSub+ Event Broker and Postman for RESTful Request/Reply
published: true
date: 2019-11-25 15:32:59 UTC
tags: solace,postman,REST
canonical_url: https://solace.com/blog/pubsub-postman-restful-request-reply/
---

 ![](https://solace.com/wp-content/uploads/2019/11/blog-featured-image_postman.jpg) 

[<u>Postman</u> ](https://www.getpostman.com/)is perhaps the most popular tool for quickly bootstrapping RESTful interactions. Since Solace PubSub+ Software Event Broker natively supports several protocols including HTTP, it makes sense to explore some of what PubSub+ Event Broker offers using Postman.

In this tutorial, we’ll use a rudimentary request and reply scenario to produce HTTP to the broker and consume the request as JMS on the backend. Notice that we don’t need to write any API transformation. PubSub+ Event Broker seamlessly translates between HTTP and JMS for us.

Specifically:

- Postman sends an HTTP request to PubSub+ Event Broker: Cloud
- A Springbootbackend application consumes the request using JMS.
- The backend application replies to Postman with a “Hello World” type string.

[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-1.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-1.png)

Figure 1: Simple Application for Postman

For brevity we avoid the use of TLS on either end. Also, the reply is sent on a dynamically generated reply topic, which I haven’t shown.

### Downloads

[Simple Springboot JMS Consumer](https://github.com/solacese/jms-hello-world)

## Set up an Instance of PubSub+ Event Broker: Cloud Free Plan

This is probably the easiest step in the entire tutorial! We setup a cloud instance of the broker to allow for communication between Postman and our backend consumer, as depicted in Figure 1.

If you already have an account, you can skip this step.

1. Go to [https://cloud.solace.com](https://cloud.solace.com/)
2. Click  **Get started**.
3. Fill up the form and click  **Sign Up** to create a free account.
4. Log in using the link you receive in the activation email.  
You’ll see the Services page and a single + tile.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-2.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-2.png)
5. Click the + tile to get to the Create Service  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-3.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-3.png)
6. Follow the steps outlined in the image below to create a free event broker service on an available AWS region.  
Note: Currently, the Free tier is offered only on AWS.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-4.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-4.png)  
Your service is up and running in a few seconds.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-5.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-5.png)

##  Set up Postman

Before we wire up any applications, let’s set up Postman to interact with the broker.

1. Fire up Postman and click  **New > Request**.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-6.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-6.png)
2. Save the request in an existing Collection or create one for this tutorial.  
Personally, I created a new one named  **Postman to Solace **** PubSub ****+**.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-7.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-7.png)
3. Change the METHODto POST for the blank request as PubSub+ Event Broker only handles HTTP POST requests by default.  
You can enable other HTTP verbs using [Microgateways](https://docs.solace.com/Configuring-and-Managing/Microgateways.htm).  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-8.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-8.png)
4. To communicate with PubSub+ Event Broker, head over to the instance of PubSub+ Event Broker: Could that you created earlier and click the **Connect** tab.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-9.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-9.png)
5. Select  **View by: > Protocol** in the top right hand and  scroll down to the  **REST**  Expand the section to view the  **Connection Details** for your service.  In our case, we are interested in Username, Password, and REST Host.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-10.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-10.png)
6. Back in Postman, enter the POST Host, Username, and Password details from the above step, paste them into the related fields, and click  **Save**.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-11.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-11.png)
7. Append `/T/service/requestto` the Host URL in Postman. This routes the request to the `T/service/request` topic on the broker.  
Note 1: PubSub+ creates the topic dynamically on the server side.  
Note 2: The request body is left empty intentionally.
8. Save the request and click  **Send**.  
You should get an empty response with an HTTP 200 Postman and our instance of PubSub+ Event Broker: Cloud are now talking!  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-12.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-12.png)

## Our Springboot Consumer

Our Springboot JMS consumer replies to any requests received on `T/service/request`. Spring handles the JMS configuration boilerplate, leaving us free to focus on the relevant application logic.

Using JMS with Spring is a deep topic outside the scope of this tutorial. Read this tutorial to learn the details.

### **Maven Configuration****  **

We import Solace’s Springboot starter to make life easier.

```
<dependency> <groupId>com.solace.spring.boot</groupId> <artifactId>solace-jms-spring-boot-starter</artifactId> <version>3.2.0</version> </dependency> 
```

### Java Code

This is the primary class that processes messages received on T/service/request and replies appropriately. As you can see, all the code does is reply with “Hello” prepended to the request body.

```
package com.solace.jmshelloworld; import org.springframework.jms.annotation.JmsListener; import org.springframework.stereotype.Component; @Component public class Receiver { @JmsListener(destination = "${app.jms.topic}", containerFactory = "myFactory") public String receiveMessage(String message) { System.out.printf("Received <%s>\n", message); return "Hello " + message + "!"; } }  
```

### Application Properties

We set the various properties used by both our service and the Solace PubSub+ Springboot starter.  
You can get the PubSub+ Event Broker properties from Solace Messaging > Solace JMS API under the  **Connect**  tab of your Solace PubSub+ Event Broker: Cloud instance. Be sure to select  **View By: Protocol**  in the top right hand.

```
#Solace propertiessolace.jms.host = tcp://mr1ilyoa01l8fn.messaging.solace.cloud:20352solace.jms.msgVpn = msgvpn-1nljqp0y1addsolace.jms.clientUsername= <u>solace-cloud-clientsolace.jms.clientPassword= <u>a29qovgiu8io1buvub6pm3gbv4#Topic for incoming requestapp.jms.topic = T/service/request
```

We start the service from the command line using mvn clean spring-boot:run

Assuming everything was configured correctly, the application should fire up and begin listening for request messages.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-13.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-13.png)

## Finalizing our Postman Setup

Since this is a request/reply exercise, we need to ask PubSub+ Event Broker to keep the HTTP session open for a reply. We do this by setting the `Solace-Reply-Wait-Time-In-ms` to a reasonable value in milliseconds. This also has the effect of creating a temporary reply-topic on the broker where our Springboot service will send responses.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-14.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-14.png)

Finally, put your name (or any string, really) in the Body.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-15.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-15.png)

## Testing the Integration

Time to test what we built! You should have the following configured and running:

1. A PubSub+ Event Broker: Cloud instance
2. Postman configured to send requests to the PubSub+ Event Broker and wait for responses
3. A SpringbootJMS application listening for messages on `T/service/request`

Save your Postman request and click  **Send**. If everything goes well, Postman will receive a greeting from the backend service.  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-16.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-16.png)  
[![](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-17.png)](https://solace.com/wp-content/uploads/2019/11/postman-blog_picture-17.png)

## Conclusion

That’s it! In a few easy steps, we were able to:

- Send an HTTP request to PubSub+ using Postman.
- Consume the request in Java using JMS and respond back to Postman using HTTP.

The PubSub+ Event Broker took care of all the necessary API and protocol transformations for us.

The post [How to use  Solace PubSub+ Event Broker and Postman for RESTful Request/Reply](https://solace.com/blog/pubsub-postman-restful-request-reply/) appeared first on [Solace](https://solace.com).