1. What is RSS?
RSS stands for “Really Simple Syndication” and is a tool that allows you to subscribe to all kinds of websites of interest in one place.
A website supports RSS, which means that every time it publishes a new article, it adds a record to a file at a specific URL with a specific syntax (specifically XML markup language or JSON) that lists the title, author, publication time, and content (which can be a full text or abstract) of the article. In this way, the user can find out if and when the content of these files is published by these websites by collecting the URLs of all such documents provided by the websites he is interested in, and checking for updates to the contents of these documents from time to time. The core function of an RSS reader is to store the RSS address to which the user subscribes, automatically check for updates at a fixed frequency, and present its content to the user in an easy-to-read format.
Why RSS
The opposite of RSS is algorithmic recommendations, such as WeChat official account, Zhihu, Weibo, Toutiao and other platforms. Not to mention the problem that there are many advertisements on the platform pushed by the algorithm and the migration is troublesome. The feature of algorithmic recommendation is that you don’t need to choose deliberately, and the algorithm will push you content according to your preferences. In this way, you have little choice, and you gradually lose the ability to judge in the constant “feeding”. What’s even more terrifying is thatIt defines your portrait for you, and then subtly transforms you into who it thinks you are。 It is no accident that the “big data kills ripeness” incident occurred in the East Window, and the use of algorithms to peep into user privacy is a wild card for today’s Internet companies.
Be the master of the message, not the slave.RSS is a public protocol that allows you to change platforms and clients freely. The important point is thatThe power to access information is completely autonomous。 Compared with algorithmic recommendations, RSS has a sense of control and security, and privacy is completely in your own hands.
What is ATOM?
AtomIt is a pair of standards that are related to each other. Atom Syndication Format is an XML-based document format for website sources; The Atom Publishing Protocol (AtomPub or APP) is an HTTP-based protocol used to add and modify network resources.
It draws on the experience of using various versions of RSS and is widely used by many aggregators for publishing and use. The Atom feed format is designed as an alternative to RSS; The Atom publishing protocol is used to replace existing publishing methods (e.g., Blogger API and LiveJournal XML-RPC Client/Server Protocol). And it’s worth mentioning that Atom is being used by a variety of services offered by Google. The Google Data API (GData) is also based on Atom.
Atom is the IETF’s “Recommended Standard”, with the Atom contribution format listed as RFC 4287 and the Atom publishing protocol listed as RFC 5023.
2. Code engineering
Objective: Implement RSS and ATOM feeds
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot-demo</artifactId>
<groupId>com.et</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rss</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--ROAM依赖 RSS 订阅-->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>1.15.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.rometools/rome-utils -->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-utils</artifactId>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.6</version>
</dependency>
</dependencies>
</project>
controller
RSS and ATOM subscriptions are implemented using the ROME library
package com.et.rss.controller;
import com.rometools.rome.feed.atom.*;
import com.rometools.rome.feed.rss.Channel;
import com.rometools.rome.feed.rss.Description;
import com.rometools.rome.feed.rss.Image;
import com.rometools.rome.feed.rss.Item;
import com.rometools.rome.feed.synd.SyndPerson;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.Date;
@RestController
@RequestMapping("/feed")
public class FeedController {
@GetMapping(path = "/rss")
public Channel rss() {
Channel channel = new Channel();
channel.setFeedType("rss_2.0");
channel.setTitle("HBLOG Feed");
channel.setDescription("Recent posts");
channel.setLink("http://www.liuhaihua.cn");
channel.setUri("http://www.liuhaihua.cn");
channel.setGenerator("Harries");
Image image = new Image();
image.setUrl("http://www.liuhaihua.cn/img/hblog.png");
image.setTitle("HBLOG Feed");
image.setHeight(32);
image.setWidth(32);
channel.setImage(image);
Date postDate = new Date();
channel.setPubDate(postDate);
Item item = new Item();
item.setAuthor("Harries");
item.setLink("http://www.liuhaihua.cn/archives/710608.html");
item.setTitle("Spring Boot integrated banner quick start demo");
item.setUri("http://www.liuhaihua.cn/archives/710608.html");
item.setComments("http://www.liuhaihua.cn/archives/710608.html#commnet");
com.rometools.rome.feed.rss.Category category = new com.rometools.rome.feed.rss.Category();
category.setValue("CORS");
item.setCategories(Collections.singletonList(category));
Description descr = new Description();
descr.setValue("pring Boot Banner is a feature for displaying custom ASCII art and information at application startup. This ASCII art usually includes the project name, version number, author information");
item.setDescription(descr);
item.setPubDate(postDate);
channel.setItems(Collections.singletonList(item));
//Like more Entries here about different new topics
return channel;
}
@GetMapping(path = "/atom")
public Feed atom() {
Feed feed = new Feed();
feed.setFeedType("atom_1.0");
feed.setTitle("HBLOG");
feed.setId("http://www.liuhaihua.cn");
Content subtitle = new Content();
subtitle.setType("text/plain");
subtitle.setValue("recents post");
feed.setSubtitle(subtitle);
Date postDate = new Date();
feed.setUpdated(postDate);
Entry entry = new Entry();
Link link = new Link();
link.setHref("http://www.liuhaihua.cn/archives/710608.html");
entry.setAlternateLinks(Collections.singletonList(link));
SyndPerson author = new Person();
author.setName("HBLOG");
entry.setAuthors(Collections.singletonList(author));
entry.setCreated(postDate);
entry.setPublished(postDate);
entry.setUpdated(postDate);
entry.setId("710608");
entry.setTitle("Spring Boot integrated banner quick start demo");
Category category = new Category();
category.setTerm("CORS");
entry.setCategories(Collections.singletonList(category));
Content summary = new Content();
summary.setType("text/plain");
summary.setValue("Spring Boot Banner is a feature for displaying custom ASCII art and information at application startup. This ASCII art usually includes the project name, version number, author information");
entry.setSummary(summary);
feed.setEntries(Collections.singletonList(entry));
//add different topic
return feed;
}
}
DemoApplication.java
package com.et.rss;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
application.yaml
server:
port: 8088
The above are just some of the key codes, all of which can be found in the repositories below
Code repositories
3. Testing
Start the Spring Boot application
rss
http://127.0.0.1:8088/feed/rss
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>HBLOG Feed</title>
<link>http://www.liuhaihua.cn</link>
<description>Recent posts</description>
<pubDate>Fri, 24 May 2024 14:26:21 GMT</pubDate>
<generator>Harries</generator>
<image>
<title>HBLOG Feed</title>
<url>http://www.liuhaihua.cn/img/hblog.png</url>
<width>32</width>
<height>32</height>
</image>
<item>
<title>Spring Boot integrated banner quick start demo</title>
<link>http://www.liuhaihua.cn/archives/710608.html</link>
<description>pring Boot Banner is a feature for displaying custom ASCII art and information at application startup. This ASCII art usually includes the project name, version number, author information</description>
<category>CORS</category>
<pubDate>Fri, 24 May 2024 14:26:21 GMT</pubDate>
<author>Harries</author>
<comments>http://www.liuhaihua.cn/archives/710608.html#commnet</comments>
</item>
</channel>
</rss>
atom
http://127.0.0.1:8088/feed/atom
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>HBLOG</title>
<subtitle type="text">recents post</subtitle>
<id>http://www.liuhaihua.cn</id>
<updated>2024-05-24T14:25:38Z</updated>
<entry>
<title>Spring Boot integrated banner quick start demo</title>
<link rel="alternate" href="http://www.liuhaihua.cn/archives/710608.html" />
<category term="CORS" />
<author>
<name>HBLOG</name>
</author>
<id>710608</id>
<updated>2024-05-24T14:25:38Z</updated>
<published>2024-05-24T14:25:38Z</published>
<summary type="text">Spring Boot Banner is a feature for displaying custom ASCII art and information at application startup. This ASCII art usually includes the project name, version number, author information</summary>
</entry>
</feed>