Difference between revisions of "Advanced Uses"

From Open Rail Data Wiki
Jump to navigation Jump to search
m (Added category)
(Update example to use Camel)
Line 1: Line 1:
 
=Bridging Topics=
 
=Bridging Topics=
  
It is possible to 'bridge' data from the Data Feeds platform to your own ActiveMQ server.  You may want to do this if:
+
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 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
 
* 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 platform is monitored, and more users equals better opportunity for making further data available!
+
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.
 
Be warned - this example assumes knowledge of ActiveMQ, and is community-supported only.
Line 12: Line 12:
 
==Configuration==
 
==Configuration==
  
Download [http://activemq.apache.org/ ActiveMQ] and add the following configuration to conf/activemq.xml:
+
Download [http://activemq.apache.org/ ActiveMQ] and add the following configuration to conf/activemq.xml before the end of the '''beans''' tag:
  
<pre><bean id="nrDataFeedsRemote" class="org.apache.activemq.ActiveMQConnectionFactory">
+
<pre><import resource="camel.xml"/></pre>
  <property name="brokerURL" value="tcp://datafeeds.networkrail.co.uk:61619"/>
 
  <property name="userName" value="YOUR_USERNAME"/>
 
  <property name="password" value="YOUR_PASSWORD"/>
 
</bean>
 
  
<bean id="localBroker" class="org.apache.activemq.ActiveMQConnectionFactory">
+
Create the file conf/camel.xml with the following:
  <property name="brokerURL" value="tcp://localhost:61616"/>
 
</bean>
 
  
<jmsBridgeConnectors>
+
<pre><?xml version="1.0"?>
  <jmsTopicConnector name="nrDataFeeds" outboundClientId="YOUR_USERNAME" outboundTopicConnectionFactory="#nrDataFeedsRemote" localTopicConnectionFactory="#localBroker">
+
<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">
    <inboundTopicBridges>
+
 
      <inboundTopicBridge consumerName="YOUR_USERNAME-movements" inboundTopicName="TRAIN_MVT_ALL_TOC" localTopicName="TRAIN_MVT_ALL_TOC"/>
+
  <camelContext xmlns="http://camel.apache.org/schema/spring" id="camel">
      <inboundTopicBridge consumerName="YOUR_USERNAME-td" inboundTopicName="TD_ALL_SIG_AREA" localTopicName="TD_ALL_SIG_AREA"/>
+
  </camelContext>
      <inboundTopicBridge consumerName="YOUR_USERNAME-vstp" inboundTopicName="VSTP_ALL" localTopicName="VSTP_ALL"/>
+
 
      <inboundTopicBridge consumerName="YOUR_USERNAME-tsr" inboundTopicName="TSR_ALL_ROUTE" localTopicName="TSR_ALL_ROUTE"/>
+
  <bean id="amq" class="org.apache.activemq.camel.component.ActiveMQComponent">
      <inboundTopicBridge consumerName="YOUR_USERNAME-rtppm" inboundTopicName="RTPPM_ALL" localTopicName="RTPPM_ALL"/>
+
    <property name="brokerURL" value="tcp://localhost:61616"/>
    </inboundTopicBridges>
+
  </bean>
   </jmsTopicConnector>
+
</pre>
</jmsBridgeConnectors>
+
 
 +
This sets up a Camel Context in which you can configure routes.
 +
 
 +
To connect to an ActiveMQ service, add the following bean:
 +
 
 +
<pre>  <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>
 +
</pre>
 +
 
 +
Replace $NAME$ with the name of the bean, e.g. "darwin" or "networkrail".  Replace $HOSTNAME$:$PORT$ with either datafeeds.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 or topic to a local queue or topic, add the following within the '''camelContext''' tag:
 +
 
 +
<pre><route>
 +
  <from uri="$NAME$:queue:$QUEUE$"/>
 +
   <to uri="amq:topic:$TOPIC$"/>
 +
</route>
 
</pre>
 
</pre>
  
Ensure you have subscribed to the feeds you want to bridge - if you only want certain feeds, change the inboundTopicBridge tags as appropriate.
+
Replace 'queue' or 'topic' as appropriate, depending on whether you're bridging a topic (Network Rail) or queue (National Rail).  You can bridge to either a queue or topic on your local ActiveMQ server.
  
Start ActiveMQ, and check the web interface to ensure your topics are being bridged.
+
Finally, start ActiveMQ, and check the web interface to ensure your data is being routed.
  
 
{{Navtable-DataFeeds}}
 
{{Navtable-DataFeeds}}

Revision as of 12:08, 4 September 2015

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>

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

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

  <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 datafeeds.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 or topic to a local queue or topic, add the following within the camelContext tag:

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

Replace 'queue' or 'topic' as appropriate, depending on whether you're bridging a topic (Network Rail) or queue (National Rail). You can bridge to either a queue or topic on your local ActiveMQ server.

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