I have a rss feed reader using spring integration. I want to learn source of a rss item.
Example item:
- title: "Top general: More ground troops needed in Libya"
- link: "cnn.com/blabla"
- pubDate: "2016-06-22 10:10:10"
I want to know in which rss link send me this item because I set it in init() function.
Result: http://rss.cnn.com/rss/edition.rss
Here is my feed channel config.
@Bean
public MessageChannel feedChannel() {
return new QueueChannel(500);
}
This is dynamic feedChannel creater. I read rss links from DB and create channel.
@PostConstruct
public void init() throws Exception{
List<RssLink> rssLinks = rssLinkService.findAll();
if(rssLinks != null && rssLinks.size() > 0 )
{
for(RssLink rss : rssLinks) {
QueueChannel channel = (QueueChannel) context.getBean("feedChannel");
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setApplicationContext(context);
adapter.setBeanName("adapter." + rss.getSource().getName());
FeedEntryMessageSource source = new FeedEntryMessageSource(new URL(rss.getLink()), rss.getSource().getName());
source.setApplicationContext(context);
source.setBeanName(rss.getSource().getDomain());
source.setBeanFactory(beanFactory);
source.afterPropertiesSet();
adapter.setSource(source);
adapter.setOutputChannel(channel);
PeriodicTrigger trigger = new PeriodicTrigger(300000);
adapter.setTrigger(trigger);
adapter.setMaxMessagesPerPoll(100);
adapter.setBeanFactory(beanFactory);
adapter.afterPropertiesSet();
adapter.start();
}
}
}
And this is the reader of the items in a channel.
@ServiceActivator(inputChannel = "feedChannel")
public void feedChannel(Message<SyndEntry> message) {
SyndEntry payload = message.getPayload();
MessageHeaders header = message.getHeaders();
Feed feed = new Feed();
feed.setLink(payload.getLink());
feed.setTitle(payload.getTitle());
//feed.setSource(I don't know which rss link send me this item);
}
So I want go get FeedEntryMessageSource of payload in ServiceActivator in order to know the item belongs which rss link. I set it 'rss.getSource().getName()' in this line :
FeedEntryMessageSource source = new FeedEntryMessageSource(new URL(rss.getLink()), rss.getSource().getName());