restfeed-client-spring


License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

org.restfeeds
ArtifactId

ArtifactId

restfeed-client-spring
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

restfeed-client-spring
restfeed-client-spring
Project URL

Project URL

https://github.com/rest-feeds/rest-feeds
Source Code Management

Source Code Management

http://github.com/rest-feeds/restfeed-client-spring/tree/master

Download restfeed-client-spring

How to add to project

<!-- https://jarcasting.com/artifacts/org.restfeeds/restfeed-client-spring/ -->
<dependency>
    <groupId>org.restfeeds</groupId>
    <artifactId>restfeed-client-spring</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.restfeeds/restfeed-client-spring/
implementation 'org.restfeeds:restfeed-client-spring:0.0.1'
// https://jarcasting.com/artifacts/org.restfeeds/restfeed-client-spring/
implementation ("org.restfeeds:restfeed-client-spring:0.0.1")
'org.restfeeds:restfeed-client-spring:jar:0.0.1'
<dependency org="org.restfeeds" name="restfeed-client-spring" rev="0.0.1">
  <artifact name="restfeed-client-spring" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.restfeeds', module='restfeed-client-spring', version='0.0.1')
)
libraryDependencies += "org.restfeeds" % "restfeed-client-spring" % "0.0.1"
[org.restfeeds/restfeed-client-spring "0.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.restfeeds : restfeed-client jar 0.0.2
org.springframework.boot : spring-boot-starter-web jar 2.2.2.RELEASE

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.2.2.RELEASE

Project Modules

There are no modules declared in this project.

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

FeedReader

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.

FeedItemConsumer

Implement FeedItemConsumer interface to handle feed items.

NextLinkRepository

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.

FeedReaderRestClient

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

Versions

Version
0.0.1