activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1389793 - /activemq/trunk/assembly/src/release/example/ruby/catstomp.rb
Date Tue, 25 Sep 2012 11:00:29 GMT
Author: davsclaus
Date: Tue Sep 25 11:00:29 2012
New Revision: 1389793

URL: http://svn.apache.org/viewvc?rev=1389793&view=rev
Log:
AMQ-4070: Improved ruby sample to shutdown nicely on cltr+c, and use publish. Thanks to Francesco
for the patch.

Modified:
    activemq/trunk/assembly/src/release/example/ruby/catstomp.rb

Modified: activemq/trunk/assembly/src/release/example/ruby/catstomp.rb
URL: http://svn.apache.org/viewvc/activemq/trunk/assembly/src/release/example/ruby/catstomp.rb?rev=1389793&r1=1389792&r2=1389793&view=diff
==============================================================================
--- activemq/trunk/assembly/src/release/example/ruby/catstomp.rb (original)
+++ activemq/trunk/assembly/src/release/example/ruby/catstomp.rb Tue Sep 25 11:00:29 2012
@@ -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"
-
-    @headers = {'persistent'=>'false'} 
-    @headers['reply-to'] = $*[1] if $*[1] != NIL
-
-    STDIN.each_line { |line| 
-        @conn.send @destination, line, @headers
-    }
-    @conn.disconnect
+$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"
 
-rescue 
-end
+@headers = {'persistent'=>'false'} 
+@headers['reply-to'] = $*[1] if $*[1] != NIL
 
+begin
+  STDIN.each_line { |line| 
+    @conn.publish @destination, line, @headers
+  }
+rescue IOError
+end



Mime
View raw message