Ably Hub TFL London tube schedule updates

London tube schedule updates

From: TFL

Pull Streams Supported

  • Ably Native SDKs
  • Websockets
  • SSE/HTTP Streaming
  • HTTP
  • MQTT
  • AMQP
  • STOMP
  • GRPC
View Pull code examples of using this product

Push Streams Supported

  • Google Cloud functions
  • AWS Lambda
  • Azure Functions
  • Webhooks
  • Websub
  • AMQP
  • Kafka
  • Kinesis
  • Amazon SQS
View Push code examples of using this product

Licensing

License category:

Channel scope

[product: ably-tfl/tube]

Code example to subscribe to predictions data stream

Choose a Pull delivery transport:

  • 
    var ably = new Ably.Realtime(<API_KEY>);
    var channel = ably.channels.get('[product:ably-tfl/tube]' + <CHANNEL_NAME>);
    
    channel.subscribe(function(message) {
      alert(message.data);
    });
    
    
    var ably = new Ably.Realtime(<API_KEY>);
    var channel = ably.channels.get('[product:ably-tfl/tube]' + <CHANNEL_NAME>);
    
    channel.subscribe(function(message) {
      console.log(message.data);
    });
    
    
    AblyRealtime realtime = new AblyRealtime(<API_KEY>);
    Channel channel = realtime.channels.get("[product:ably-tfl/tube]" + <CHANNEL_NAME>);
    channel.subscribe(new MessageListener() {
      @Override
      public void onMessage(Message message) {
        System.out.println(message.data);
      }
    });
    
    
    let ably = ARTRealtime(key: <API_KEY>)
    let channel = ably.channels.get("[product:ably-tfl/tube]" + <CHANNEL_NAME>)
    
    channel.subscribe("greeting") { message in
      print("\(message.data)")
    }
    
    
    var ably = new AblyRealtime(<API_KEY>);
    var channel = ably.Channels.Get("[product:ably-tfl/tube]" + <CHANNEL_NAME>);
    
    channel.Subscribe(message => {
      Console.WriteLine($"{message.Data}");
    });
    
    
    ARTRest realtime = [[ARTRealtime alloc] initWithKey:<API_KEY>];
    ARTRealtimeChannel *channel = [ably.channels get:@"[product:ably-tfl/tube]" + <CHANNEL_NAME>];
    
    [channel subscribe:^(ARTMessage *message) {
      NSLog(@"Received: %@", message.data);
    }];
    
    

    <API_KEY> is your app's API KEY.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    Select one language

  • 
    const channelName = '[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;;
    const uri = 'wss://realtime.ably.io/event-stream?key=' + &lt;API_KEY&gt; + '&channel=${channelName}';
    const webSocket = new WebSocket(uri);
    webSocket.onmessage = (event) => {
       if (event.data.message) {
          console.log(event.data.message);
       }
    };
    // This protocol is still in private beta. Get in touch if you want early access
    

    <API_KEY> is your app's API KEY.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    Select one language

  • 
    const EventSource = require('eventsource');
    const channelName = '[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;;
    const uri = `https://realtime.ably.io/event-stream?key=&lt;API_KEY&gt;&channel=${channelName}`;
    const evtSource = new EventSource(uri);
    evtSource.addEventListener('message', msg => {
        console.log('Message: ', msg.data);
    });
    // This protocol is still in private beta. Get in touch if you want early access
    

    <API_KEY> is your app's API KEY.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    Select one language

  • 
    // You can only use CURL to obtain history of a channel.
    channel=$(echo "product:ably-tfl/tube]" + &lt;CHANNEL_NAME&gt; | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"');
    curl "https://rest.ably.io/channels/${channel}/messages" -u '&lt;API_KEY&gt;'
    
    
    // This can be used to get the history of a product
    
    var channel = encodeURI('[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;)
    $.ajax({
            url: 'https://rest.ably.io/channels/' + channel + '/messages',
            xhrFields: {
                withCredentials: true
            },
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'Basic ' + btoa(&lt;API_KEY&gt;));
            },
            success: function(data){
                alert(data);
            }
    })
    var channel = encodeURI('[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;)
    

    <API_KEY> is your app's API KEY.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    Select one language

  • 
    // Using https://www.npmjs.com/package/mqtt
    var mqtt = require('mqtt')
    
    var options = { 
      keepAlive: 15,
      username: &lt;API_KEY_ID&gt;,
      password: &lt;API_KEY_SECRET&gt;,
      port: 8883
    };
    
    var client = mqtt.connect('mqtts:mqtt.ably.io', options);
    
    var channel = encodeURI('[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;)
    client.on('connect', function () {
      client.subscribe(channel);
    })
    
    client.on('message', function (topic, message) {
      console.log(message.toString())
    })
    
    
    import paho.mqtt.client as mqtt
    
    def on_connect(client, userdata, message):
      print(message)
    
    client = mqtt.Client()
    client.username_pw_set(&lt;API_KEY_ID&gt;, &lt;API_KEY_SECRET&gt;)
    client.tls_set()
    client.loop_start()
    client.connect('mqtt.ably.io', port=8883, keepalive=15)
    
    client.subscribe('[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;)
    client.on_message = on_message
    
    
    import (
      MQTT "github.com/eclipse/paho.mqtt.golang"
    )
    
    func main() {
      options := MQTT.NewClientOptions();
      options.AddBroker("ssl://mqtt.ably.io:8883")
      options.SetKeepAlive(15)
      options.SetUsername("API_KEY_ID")
      options.SetPassword("API_KEY_SECRET")
      client := MQTT.NewClient(options)
      client.Connect();
      client.Subscribe('[product:ably-tfl/tube]' + &lt;CHANNEL_NAME&gt;, 0, func(client mqtt.Client, msg mqtt.Message) {
        // Deal with message
      });
    }
    

    <API_KEY_ID> should be your API KEY id.

    <API_KEY_SECRET> should be your secret part of your API.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    Select one language

  • 
    const amqp = require('amqplib/callback_api');
    const queue = &lt;APP_ID&gt; + ':' + &lt;QUEUE_NAME&gt;;
    const url = 'amqps://' + &lt;API_KEY&gt; + '@' + &lt;QUEUE_ENDPOINT&gt;;
    
    amqp.connect(url, (err, conn) => {
      conn.createChannel((err, ch) => {
        ch.consume(queue, (item) => {
          // Deal with messages
        });
      });
    });
    
    
    using RabbitMQ.Client;
    
    string url = "amqps://" + &lt;API_KEY&gt; + "@" + &lt;QUEUE_ENDPOINT&gt;;
    string ablyQueue = &lt;APP_ID&gt; + ":" + &lt;QUEUE_NAME&gt;;
    
    var factory = new ConnectionFactory() { HostName = url };
    using (var connection = factory.CreateConnection()) {
        using (var channel = connection.CreateModel()) {
          channel.QueueDeclare(queue: ablyQueue);
    
          var consumer = new EventingBasicConsumer(channel);
          consumer.Received += (model, ea) => {
            // Deal with your messages
          };
        }
    }
    
    
    private final static String QUEUE_NAME = &lt;APP_ID&gt; + ":" + &lt;QUEUE_NAME&gt;;
    private final static String URL = "amqps://" + &lt;API_KEY&gt; + "@" + &lt;QUEUE_ENDPOINT&gt;;
    
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(URL);
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    
    // deliverCallback to be used to deal with messages
    channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> { });
    

    <API_KEY> is your app's API KEY.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    <QUEUE_*> are elements of your Ably queue.

    <APP_ID> is the first part of your API key.

    Select one language

  • 
    const Stompit = require('stompit');
    
    const connectOptions = {
      'host': &lt;QUEUE_ENDPOINT&gt;,
      'port': &lt;QUEUE_PORT&gt;,
      'ssl': true,
      'connectHeaders':{
        'host': &lt;QUEUE_VHOST&gt;,
        'login': &lt;API_KEY_ID&gt;,
        'passcode': &lt;API_KEY_SECRET&gt;
      }
    };
    
    const subscribeHeaders = {
      'destination': '/amq/queue/' + &lt;QUEUE_NAME&gt;
      'ack': 'client-individual'
    };
    
    Stompit.connect(connectOptions, function(error, client) {
      client.subscribe(subscribeHeaders, function(error, message) {
        message.readString('utf-8', function(error, body) {
          // Do what you want with the body
        });
      });
    });
    

    <API_KEY_ID> should be your API KEY id.

    <API_KEY_SECRET> should be your secret part of your API.

    <CHANNEL_NAME> is the name of a channel which the producer is publishing on.

    <QUEUE_*> are elements of your Ably queue.

    For Serverless and Push integration:

    • Google Cloud functions
    • AWS Lambda
    • Azure Functions
    • Webhooks
    • Websub
    • AMQP
    • Kafka
    • Kinesis
    • Amazon SQS
    View Push code examples of using this product

    Ably carries out periodic reviews of products in the Ably Hub. However, we don't individually review each new product or update. As such, we cannot endorse or certify any of these products. Report violations or inappropriate products.

    API Streamer ID:
    ably-tfl/tube

    Image preview Image preview
    Hub logo light

    Ably Hub

    This stream is bought to you via the Ably Hub - the place to go for data streams for your apps & services.

    Looking for a specific data source?

    Suggest a source
    Cons graphic