Skip to content

Instantly share code, notes, and snippets.

@dashdotat
Created December 18, 2013 16:55
Show Gist options
  • Save dashdotat/8025768 to your computer and use it in GitHub Desktop.
Save dashdotat/8025768 to your computer and use it in GitHub Desktop.
NRPoller
require 'socket'
require 'stomp'
class NrPollerPoller
def initialize
@hostname = 'datafeeds.networkrail.co.uk'
@username = '<username used at https://datafeeds.networkrail.co.uk/ntrod/login>'
@password = '<password used at https://datafeeds.networkrail.co.uk/ntrod/login>'
puts 'Stomp consumer for Network Rail Open Data Distribution Service'
end
def run
client_headers = { 'accept-version' => '1.1',
'heart-beat' => '5000,10000',
'client-id' => Socket.gethostname,
'host' => @hostname }
client_hash = { :hosts => [ { :login => @username, :password => @password, :host => @hostname, :port => 61618 } ],
:connect_headers => client_headers }
client = Stomp::Client.new(client_hash)
raise 'Connection failed' unless client.open?
raise "Connect error: #{client.connection_frame().body}" if client.connection_frame().command == Stomp::CMD_ERROR
raise "Unexpected protocol level #{client.protocol}" unless client.protocol == Stomp::SPL_11
puts "Connected to #{client.connection_frame().headers['server']} server with STOMP #{client.connection_frame().headers['version']}"
client.subscribe('/topic/TRAIN_MVT_EG_TOC', { 'id' => client.uuid(), 'ack' => 'client', 'activemq.subscriptionName' => Socket.gethostname + '-TRAIN_MVT_EG_TOC' }) do |msg|
puts msg.body
client.acknowledge(msg, msg.headers)
end
client.join
client.close
puts "Client close complete"
end
end
e = NrPollerPoller.new
e.run
@raj2kumar2
Copy link

Hi currently i am running this file and got result in command line. i want to know the next step such as storing & displaying it to browser.
im using apache server (centOs 7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment