#!/usr/bin/env python

# Copyright 2007 Albert Strasheim <fullung@gmail.com>
#
# Licensed 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.

from pyactivemq import ActiveMQConnectionFactory
from numpy.testing import assert_array_equal
import numpy as N

npickles = 50

# generate random array containing 100*100 doubles
x = N.random.randn(100, 100)

f = ActiveMQConnectionFactory('tcp://localhost:61613?wireFormat=stomp')
conn = f.createConnection()
session = conn.createSession()
queue = session.createQueue('arrays')
consumer = session.createConsumer(queue)
producer = session.createProducer(queue)
conn.start()

def test():
    for i in xrange(npickles):
        m = session.createBytesMessage()
        # pickle array into BytesMessage's body
        m.bodyBytes = x.dumps()
        producer.send(m)
        m2 = consumer.receive(1000)
        assert m2 is not None
        # unpickle array from BytesMessage's body
        y = N.loads(m2.bodyBytes)
        assert_array_equal(x, y)

from timeit import Timer
t = Timer('test()', 'from __main__ import test')
delta = t.timeit(1)

conn.close()

print 'pickled %d arrays, each %d bytes, in %f seconds' % \
    (npickles, x.nbytes, delta)

@@ -666,16 +666,91 @@
 Factory%0A
+from pyactivemq import AcknowledgeMode%0Afrom pyactivemq import DeliveryMode%0A
 from num
@@ -786,16 +786,16 @@
 y_equal%0A
-
 import n
@@ -820,9 +820,11 @@
 s = 
-5
+100
 0%0A%0A#
@@ -1032,16 +1032,51 @@
 Session(
+AcknowledgeMode.DUPS_OK_ACKNOWLEDGE
 )%0Aqueue 
@@ -1148,16 +1148,16 @@
 (queue)%0A
-
 producer
@@ -1189,16 +1189,68 @@
 (queue)%0A
+producer.deliveryMode = DeliveryMode.NON_PERSISTENT%0A
 conn.sta

Make example run faster by changing acknowledge and delivery modes.