activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1028714 - in /activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples: ./ ruby/ ruby/catstomp.rb ruby/listener.rb ruby/publisher.rb ruby/readme.md ruby/stompcat.rb
Date Fri, 29 Oct 2010 12:22:18 GMT
Author: chirino
Date: Fri Oct 29 12:22:17 2010
New Revision: 1028714

URL: http://svn.apache.org/viewvc?rev=1028714&view=rev
Log:
adding the ruby stomp examples from activemq 5.x

Added:
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
  (with props)
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
  (with props)
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
  (with props)
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/readme.md
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
  (with props)

Added: 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=1028714&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
Fri Oct 29 12:22:17 2010
@@ -0,0 +1,49 @@
+#!/usr/bin/ruby
+# ------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ------------------------------------------------------------------------
+
+require 'rubygems'
+require 'stomp'
+
+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
+
+rescue 
+end
+

Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/catstomp.rb
------------------------------------------------------------------------------
    svn:executable = *

Added: 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=1028714&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
Fri Oct 29 12:22:17 2010
@@ -0,0 +1,51 @@
+#!/usr/bin/ruby
+# ------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ------------------------------------------------------------------------
+ 
+require 'rubygems'
+require 'stomp'
+
+@conn = Stomp::Connection.open '', '', 'localhost', 61613, false 
+@count = 0
+
+@conn.subscribe '/topic/event', { :ack =>"auto" }
+while true 
+	@msg = @conn.receive
+	if @msg.command == "MESSAGE" 
+		if @msg.body == "SHUTDOWN"
+			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"
+			end
+		end
+	else
+ 		$stdout.print "#{@msg.command}: #{@msg.body}\n"
+	end
+end
+@conn.disconnect
\ No newline at end of file

Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/listener.rb
------------------------------------------------------------------------------
    svn:executable = *

Added: 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=1028714&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
Fri Oct 29 12:22:17 2010
@@ -0,0 +1,67 @@
+#!/usr/bin/ruby
+# ------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ------------------------------------------------------------------------
+ 
+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 = []
+@conn.subscribe '/queue/response', { :ack =>"auto" }
+
+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.send '/topic/event', @body, {'persistent'=>'false'}
+		$stdout.print "Sent #{j} messages\n" if j%1000==0
+	end
+	@conn.send '/topic/event', "REPORT", {'persistent'=>'false'}
+
+	@remaining = @subscribers
+	while @remaining > 0
+		@msg = @conn.receive
+		if @msg.command == "MESSAGE" 
+			@remaining -= 1
+			$stdout.print "Received report: #{@msg.body}, remaining: #{@remaining}\n"
+		else
+ 			$stdout.print "#{@msg.command}: #{@msg.body}\n"
+		end
+	end
+ 	@diff = Time.now-@start
+
+	$stdout.print "Batch #{i} of #{@batches} completed in #{@diff} seconds.\n"
+	@times[i] = @diff
+end
+
+@conn.send '/topic/event', "SHUTDOWN", {'persistent'=>'false'}
+
+@conn.disconnect
\ No newline at end of file

Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/publisher.rb
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/readme.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/readme.md?rev=1028714&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/readme.md
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/readme.md
Fri Oct 29 12:22:17 2010
@@ -0,0 +1,27 @@
+Prereqs
+=======
+
+- Install RubyGems see: http://docs.rubygems.org/
+- Install the stomp gem.  Run: gem install stomp
+
+Overview of stompcat.rb and catstomp.rb 
+==========================================
+
+The basic idea behind these scripts to to create something like netcat except over JMS
+destinations.
+
+catstomp.rb - takes stdin and sends it to a stomp destination
+stompcat.rb - outputs data received from a stomp destination
+
+A simple example usage:
+
+In console 1 run:
+cat | ./catstomp.rb
+
+In console 2 run:
+./stompcat.rb
+
+now any line you enter into console 1 will get sent to console 2.
+
+Hopefully these to scripts can get merged together in the future and the command line
+arguments can change so that it look more like netcat.

Added: 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=1028714&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
Fri Oct 29 12:22:17 2010
@@ -0,0 +1,50 @@
+#!/usr/bin/ruby
+# ------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ------------------------------------------------------------------------
+
+require 'rubygems'
+require 'stomp'
+
+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
+  
+rescue 
+end
+

Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/ruby/stompcat.rb
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message