w3stling/rssreader

How to subscribe to RSS feed?

Closed this issue · 1 comments

I'm not quite understanding how this repository does what it promises. You state the following in the description:

Subscribing to a website RSS removes the need for the user to manually check the website for new content.

This is closely followed by:

This Java RSS parser library makes it easier to automate data extraction from RSS or Atom feeds via Java stream API.

To me, and I would like to believe most people, this suggests that this repository has the capabilities of "subscribing" to an "RSS" feed (henceforth "automating data extraction"). But unless I'm being silly and just completely missing something, this is not possible with this library?

If this could be added, that would be great because otherwise I don't believe it fulfils the description of this repository. Don't get me wrong, this library is very handy nonetheless, but what I would consider the more important part of the library is being able to subscribe to a feed. Otherwise it verges on the edge of not being so useful.

I also cannot help but point out, the fact that it uses the Java Stream API is a weird point to advertise this repository from? Is that really a such a big thing? It's not any different than just giving us a List and us calling List#stream. Generally it feels like a bad idea to just pass streams around since obviously they do need to be closed.

It is not possible to subscribe to a feed. However it can be implemented by wrapping RssReader in a TimeTask or using ScheduledExecutorService.

Generally it feels like a bad idea to just pass streams around since obviously they do need to be closed.

The underlying resources is automatically closed when reading to the end of the stream. If using methods like Stream::findFirst, Stream::findAny, Stream::limit or any other method that only reads the beginning of the stream then use the try-with-resources statement to close the stream.

        var rssReader = new RssReader();

        try (var feed = rssReader.read(URL)) {
            feed.limit(5)
                .map(this::toNews)
                .forEach(this::publishFiveLatestNews);
        }

It's not any different than just giving us a List and us calling List#stream

Returning a List<Item> would require the entire feed to be parsed and all items to be kept in memory.
RssReader uses a streaming XML parser that parse Items one by one and keeping one Item in memory at a time per feed.