diff --git a/assembly/src/release/example/ruby/catstomp.rb b/assembly/src/release/example/ruby/catstomp.rb index 96c6c495f5..ed8eff0f44 100755 --- a/assembly/src/release/example/ruby/catstomp.rb +++ b/assembly/src/release/example/ruby/catstomp.rb @@ -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 -