Ruby: Difference between revisions
Created page with "Ruby example to go here" |
Added example code for Ruby |
||
Line 1: | Line 1: | ||
Ruby | Here is a very simple Ruby script to get you subscribing to messages, they simply get output to the console. | ||
Note that you'll need environment variables set up with DATAFEEDS_USER as your username and DATAFEEDS_PASSWORD as your password - for the datafeeds.networkrail.co.uk site. | |||
<code> | |||
require 'stomp' | |||
begin | |||
# Credentials set here as environment variables | |||
@user = ENV["DATAFEEDS_USER"]; | |||
@password = ENV["DATAFEEDS_PASSWORD"] | |||
@host = "datafeeds.networkrail.co.uk" | |||
@port = 61618 | |||
# Example destination add yours here | |||
@destination = "/topic/TD_ALL_SIG_AREA" | |||
puts "Connecting to datafeeds as #{@user} using stomp protocol stomp://#{@host}:#{@port}\n" | |||
@connection = Stomp::Connection.open @user, @password, @host, @port, true | |||
@connection.subscribe @destination | |||
while true | |||
@msg = @connection.receive | |||
puts @msg | |||
end | |||
@connection.disconnect | |||
rescue | |||
end | |||
</code> |
Revision as of 15:37, 4 September 2012
Here is a very simple Ruby script to get you subscribing to messages, they simply get output to the console.
Note that you'll need environment variables set up with DATAFEEDS_USER as your username and DATAFEEDS_PASSWORD as your password - for the datafeeds.networkrail.co.uk site.
require 'stomp'
begin
# Credentials set here as environment variables
@user = ENV["DATAFEEDS_USER"];
@password = ENV["DATAFEEDS_PASSWORD"]
@host = "datafeeds.networkrail.co.uk"
@port = 61618
# Example destination add yours here
@destination = "/topic/TD_ALL_SIG_AREA"
puts "Connecting to datafeeds as #{@user} using stomp protocol stomp://#{@host}:#{@port}\n"
@connection = Stomp::Connection.open @user, @password, @host, @port, true
@connection.subscribe @destination
while true
@msg = @connection.receive
puts @msg
end
@connection.disconnect
rescue
end