How to use Spring Integration Http Outbound Gateway for Polling a http end point with GET method

Spring Integration provides Http Outbound Components for polling a Http Endpoints with: Http Outbound Gateway & Http Outbound Adapter.
Http Outbound adapter: just send requests to an http endpoint.
– But Http Outbound gateway: send requests to an http endpoint then return responses.
In the tutorial, JavaSampleApproach will guide you how to poll a http end point with Get request by Http Outbound Gateway.

Related Posts:
1. How to use Spring Integration Http Inbound with Spring Boot
2. How to start Spring Integration with Spring Boot

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Boot: 1.5.1.RELEASE
– Spring Tool Suite – Version 3.8.1.RELEASE

II. Overview

The tutorial creates 2 projects: Http OutBound Gateway & simple RestfulApi Server with a GET request mapping.

1. Project Structure

Spring Integration Http Outboud Gateway - structure project

2. Step to do

– Create Spring Boot projects
– Create a simple data model
– Configure Http Outbound Gateway
– Create a Test case for HTTP Outbound Gateway
– Create a simple RestController for Server
– Run & Check Result

III. Practice
1. Create Spring Boot projects

– Open Spring Tool Suite, on main menu, choose File->New->Spring Starter Project, input project info. Press Next then Finish, a Spring Boot project will be created successfully.

For Http Outbound Gateway, add dependencies:
spring-boot-starter-integration
spring-boot-starter-web
spring-integration-http

For RestfulApi Server, add dependencies:
spring-boot-starter-web

2. Create a simple data model

3. Configure Http Outbound Gateway

Use HTTP Namespace Support, we define 2 channel: reply.channel & get.request.channel
expected-response-type is used to define type of message’s Payload.

4. Create a Test case for HTTP Outbound Gateway

@Autowired @Qualifier("reply.channel") PollableChannel receivedChannel for received channel.
@Autowired @Qualifier("get.request.channel") MessageChannel getRequestChannel for request channel.
Use MessageBuilder to build a message with empty payload.

5. Create a simple RestController for Server

Create WebController with a GET requestmapping.

6. Run & Check Result

Build the projects with Spring Boot App mode.
– Run RestfulApi Server
– Then run testcase for HTTP Outbound Gateway project.
Logs:

IV. Sourcecode

SpringRestfulApi
SpringIntegrationOutboundComponent


Related Posts



3 thoughts on “How to use Spring Integration Http Outbound Gateway for Polling a http end point with GET method”

    1. Yes,

      You can test by using a statement: Thread.sleep(timeforresponse) in RestFulService.

      With condition: timeforresponse > timeout

Got Something To Say:

Your email address will not be published. Required fields are marked *

*