AMQ-4070: Improved ruby sample to shutdown nicely on cltr+c, and use publish. Thanks to Francesco for the patch.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1389793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Claus Ibsen 2012-09-25 11:00:29 +00:00
parent fa29678c54
commit d9c73363a9
1 changed files with 29 additions and 22 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/ruby
#!/usr/bin/env ruby
# ------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@ -19,31 +19,38 @@
require 'rubygems'
require 'stomp'
begin
continue = true
trap("INT") {
puts "CTRL+C"
puts "shutting down ..."
@conn.disconnect
sleep 1
STDIN.close
}
@port = 61613
@host = "localhost"
@user = ENV["STOMP_USER"];
@password = ENV["STOMP_PASSWORD"]
@port = 61613
@host = "localhost"
@user = ENV["STOMP_USER"];
@password = ENV["STOMP_PASSWORD"]
@host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != NIL
@port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != NIL
@host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != NIL
@port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != NIL
@destination = "/topic/stompcat"
@destination = $*[0] if $*[0] != NIL
@destination = "/topic/stompcat"
@destination = $*[0] if $*[0] != NIL
$stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
@conn = Stomp::Connection.open @user, @password, @host, @port, true
$stderr.print "Sending input to #{@destination}\n"
$stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
@conn = Stomp::Connection.open @user, @password, @host, @port, true
$stderr.print "Sending input to #{@destination}\n"
@headers = {'persistent'=>'false'}
@headers['reply-to'] = $*[1] if $*[1] != NIL
@headers = {'persistent'=>'false'}
@headers['reply-to'] = $*[1] if $*[1] != NIL
STDIN.each_line { |line|
@conn.send @destination, line, @headers
}
@conn.disconnect
rescue
begin
STDIN.each_line { |line|
@conn.publish @destination, line, @headers
}
rescue IOError
end