Java Examples

From Open Rail Data Wiki
Jump to navigation Jump to search

Gorizza Stomp library

This code requires the Gozirra Stomp library.

import net.ser1.stomp.Client;
import net.ser1.stomp.Listener;

 * Example client that connects to the Network Rail ActiveMQ
 * and subscribes a listener to receive real-time messages
 * @author
public class MyClient {

	//Network Rail ActiveMQ server
	private static final String SERVER = "";
	// Server port for STOMP clients
	private static final int PORT = 61618;
	// Your account username, typically an email address
	private static final String USERNAME = "yourUserName";
	// Your account password
	private static final String PASSWORD = "yourPassword";
	// Example topic (this one is for Southern Train Movements)
	private static final String TOPIC = "/topic/TRAIN_MVT_ALL_TOC"; 
	public static void main(String[] args) throws Exception {
		new MyClient().go();
	 * Connect to a single topic and subscribe a listener
	 * @throws Exception Too lazy to implement exception handling....
	private void go() throws Exception {
		System.out.println("| Connecting...");
		Client client = new Client(SERVER, PORT, USERNAME, PASSWORD);
		if (client.isConnected()) {
			System.out.println("| Connected to " + SERVER + ":" + PORT);
		} else {
			System.out.println("| Could not connect");
		System.out.println("| Subscribing...");
		Listener listener = new MyListener();
		client.subscribe(TOPIC , listener);
		System.out.println("| Subscribed to " + TOPIC);
		System.out.println("| Waiting for message...");
import net.ser1.stomp.Listener;
import java.util.Map;
 * Example listener process that receives messages 
 * in JSON format from the Network Rail ActiveMQ
 * @author
public class MyListener implements Listener {
	public void message(Map header, String body) {
		System.out.println("| Got header: " + header);
		System.out.println("| Got body: " + body);

Network Rail Open Data Feeds
Data Feeds About the Feeds Account States Durable Subscriptions Example Code ( PHP / C# / Java / Ruby / Node.js) • Advanced UsesFAQ Release Notes
Train Movements Train Movements Feed Train Activation Train Cancellation Train Movement Train Reinstatement Change of Origin Change of Identity Change of Location TSPEED Field Planned Cancellations Cancellation Codes
TD TD Feed C-Class Messages S-Class Messages Train Describers TD Berths
TSR TSR Feed Route Codes
SCHEDULE SCHEDULE Feed Schedule and Location Records Association Records CIF Codes How Scheduling Works Allowances
Reference Data Reference Data Feed TOC Codes CIF Codes Delay Attribution Codes Identifying Locations (STANOX, TIPLOC, NLC and 3-Alpha Codes) STANOX Geographical Areas Train Planning data