Real-Time Transit Feed Data Processing With Apache NiFi
Ingesting and processing real-time transit feeds at scale with Apache NiFi.
Join the DZone community and get the full member experience.Join For Free
GTFS Real-Time Streaming With Apache NiFi
To facilitate ingesting GTFS Real-Time data, I have added a processor that converts GTFS (General Transit Feed Specification) formatted ProtoBuf data into JSON. This is using the standard Google APIs to accomplish this. You can see the Protocol Buffers schema here.
We will be able to get data on trip updates including delays and service alerts, including changed routes and vehicle positions that can have location and congestion information. This is the same information that these public transit systems feed to Google Maps.
An Example NiFi Flow for Accessing GTFS Data
First, we add my new NiFi Processor, which you can get as a source and build the NAR. Or download one of the release builds of my new NiFi NAR archive. This is alpha-level code done very quickly. If you find bugs, please report and suggest updates.
Once it is added to your canvas, you can change the name and scheduling.
The only setting currently is the URL of the GTFS resource (which may require a key from some transportation APIs).
Once it runs, it will quickly return a flow file containing a JSON-formatted version of the GTFS result, as well as some attributes with GTFS information.
The JSON code has a lot of arrays and subsections, not very flat. We could dump this raw to Hive and query it as a JSON document. Or, we can parse it with FlattenJSON, EvaluateJSONPath, SplitJson, or various other options.
As mentioned before, the main sections are tripUpdate, vehicle, and alerts. I will parse this and use this for real-time Slack, Kafka, HBase, and Kudu messaging. This data can become critical to companies that have trucks or people trying to navigate systems.
My first use case is to see if I can find out this data real-time during a time of emergency or events to help communities. Non-profit agents will be able to have real-time status reports of what transportation is available. You have to ingest, cleanse, and transform data to become knowledge and that can empower the community.
Join me in Puerto Rico at the NetHope Global Summit.
Nar Release to Install in Apache NiFi 1.9.2
Opinions expressed by DZone contributors are their own.