Reputation: 1281
I am using Spring Integration and the Feed Inbound Channel Adapter to process news RSS feeds (which I think is fantastic :). I would also like to consume some additional news feeds which are available by an API into the same channel. The API is just a HTTP endpoint which returns a list of news articles in JSON. The fields are very similar to RSS i.e. there is a title, description, published date which could be mapped to the SyndEntry object.
Ideally I want to use the same functionality available in feed inbound channel adapter which deals with duplicate entries etc. Is it possible to customise Feed Inbound Channel Adaptor to process and map the JSON?
Any sample code or pointers would be really helpful.
Upvotes: 1
Views: 230
Reputation: 121177
Well, no. FeedEntryMessageSource
is fully based on the Rome Tools which deals only with the XML model.
I'm afraid you have to create your own component which will produce SyndEntry
instances for those JSON records. That can really be something like HttpRequestExecutingMessageHandler
, based on the RestTemplate
with the MappingJackson2HttpMessageConverter
which is present by default anyway.
You can try to configure HttpRequestExecutingMessageHandler
to the setExpectedResponseType(SyndFeedImpl.class)
and expect to have application/json
content-type in the response.
To achieve the "deals with duplicate entries" you can consider to use Idempotent Receiver pattern afterwards. Where the MessageSelector
should be based on the MetadaStore
and really preform logic similar to the one in the FeedEntryMessageSource
:
if (lastModifiedDate != null) {
this.lastTime = lastModifiedDate.getTime();
}
else {
this.lastTime += 1; //NOSONAR - single poller thread
}
this.metadataStore.put(this.metadataKey, this.lastTime + "");
...
if ((entryDate != null && entryDate.getTime() > this.lastTime)
where entry
is a payload
(FeedEntry
) of splitted
result from mentioned HttpRequestExecutingMessageHandler
.
Upvotes: 0