You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2013/10/10 16:40:28 UTC
[05/18] Porting apollo examples structure to ActiveMQ 5.9.
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stompest/readme.md
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stompest/readme.md b/assembly/src/release/examples/stomp/python/stompest/readme.md
new file mode 100644
index 0000000..a1a912b
--- /dev/null
+++ b/assembly/src/release/examples/stomp/python/stompest/readme.md
@@ -0,0 +1,14 @@
+Prereqs
+=======
+
+Install the [stomppy](http://code.google.com/p/stomppy) python client
+library.
+
+easy_install users can install it by running:
+
+ easy_install stompest
+
+The stompest client library supports a blocking API, and you can find an
+example of it's use in the `sync` directory. It also supports using
+a non-blocking API based on Twisted, and that example can be found in
+the `async` directory.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stompest/sync/__init__.py
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stompest/sync/__init__.py b/assembly/src/release/examples/stomp/python/stompest/sync/__init__.py
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stompest/sync/listener.py
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stompest/sync/listener.py b/assembly/src/release/examples/stomp/python/stompest/sync/listener.py
new file mode 100644
index 0000000..2110ee0
--- /dev/null
+++ b/assembly/src/release/examples/stomp/python/stompest/sync/listener.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+"""
+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.
+"""
+import os
+import sys
+import time
+
+from stompest.config import StompConfig
+from stompest.sync import Stomp
+
+user = os.getenv('ACTIVEMQ_USER') or 'admin'
+password = os.getenv('ACTIVEMQ_PASSWORD') or 'password'
+host = os.getenv('ACTIVEMQ_HOST') or 'localhost'
+port = int(os.getenv('ACTIVEMQ_PORT') or 61613)
+destination = sys.argv[1:2] or ['/topic/event']
+destination = destination[0]
+
+config = StompConfig('tcp://%s:%d' % (host, port), login=user, passcode=password, version='1.1')
+client = Stomp(config)
+
+client.connect(host='mybroker')
+client.subscribe(destination=destination, headers={'id': 'required-for-STOMP-1.1'})
+
+count = 0
+start = time.time()
+
+while (not count) or client.canRead(0):
+ client.receiveFrame()
+ count += 1
+
+diff = time.time() - start
+print 'Received %s frames in %f seconds' % (count, diff)
+
+client.disconnect(receipt='bye')
+client.receiveFrame()
+client.close()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stompest/sync/publisher.py
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stompest/sync/publisher.py b/assembly/src/release/examples/stomp/python/stompest/sync/publisher.py
new file mode 100644
index 0000000..d666244
--- /dev/null
+++ b/assembly/src/release/examples/stomp/python/stompest/sync/publisher.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+"""
+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.
+"""
+import os
+import sys
+import time
+
+from stompest.config import StompConfig
+from stompest.sync import Stomp
+
+user = os.getenv('ACTIVEMQ_USER') or 'admin'
+password = os.getenv('ACTIVEMQ_PASSWORD') or 'password'
+host = os.getenv('ACTIVEMQ_HOST') or 'localhost'
+port = int(os.getenv('ACTIVEMQ_PORT') or 61613)
+destination = sys.argv[1:2] or ['/topic/event']
+destination = destination[0]
+
+messages = 10000
+data = 'Hello World from Python'
+
+config = StompConfig('tcp://%s:%d' % (host, port), login=user, passcode=password, version='1.1')
+client = Stomp(config)
+client.connect(host='mybroker')
+
+count = 0
+start = time.time()
+
+for _ in xrange(messages):
+ client.send(destination=destination, body=data, headers={'persistent': 'false'})
+ count += 1
+
+diff = time.time() - start
+print 'Sent %s frames in %f seconds' % (count, diff)
+
+client.disconnect(receipt='bye')
+client.receiveFrame()
+client.close()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stomppy/listener.py
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stomppy/listener.py b/assembly/src/release/examples/stomp/python/stomppy/listener.py
new file mode 100755
index 0000000..81fadaf
--- /dev/null
+++ b/assembly/src/release/examples/stomp/python/stomppy/listener.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# ------------------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------------------
+
+import time
+import sys
+import os
+import stomp
+
+user = os.getenv("ACTIVEMQ_USER") or "admin"
+password = os.getenv("ACTIVEMQ_PASSWORD") or "password"
+host = os.getenv("ACTIVEMQ_HOST") or "localhost"
+port = os.getenv("ACTIVEMQ_PORT") or 61613
+destination = sys.argv[1:2] or ["/topic/event"]
+destination = destination[0]
+
+class MyListener(object):
+
+ def __init__(self, conn):
+ self.conn = conn
+ self.count = 0
+ self.start = time.time()
+
+ def on_error(self, headers, message):
+ print('received an error %s' % message)
+
+ def on_message(self, headers, message):
+ if message == "SHUTDOWN":
+
+ diff = time.time() - self.start
+ print("Received %s in %f seconds" % (self.count, diff))
+ conn.disconnect()
+ sys.exit(0)
+
+ else:
+ if self.count==0:
+ self.start = time.time()
+
+ self.count += 1
+ if self.count % 1000 == 0:
+ print("Received %s messages." % self.count)
+
+conn = stomp.Connection(host_and_ports = [(host, port)])
+conn.set_listener('', MyListener(conn))
+conn.start()
+conn.connect(login=user,passcode=password)
+conn.subscribe(destination=destination, ack='auto')
+print("Waiting for messages...")
+while 1:
+ time.sleep(10)
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stomppy/publisher.py
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stomppy/publisher.py b/assembly/src/release/examples/stomp/python/stomppy/publisher.py
new file mode 100755
index 0000000..4e5e0bf
--- /dev/null
+++ b/assembly/src/release/examples/stomp/python/stomppy/publisher.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# ------------------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------------------
+
+import time
+import sys
+import os
+import stomp
+
+user = os.getenv("ACTIVEMQ_USER") or "admin"
+password = os.getenv("ACTIVEMQ_PASSWORD") or "password"
+host = os.getenv("ACTIVEMQ_HOST") or "localhost"
+port = os.getenv("ACTIVEMQ_PORT") or 61613
+destination = sys.argv[1:2] or ["/topic/event"]
+destination = destination[0]
+
+messages = 10000
+data = "Hello World from Python"
+
+conn = stomp.Connection(host_and_ports = [(host, port)])
+conn.start()
+conn.connect(login=user,passcode=password)
+
+for i in range(0, messages):
+ conn.send(data, destination=destination, persistent='false')
+
+conn.send("SHUTDOWN", destination=destination, persistent='false')
+
+conn.disconnect()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/python/stomppy/readme.md
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/python/stomppy/readme.md b/assembly/src/release/examples/stomp/python/stomppy/readme.md
new file mode 100644
index 0000000..1819d35
--- /dev/null
+++ b/assembly/src/release/examples/stomp/python/stomppy/readme.md
@@ -0,0 +1,10 @@
+Prereqs
+=======
+
+Install the [stomppy](http://code.google.com/p/stomppy) python client
+library.
+
+easy_install users can install it by running:
+
+ easy_install http://stomppy.googlecode.com/files/stomp.py-3.0.2a.tar.gz
+
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/ruby/catstomp.rb
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/ruby/catstomp.rb b/assembly/src/release/examples/stomp/ruby/catstomp.rb
new file mode 100755
index 0000000..e39af47
--- /dev/null
+++ b/assembly/src/release/examples/stomp/ruby/catstomp.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env 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'
+
+user = ENV["ACTIVEMQ_USER"] || "admin"
+password = ENV["ACTIVEMQ_PASSWORD"] || "password"
+host = ENV["ACTIVEMQ_HOST"] || "localhost"
+port = ENV["ACTIVEMQ_PORT"] || 61613
+destination = $*[0] || "/topic/event"
+
+begin
+
+ $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
+
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/ruby/listener.rb
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/ruby/listener.rb b/assembly/src/release/examples/stomp/ruby/listener.rb
new file mode 100755
index 0000000..b3db3cb
--- /dev/null
+++ b/assembly/src/release/examples/stomp/ruby/listener.rb
@@ -0,0 +1,54 @@
+#!/usr/bin/env 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'
+
+user = ENV["ACTIVEMQ_USER"] || "admin"
+password = ENV["ACTIVEMQ_PASSWORD"] || "password"
+host = ENV["ACTIVEMQ_HOST"] || "localhost"
+port = ENV["ACTIVEMQ_PORT"] || 61613
+destination = $*[0] || "/topic/event"
+
+conn = Stomp::Connection.open user, password, host, port, false
+count = 0
+
+conn.subscribe destination, { :ack =>"auto" }
+start = Time.now
+$stdout.print "Waiting for messages...\n"
+while true
+ 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
+
+ else
+ start = Time.now if count==0
+ 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
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/ruby/publisher.rb
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/ruby/publisher.rb b/assembly/src/release/examples/stomp/ruby/publisher.rb
new file mode 100755
index 0000000..be7c0da
--- /dev/null
+++ b/assembly/src/release/examples/stomp/ruby/publisher.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/env 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'
+
+messages = 10000
+size = 256
+
+user = ENV["ACTIVEMQ_USER"] || "admin"
+password = ENV["ACTIVEMQ_PASSWORD"] || "password"
+host = ENV["ACTIVEMQ_HOST"] || "localhost"
+port = ENV["ACTIVEMQ_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
+
+for i in 1..messages
+ conn.publish destination, body, {'persistent'=>'false'}
+ $stdout.print "Sent #{i} messages\n" if i%1000==0
+end
+
+conn.publish destination, "SHUTDOWN", {'persistent'=>'false'}
+conn.disconnect
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/ruby/readme.md
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/ruby/readme.md b/assembly/src/release/examples/stomp/ruby/readme.md
new file mode 100644
index 0000000..cf8efbf
--- /dev/null
+++ b/assembly/src/release/examples/stomp/ruby/readme.md
@@ -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.
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/stomp/ruby/stompcat.rb
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/stomp/ruby/stompcat.rb b/assembly/src/release/examples/stomp/ruby/stompcat.rb
new file mode 100755
index 0000000..20e2667
--- /dev/null
+++ b/assembly/src/release/examples/stomp/ruby/stompcat.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/env 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'
+
+user = ENV["ACTIVEMQ_USER"] || "admin"
+password = ENV["ACTIVEMQ_PASSWORD"] || "password"
+host = ENV["ACTIVEMQ_HOST"] || "localhost"
+port = ENV["ACTIVEMQ_PORT"] || 61613
+destination = $*[0] || "/topic/event"
+
+begin
+
+ $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
+