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,7 +19,16 @@
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"
@ -39,11 +48,9 @@ begin
@headers = {'persistent'=>'false'}
@headers['reply-to'] = $*[1] if $*[1] != NIL
begin
STDIN.each_line { |line|
@conn.send @destination, line, @headers
@conn.publish @destination, line, @headers
}
@conn.disconnect
rescue
rescue IOError
end