Skip to content

Latest commit

 

History

History
108 lines (63 loc) · 4.42 KB

README.md

File metadata and controls

108 lines (63 loc) · 4.42 KB

restfeed-client-spring

Maven Central

Client library to consume REST Feeds with Spring Boot.

Getting Started

Go to start.spring.io and create an new application. Select this dependency for RestTemplate and HttpMessageConverters:

  • Spring Web

Then add this library to your pom.xml:

    <dependency>
      <groupId>org.restfeeds</groupId>
      <artifactId>restfeed-client-spring</artifactId>
      <version>0.0.1</version>
    </dependency>

Add the base URL of the feed endpoint to your application.properties:

restfeed.client.url=https://example.rest-feeds.org/movies

And implement a FeedItemConsumer:

@Component
public class SimpleFeedItemConsumer implements FeedItemConsumer{

  @Override
  public void accept(FeedItem feedItem) {
    System.out.println(feedItem);
  }
}

Now run the application, you should see all feed items printed to your console.

Components

The FeedReader is the core class that polls the feed endpoint for new items in an endless loop.

Call the read() method to start reading the feed.

When shutting down the application, call the stop() method to end the endless loop.

The Spring RestFeedClientAutoConfiguration starts and stops the FeedReader on application startup and shutdown.

Implement FeedItemConsumer interface to handle feed items.

Provide an implementation how the next link is stored. The save() method is called directly after a feed item was consumed.

Typically, the NextLinkRepository is implemented as a SQL or NoSQL database.

An InMemoryNextLinkRepository is provided for testing.

The Spring RestFeedClientAutoConfiguration configures an InMemoryNextLinkRepository, when no other NextLinkRepository bean was created.

Implement this interface to perform the HTTP connection to the feed endpoint, authenticate, negotiate the content type, and do the unmarshalling.

The Spring RestFeedClientAutoConfiguration configures a RestTemplateFeedReaderRestClient, when no other FeedReaderRestClient bean was created. Consider configuring the RestTemplateBuilder for your needs.

Spring Properties

RestFeedClientAutoConfiguration uses these properties:

Key Default Value Description
restfeed.client.enabled true Enable REST feed client auto configuration and run FeedReader on application start.
restfeed.client.url The base URL of the feed endpoint to consume. Required.
restfeed.client.username The username for basic authentication. Optional.
restfeed.client.password The password for basic authentication. Optional.

FAQ

How to disable the embedded web server

Spring Web automatically starts up a Tomcat server on port 8080.

Set this property to disable:

spring.main.web-application-type=none