activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1423009 - in /activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp: java/src/main/java/example/Listener.java java/src/main/java/example/Publisher.java python/ python/listener.py python/publisher.py
Date Mon, 17 Dec 2012 16:26:20 GMT
Author: chirino
Date: Mon Dec 17 16:26:19 2012
New Revision: 1423009

URL: http://svn.apache.org/viewvc?rev=1423009&view=rev
Log:
Added proton python examples, also make the java ones work better /w it.

Added:
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/listener.py
  (with props)
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/publisher.py
  (with props)
Modified:
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
    activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java

Modified: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java?rev=1423009&r1=1423008&r2=1423009&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Listener.java
Mon Dec 17 16:26:19 2012
@@ -51,17 +51,18 @@ class Listener {
                 if( "SHUTDOWN".equals(body)) {
                     long diff = System.currentTimeMillis() - start;
                     System.out.println(String.format("Received %d in %.2f seconds", count,
(1.0*diff/1000.0)));
-                    break;
+                    connection.close();
+                    System.exit(1);
                 } else {
-                    if( count != msg.getIntProperty("id") ) {
-                        System.out.println("mismatch: "+count+"!="+msg.getIntProperty("id"));
+                    try {
+                        if( count != msg.getIntProperty("id") ) {
+                            System.out.println("mismatch: "+count+"!="+msg.getIntProperty("id"));
+                        }
+                    } catch (NumberFormatException ignore) {
                     }
-                    count = msg.getIntProperty("id");
-
-                    if( count == 0 ) {
+                    if( count == 1 ) {
                         start = System.currentTimeMillis();
-                    }
-                    if( count % 1000 == 0 ) {
+                    } else if( count % 1000 == 0 ) {
                         System.out.println(String.format("Received %d messages.", count));
                     }
                     count ++;
@@ -71,7 +72,6 @@ class Listener {
                 System.out.println("Unexpected message type: "+msg.getClass());
             }
         }
-        connection.close();
     }
 
     private static String env(String key, String defaultValue) {
@@ -87,4 +87,4 @@ class Listener {
         else
             return defaultValue;
     }
-}
\ No newline at end of file
+}

Modified: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java?rev=1423009&r1=1423008&r2=1423009&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/java/src/main/java/example/Publisher.java
Mon Dec 17 16:26:19 2012
@@ -21,7 +21,7 @@ import javax.jms.*;
 
 class Publisher {
 
-    public static void main(String []args) throws JMSException {
+    public static void main(String []args) throws Exception {
 
         String user = env("APOLLO_USER", "admin");
         String password = env("APOLLO_PASSWORD", "password");
@@ -53,7 +53,7 @@ class Publisher {
         producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
 
         for( int i=1; i <= messages; i ++) {
-            TextMessage msg = session.createTextMessage(body);
+            TextMessage msg = session.createTextMessage("#:"+i);
             msg.setIntProperty("id", i);
             producer.send(msg);
             if( (i % 1000) == 0) {
@@ -62,8 +62,9 @@ class Publisher {
         }
 
         producer.send(session.createTextMessage("SHUTDOWN"));
+        Thread.sleep(1000*3);
         connection.close();
-
+        System.exit(0);
     }
 
     private static String env(String key, String defaultValue) {
@@ -80,4 +81,4 @@ class Publisher {
             return defaultValue;
     }
 
-}
\ No newline at end of file
+}

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/listener.py
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/listener.py?rev=1423009&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/listener.py
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/listener.py
Mon Dec 17 16:26:19 2012
@@ -0,0 +1,54 @@
+#!/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 proton import *
+
+user = os.getenv('APOLLO_USER') or 'admin'
+password = os.getenv('APOLLO_PASSWORD') or 'password'
+host = os.getenv('APOLLO_HOST') or '127.0.0.1'
+port = int(os.getenv('APOLLO_PORT') or 61613)
+destination = sys.argv[1:2] or ['topic://event']
+destination = destination[0]
+
+msg = Message()
+mng = Messenger()
+mng.password=password
+mng.start()
+mng.subscribe("amqp://%s@%s:%d/%s"%(user, host, port, destination))
+
+count = 0
+start = time.time()
+while True:
+  mng.recv(10)
+  while mng.incoming:
+    mng.get(msg)
+    if msg.body=="SHUTDOWN":
+      diff = time.time() - start
+      print 'Received %d frames in %f seconds' % (count, diff)
+      exit(0)
+    else:
+      if count==0:
+        start = time.time()
+      count+=1
+      if count % 1000 == 0:
+        print 'Received %d messages.' % (count)
+
+mng.stop()

Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/listener.py
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/publisher.py
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/publisher.py?rev=1423009&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/publisher.py
(added)
+++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/publisher.py
Mon Dec 17 16:26:19 2012
@@ -0,0 +1,57 @@
+#!/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 proton import *
+
+user = os.getenv('APOLLO_USER') or 'admin'
+password = os.getenv('APOLLO_PASSWORD') or 'password'
+host = os.getenv('APOLLO_HOST') or '127.0.0.1'
+port = int(os.getenv('APOLLO_PORT') or 61613)
+destination = sys.argv[1:2] or ['topic://event']
+destination = destination[0]
+address = "amqp://%s@%s:%d/%s"%(user, host, port, destination)
+
+msg = Message()
+mng = Messenger()
+mng.password=password
+mng.start()
+
+messages = 10000
+
+msg.address = address
+msg.body = unicode('Hello World from Python')
+
+count = 0
+start = time.time()
+for _ in xrange(messages):
+  mng.put(msg)
+  count += 1
+  if count % 1000 == 0 :
+    print("Sent %d messages"%(count))
+
+msg.body = unicode("SHUTDOWN")
+mng.put(msg)
+mng.send
+
+diff = time.time() - start
+print 'Sent %s frames in %f seconds' % (count, diff)
+
+mng.stop()

Propchange: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/amqp/python/publisher.py
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message