Author: chirino
Date: Fri Dec 10 21:13:05 2010
New Revision: 1044514
URL: http://svn.apache.org/viewvc?rev=1044514&view=rev
Log:
Simplifying the out of the box stomp ruby examples and defaulting the user
id/password.
Modified:
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
Modified:
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb?rev=1044514&r1=1044513&r2=1044514&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
(original)
+++
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
Fri Dec 10 21:13:05 2010
@@ -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
@@ -15,34 +15,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
-
require 'rubygems'
require 'stomp'
+user = ENV["STOMP_USER"] || "admin"
+password = ENV["STOMP_PASSWORD"] || "password"
+host = ENV["STOMP_HOST"] || "localhost"
+port = ENV["STOMP_PORT"] || 61613
+destination = $*[0] || "/topic/event"
+
begin
- @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
-
- @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"
+
+ headers = {'persistent'=>'false'}
+ headers['reply-to'] = $*[1] if $*[1] != NIL
+
+ STDIN.each_line { |line|
+ conn.publish destination, line, headers
+ }
+ conn.disconnect
rescue
end
Modified:
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb?rev=1044514&r1=1044513&r2=1044514&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
(original)
+++
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
Fri Dec 10 21:13:05 2010
@@ -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,33 +19,35 @@
require 'rubygems'
require 'stomp'
-...@conn = Stomp::Connection.open '', '', 'localhost', 61613, false
-...@count = 0
+user = ENV["STOMP_USER"] || "admin"
+password = ENV["STOMP_PASSWORD"] || "password"
+host = ENV["STOMP_HOST"] || "localhost"
+port = ENV["STOMP_PORT"] || 61613
+destination = $*[0] || "/topic/event"
[email protected] '/topic/event', { :ack =>"auto" }
+conn = Stomp::Connection.open user, password, host, port, false
+count = 0
+
+conn.subscribe destination, { :ack =>"auto" }
+start = Time.now
while true
- @msg = @conn.receive
- if @msg.command == "MESSAGE"
- if @msg.body == "SHUTDOWN"
+ msg = conn.receive
+ if msg.command == "MESSAGE"
+ if msg.body == "SHUTDOWN"
+ diff = Time.now - start
+ $stdout.print "Received #{count} in #{diff} seconds\n";
exit 0
- elsif @msg.body == "REPORT"
- @diff = Time.now - @start
- @body = "Received #...@count} in #...@diff} seconds";
- @conn.send '/queue/response', @body,
{'persistent'=>'false'}
- @count = 0;
else
- if @count == 0
- @start = Time.now
- end
-
- @count += 1;
- if @count % 1000 == 0
- $stdout.print "Received #...@count} messages.\n"
+ start = Time.now if count==0
+ count += 1;
+ if count % 1000 == 0
+ $stdout.print "Received #{count} messages.\n"
end
end
else
- $stdout.print "#[email protected]}: #[email protected]}\n"
+ $stdout.print "#{msg.command}: #{msg.body}\n"
end
end
[email protected]
\ No newline at end of file
+
+conn.disconnect
Modified:
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb?rev=1044514&r1=1044513&r2=1044514&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
(original)
+++
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
Fri Dec 10 21:13:05 2010
@@ -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,49 +19,27 @@
require 'rubygems'
require 'stomp'
-...@conn = Stomp::Connection.open '', '', 'localhost', 61613, false
-...@messages = 10000
-...@batches = 40
-...@subscribers = 10
-...@size = 256
-
-...@data = "abcdefghijklmnopqrstuvwxyz";
-...@body = "";
-for i in 0..(@size-1)
- @body += @DATA[ i % @DATA.length,1]
-end
-
-...@times = []
[email protected] '/queue/response', { :ack =>"auto" }
+messages = 10000
+size = 256
-for i in 1..(@batches)
- @body += @DATA[ i % @DATA.length,1]
- sleep 1 if i == 1
-
- @start = Time.now
-
- for j in 1...@messages
- @conn.publish '/topic/event', @body, {'persistent'=>'false'}
- $stdout.print "Sent #{j} messages\n" if j%1000==0
- end
- @conn.publish '/topic/event', "REPORT", {'persistent'=>'false'}
-
- @remaining = @subscribers
- while @remaining > 0
- @msg = @conn.receive
- if @msg.command == "MESSAGE"
- @remaining -= 1
- $stdout.print "Received report: #[email protected]},
remaining: #...@remaining}\n"
- else
- $stdout.print "#[email protected]}: #[email protected]}\n"
- end
- end
- @diff = time.n...@start
-
- $stdout.print "Batch #{i} of #...@batches} completed in #...@diff}
seconds.\n"
- @times[i] = @diff
+user = ENV["STOMP_USER"] || "admin"
+password = ENV["STOMP_PASSWORD"] || "password"
+host = ENV["STOMP_HOST"] || "localhost"
+port = ENV["STOMP_PORT"] || 61613
+destination = $*[0] || "/topic/event"
+
+conn = Stomp::Connection.open user, password, host, port, false
+
+DATA = "abcdefghijklmnopqrstuvwxyz";
+body = "";
+for i in 0..(size-1)
+ body += DATA[ i % DATA.length,1]
end
[email protected] '/topic/event', "SHUTDOWN", {'persistent'=>'false'}
+for i in 1..messages
+ conn.publish destination, body, {'persistent'=>'false'}
+ $stdout.print "Sent #{i} messages\n" if i%1000==0
+end
[email protected]
\ No newline at end of file
+conn.publish destination, "SHUTDOWN", {'persistent'=>'false'}
+conn.disconnect
Modified:
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb?rev=1044514&r1=1044513&r2=1044514&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
(original)
+++
activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
Fri Dec 10 21:13:05 2010
@@ -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,26 @@
require 'rubygems'
require 'stomp'
+user = ENV["STOMP_USER"] || "admin"
+password = ENV["STOMP_PASSWORD"] || "password"
+host = ENV["STOMP_HOST"] || "localhost"
+port = ENV["STOMP_PORT"] || 61613
+destination = $*[0] || "/topic/event"
+
begin
- @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
-
- @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 "Getting output from #...@destination}\n"
-
- @conn.subscribe @destination, { :ack =>"client" }
- while true
- @msg = @conn.receive
- $stdout.print @msg.body
- $stdout.flush
- @conn.ack @msg.headers["message-id"]
- end
- @conn.disconnect
+ $stderr.print "Connecting to stomp://#{host}:#{port} as #{user}\n"
+ conn = Stomp::Connection.open user, password, host, port, true
+ $stderr.print "Getting output from #{destination}\n"
+
+ conn.subscribe destination, { :ack =>"client" }
+ while true
+ msg = conn.receive
+ $stdout.print msg.body
+ $stdout.flush
+ conn.ack msg.headers["message-id"]
+ end
+ conn.disconnect
rescue
end