Advanced Uses

From Open Rail Data Wiki
Jump to navigation Jump to search

Bridging Topics

It is possible to 'bridge' data from the Data Feeds platforms to your own ActiveMQ server. You may want to do this if:

  • You need to store messages for longer than the durable subscription TTL of 5 minutes
  • You want to have multiple consumers connected over a slow network connection

If you do this, please don't simply re-publish data for other people or organisations. Usage of the Data Feeds platforms is monitored, and more users equals better opportunity for making further data available!

Be warned - this example assumes knowledge of ActiveMQ, and is community-supported only.

Configuration

Download ActiveMQ and add the following configuration to conf/activemq.xml before the end of the beans tag:

<import resource="camel.xml"/>

Create the file conf/camel.xml with the following:

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/spring" id="camel">
  </camelContext>

  <bean id="amq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61616"/>
  </bean>
</beans>

This sets up a Camel Context in which you can configure routes.

To connect to an ActiveMQ service, add the following bean outside the camelContext tag:

  <bean id="$NAME$" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://$HOSTNAME$:$PORT$"/>
    <property name="userName" value="$USERNAME$"/>
    <property name="password" value="$PASSWORD"/>
  </bean>

Replace $NAME$ with the name of the bean, e.g. "darwin" or "networkrail". Replace $HOSTNAME$:$PORT$ with either publicdatafeeds.networkrail.co.uk:61619 or datafeeds.nationalrail.co.uk:61616, and $USERNAME$ and $PASSWORD$ with the username/password as appropriate.

To route data from a queue on the National Rail Enquiries service, add the following within the camelContext tag:

<route>
  <from uri="$NAME$:queue:$QUEUE$"/>
  <to uri="amq:topic:$TOPIC$"/>
</route>

To route data from a topic on the Network Rail service, add the following within the camelContext tag:

<route>
  <from uri="$NAME$:topic:$TOPIC$?clientId=$CLIENT_ID$&amp;durableSubscriptionName=$SUBSCRIPTION_NAME$"/>
  <to uri="amq:topic:$TOPIC$"/>
</route>

Replace $CLIENT_ID$ with a client ID which start with the email address you use to subscribe, followed by the name of the feed e.g. "user@example.com-td" for the TD feed. Set a sensible name for the $SUBSCRIPTION_NAME$ setting, for example, your email address.

Finally, start ActiveMQ, and check the web interface to ensure your data is being routed.


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
RTPPM RTPPM Feed
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
VSTP VSTP Feed
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