Interface FeedConsumer
-
public interface FeedConsumer
An interface for consuming a Feed provided by theFeedProducer
.Feed pages are paginated collections of feed entities. Each page contains a list of feed entities and an optional link to the next page. Feed pages are consumed by starting from the provided feed URL (which will generally point to the newest page in the feed) and walking backwards until the desired starting point determined by the
StartFrom
parameters is reached. Then the feed pages are streamed from oldest to newest until the head of the feed is reached.This interface exposes two different ways to consume feed data:
streamEntities(Url, StartFrom)
hides the page breaks and provides a stream of fully downloaded entities in chronological order as they appear in the feed. This is usually what you want since order matters when consuming a feed. This method also provides entity-level filtering when using eitherStartFrom.Timestamp
orStartFrom.ContentId
.streamPages(Url, StartFrom)
instead returns a stream ofStreamingPage
objects. This provides more control over how the pages are consumed: for example, it allows streaming individual entity bodies (in contrast to always downloading the entire body of an entity before it is emitted) and downloading and processing multiple feed pages in parallel. Note that this is usually not what you want because the order of pages and entities matters for a feed.Note that this method never returns partial pages. This means that where
streamEntities(Url, StartFrom)
might discard entities from the first page because their timestamps are older than requested, this method will return the full first page including those entities.
A feed consumer is created using a builder: call the
builder()
method to create a new builder with default settings, call the methods onFeedConsumer.Builder
to customize the consumer, then callFeedConsumer.Builder.build()
to create a newFeedConsumer
instance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
FeedConsumer.Builder
A builder forFeedConsumer
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static FeedConsumer.Builder
builder()
Create a newFeedConsumer.Builder
with default settings.java.util.concurrent.Flow.Publisher<@NonNull Entity<@NonNull FeedEntityHeader>>
streamEntities(@NonNull Url url, @NonNull StartFrom startFrom)
Stream the entities of the feed starting from the givenUrl
.java.util.concurrent.Flow.Publisher<@NonNull StreamingPage<@NonNull FeedPageHeader,@NonNull FeedEntityHeader>>
streamPages(@NonNull Url url, @NonNull StartFrom startFrom)
Stream the feed pages starting from the givenUrl
.
-
-
-
Method Detail
-
streamPages
@NonNull java.util.concurrent.Flow.Publisher<@NonNull StreamingPage<@NonNull FeedPageHeader,@NonNull FeedEntityHeader>> streamPages(@NonNull @NonNull Url url, @NonNull @NonNull StartFrom startFrom)
Stream the feed pages starting from the givenUrl
. Streaming aStreamingPage
will result into receiving already consumed entities with an older last modified date of the current FeedPage again. TheContentId
fromStartFrom.ContentId
will not respect in streamPages, usestreamEntities(Url, StartFrom)
instead.- Parameters:
url
- theUrl
to start streaming fromstartFrom
- theStartFrom
parameter- Returns:
- a
Flow.Publisher
ofStreamingPage
ofFeedPageHeader
andFeedEntityHeader
- Throws:
FeedException.FeedNotOldEnough
- if the last modified date of the last page is not older andStartFrom
is notStartFrom.Beginning
HttpException
- in case of HTTP errors (invalid URL, HTTP error status codes, network errors/timeouts, ...)PageFormatException
- if the HTTP response is ok, but the page response is malformed in some way (usually missing or malformed HTTP Content-Type header since multipart parsing errors will only start happening when we get toStreamingPage
)
-
streamEntities
@NonNull java.util.concurrent.Flow.Publisher<@NonNull Entity<@NonNull FeedEntityHeader>> streamEntities(@NonNull @NonNull Url url, @NonNull @NonNull StartFrom startFrom)
Stream the entities of the feed starting from the givenUrl
. Streaming entities will result into skipping already consumed entities with an older last modified date of the current FeedPage. Streaming entities will respect theContentId
fromStartFrom.ContentId
.- Parameters:
url
- theUrl
to start streaming fromstartFrom
- theStartFrom
parameter- Returns:
- a
Flow.Publisher
ofEntity
ofFeedEntityHeader
- Throws:
FeedException.FeedNotOldEnough
- if the last modified date of the last page is not older andStartFrom
is notStartFrom.Beginning
FeedException.ContentIdNotFound
- when usingStartFrom.ContentId
and the specified content ID was not found with the specified timestampHttpException
- in case of HTTP errors (invalid URL, HTTP error status codes, network errors/timeouts, ...)PageFormatException
- if the HTTP response is ok, but the page response is malformed in some way (usually missing or malformed HTTP Content-Type header since multipart parsing errors will only start happening when we get toStreamingPage
)
-
builder
@NonNull static FeedConsumer.Builder builder()
Create a newFeedConsumer.Builder
with default settings. Use theFeedConsumer.Builder.build()
method on the returned builder to create aFeedConsumer
with the specified settings.- Returns:
- a new builder
-
-