Skip to content
bdferris edited this page Feb 24, 2012 · 11 revisions

The onebusaway-gtfs-realtime-exporter module provides a number of methods to assist you in producing and sharing a GTFS-realtime real-time transit data feed. Specific features include:

  • Support for running a simple, embedded webserver to quickly share your GTFS-realtime data.
  • Support for writing GTFS-realtime data to a file.
  • Convenience methods for constructing a GTFS-realtime feed.

Quick Start

The onebusaway-gtfs-realtime-exporter module is provided as a Maven module in the OneBusAway Maven Repository. To include it as a dependency to your Maven project, add the following to the <dependencies/> section of your project's pom.xml file:

<dependency>
  <groupId>org.onebusaway</groupId>
  <artifactId>onebusaway-gtfs-realtime-exporter</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>     

How do you use the library? The first step is to write a class that implements the GtfsRealtimeProvider interface. The interface defines a contract for providing GTFS-realtime data through three methods:

public interface GtfsRealtimeProvider {
  FeedMessage getAlerts();
  FeedMessage getTripUpdates();
  FeedMessage getVehiclePositions();
}

The three methods correspond to the three GTFS-realtime feed types. The logic to build your GTFS-realtime feed is up to you to provide and will depend on the nature of your underlying real-time system and data-sources.

Once you've build your provider, it's time to wire it up so that we can easily share the data on the web, or optionally write it to a file to share in a more custom way. We make use of the Google Guice dependency-injection framework to wire everything up.

Set<Module> modules = new HashSet<Module>();
GtfsRealtimeExporterModule.addModuleAndDependencies(modules);
Injector injector = Guice.createInjector(modules);

Once we have our Guice injector, we can now configure our application to share GTFS-realtime data via an embedded web-server, a file, or both.

  AlertsServlet servlet = injector.getInstance(AlertsServlet.class);
  servlet.setUrl(new URL("http://localhost:8080/alerts");

  AlertsFileWriter writer = injector.getInstance(AlertsFileWriter.class);
  writer.setPath("/some/path/for/alerts");

You can configure all three feed types in a similar manner:

Once you've got everything wired up and configured, you can start the application:

LifecycleService lifecycleService = injector.getInstance(LifecycleService.class);
lifecycleService.start();
Clone this wiki locally