| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
begin; require 'rubygems'; rescue; end |
| 18 |
require 'stomp' |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
begin |
| 30 |
|
| 31 |
if ARGV[0] == '-h' || ARGV[0] == '--help' |
| 32 |
$stdout.puts |
| 33 |
$stdout.puts 'Usage: catstomp DESTINATION' |
| 34 |
$stdout.puts |
| 35 |
$stdout.puts 'Publishes STDIN to the desired stomp destination' |
| 36 |
$stdout.puts |
| 37 |
$stdout.puts 'Example: ls | catstomp /topic/foo' |
| 38 |
$stdout.puts |
| 39 |
$stdout.puts 'Defaults:' |
| 40 |
$stdout.puts "DESTINATION\t/topic/default" |
| 41 |
$stdout.puts "STOMP_HOST\tlocalhost" |
| 42 |
$stdout.puts "STOMP_PORT\t61613" |
| 43 |
$stdout.puts "STOMP_USER" |
| 44 |
$stdout.puts "STOMP_PASSWORD" |
| 45 |
$stdout.puts |
| 46 |
$stdout.puts 'You can override the stomp host, port, user, or password through environment variables' |
| 47 |
exit 0 |
| 48 |
end |
| 49 |
|
| 50 |
@port = 61613 |
| 51 |
@host = "localhost" |
| 52 |
@user = ENV["STOMP_USER"]; |
| 53 |
@password = ENV["STOMP_PASSWORD"] |
| 54 |
|
| 55 |
@host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != nil |
| 56 |
@port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != nil |
| 57 |
|
| 58 |
@destination = "/topic/default" |
| 59 |
@destination = $*[0] if $*[0] != nil |
| 60 |
|
| 61 |
$stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n" |
| 62 |
@conn = Stomp::Connection.open(@user, @password, @host, @port, true) |
| 63 |
$stderr.print "Sending input to #{@destination}\n" |
| 64 |
|
| 65 |
@headers = {'persistent'=>'false'} |
| 66 |
@headers['reply-to'] = $*[1] if $*[1] != nil |
| 67 |
|
| 68 |
STDIN.each_line { |line| |
| 69 |
@conn.publish @destination, line, @headers |
| 70 |
} |
| 71 |
|
| 72 |
rescue |
| 73 |
end |
| 74 |
|