Skip to content

Reads DIFFERENTIAL-mode GTFS Realtime data from NATS message broker, and serves it as FULL_DATASET via HTTP.

License

Notifications You must be signed in to change notification settings

OpenDataVBB/nats-consuming-gtfs-rt-server

Repository files navigation

nats-consuming-gtfs-rt-server

Reads a continuous stream of GTFS Realtime (GTFS-RT) data with DIFFERENTIAL incrementality from NATS, converts it into a single FULL_DATASET GTFS-RT feed, and serves it via HTTP.

Note from gtfs-rt-differential-to-full-dataset, which is used for the conversion:

Right now, this package does not obey the draft DIFFERENTIAL spec exactly. See below and #1 for details.

ISC-licensed

Installation

npm install -g OpenDataVBB/nats-consuming-gtfs-rt-server

Getting Started

# todo

Usage

Usage:
    serve-gtfs-rt-from-nats [options]
Options:
	--port                    -p  Port to serve the GTFS Realtime feed on.
	                              Default: $PORT, otherwise 3000
	--nats-servers                NATS server(s) to connect to.
	                              Default: $NATS_SERVERS
	--nats-user                   User to use when authenticating with NATS server.
	                              Default: $NATS_USER
	--nats-client-name            Name identifying the NATS client among others.
	                              Default: vdv453-1-${randomHex(4)}
	--nats-consumer-name          Name of the NATS JetStream consumer on the
	                              GTFS_RT_2 stream.
	                              Default: $GTFS_RT_CONSUMER_NAME, otherwise `nats-
	                              consuming-gtfs-rt-server`
	--diff-entities-ttl           Time to keep DIFFERENTIAL-mode GTFS-RT FeedEntities
	                              in the combined FULL_DATASET-mode feed for, in seconds.
	                              Default: 10 minutes
	--t0                          UNIX timestamp to use as now, for debugging purposes.
	                              Default: current UNIX timestamp
Examples:
    serve-gtfs-rt-from-nats --port 1234 --nats-user foo

create NATS stream & consumer

Before running nats-consuming-gtfs-rt-server, you must create a NATS JetStream stream called GTFS_RT_2 holding the FeedEntity GTFS-RT messages. This can be done using the NATS CLI:

nats stream add \
	# omit this if you want to configure more details
	--defaults \
	# collect all messages published to these subjects
	--subjects='gtfsrt.>' \
	# acknowledge publishes
	--ack \
	# with limited storage, discard the oldest limits first
	--retention=limits --discard=old \
	--description='GTFS-Realtime FeedEntity messages' \
	# name of the stream
	GTFS_RT_2

On the GTFS_RT_2 stream, you must also create a durable consumer:

nats consumer add \
	# omit this if you want to configure more details
	--defaults \
	# create a pull-based consumer (refer to the NATS JetStream docs)
	--pull \
	# let gtfs-rt-feed explicitly acknowledge all received messages
	--ack=explicit \
	# let the newly created consumer start with the latest messages in GTFS_RT_2 (not all)
	--deliver=new \
	# send gtfs-rt-feed at most 200 messages at once
	--max-pending=500 \
	# when & how often to re-deliver a message that hasn't been acknowledged (usually because it couldn't be processed)
	--max-deliver=3 \
	--backoff=linear \
	--backoff-steps=2 \
	--backoff-min=15s \
	--backoff-max=1m \
	--description 'OpenDataVBB/nats-consuming-gtfs-rt-server' \
	# name of the stream
	GTFS_RT_2 \
	# name of the consumer
	nats-consuming-gtfs-rt-server

Related

Contributing

If you have a question or need support using nats-consuming-gtfs-rt-server, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.

About

Reads DIFFERENTIAL-mode GTFS Realtime data from NATS message broker, and serves it as FULL_DATASET via HTTP.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published