Skip to content

Martini Invoking Services via a RSS Trigger

The RSS trigger in Martini enables applications to automatically invoke a configured Groovy service in response to updates within an RSS feed. This feature is essential for integrating dynamic content updates, such as news, blog posts, or podcasts, directly into your application's workflows.

Configuration

Configuring the RSS trigger is straightforward but requires attention to specific settings tailored to monitoring and processing RSS feeds.

General Configuration

Martini's general trigger configurations apply to all trigger types and include settings for authentication, error handling, and logging. These settings provide the foundation for configuring RSS and other types of triggers within Martini. Refer to the Martini documentation for detailed information on general trigger configurations.

RSS-specific Configuration

The RSS trigger has specific properties that must be set for it to monitor and process RSS feeds effectively.

Property Default Description
URL (required) The URL hosting the RSS feed.
Polling Interval (required) The interval, in seconds, at which Martini checks for changes in the RSS feed.
Only New Entries false When checked, only 'unread' entries in the RSS feed will be sent to the service.

Service Invocation

When the RSS trigger detects new entries in the feed, it automatically invokes a Groovy service with the following parameters, enabling the service to process the feed entries.

Parameters for Groovy Services

Name Type Description
context org.quartz.JobExecutionContext The Quartz context, providing information about the job's runtime environment.
jobDataMap org.quartz.JobDataMap The Quartz job data map, containing data passed to the job during execution.
job org.quartz.Job The Quartz job instance being executed.
feed com.rometools.rome.feed.synd.SyndFeed The object containing the RSS feed.
entries List<com.rometools.rome.feed.synd.SyndEntry> The list of entries in the RSS feed.
entry com.rometools.rome.feed.synd.SyndEntry The newest entry in the feed.

By setting up the RSS trigger as described, developers can automate the invocation of Groovy services in Martini based on real-time RSS feed updates. This functionality allows for seamless integration of dynamic content into applications, ensuring timely responses to new information.

Example

The RSS trigger in Martini enables the automatic invocation of services when there are updates to an RSS feed. Groovy scripts and functions offer flexible and powerful ways to process these updates. Below are examples demonstrating how to use Groovy for handling RSS feed updates.

Groovy Script as Service

Consider a Groovy script designed to print the available variables in the context when an RSS feed triggers the service. This script is an excellent starting point for understanding how to access and manipulate the data passed to a service by an RSS trigger.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[
    'properties',
    'parameters',
    'martiniPackage',
    'properties',
    'feed',
    'entries',
    'entry',
    '$trackerId',
    '$tracker'
].each {
    println "$it\t : " + this[it]
}

When the RSS trigger detects new entries and invokes this script, the console will display logs similar to the following, listing all available variables and their values:

1
2
3
4
5
6
7
8
9
properties    : [ <omitted> ]
parameters    : [ <omitted> ]
martiniPackage: martiniPackage [name=examples]
properties    : [runAs:, schedule:repeating:120, documentType:RSS, onlyNew:false, track:false,... <omitted>]
feed          : <omitted>
entries       : [ <omitted> ]
entry         : <omitted>
$trackerId    : null
$tracker      : null

This example demonstrates how to access context information, RSS feed data, and specific entries within the script.

Groovy Function as Service

For more structured and reusable code, you can define a Groovy class with functions that handle RSS feed updates. Here's an example of a Groovy class with a function designed to log titles of new RSS entries:

1
2
3
4
5
6
7
8
class RSSExamples {

    void read(def entries) {
        entries.each {
            "Found a new RSS item with title ${it.title}".info()
        }
    }
}

This function, read, takes the list of SyndEntry objects provided by the entries variable and uses a logger to print the title of each entry. To use this function as a service, you would configure the RSS trigger to invoke this specific method, passing the entries variable as an argument.

These examples illustrate how Groovy scripts and functions can be utilized to process RSS feed updates in Martini. The flexibility of Groovy allows for sophisticated data manipulation and processing, enabling developers to integrate complex logic into their RSS-triggered services.

Want more examples?

Martini's distribution includes a package called examples, which contains services demonstrating more use cases. Explore this package for additional examples and inspiration for your own implementations.