Created
December 18, 2013 16:55
-
-
Save dashdotat/8025768 to your computer and use it in GitHub Desktop.
NRPoller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)