示例#1
0
def main():
    brokerUrl = 'tcp://localhost:61616?wireFormat=openwire'

    message_size = 256

    if (len(sys.argv) == 2):
        message_size = int(sys.argv[1])

    print 'connecting to: ', brokerUrl

    factory = ActiveMQConnectionFactory(brokerUrl)
    conn = factory.createConnection()
    session = conn.createSession()
    destination = session.createQueue("perftest")

    producer = perftest.PerfProducer(factory, destination, message_size)
    producer.start()

    for i in range(1, 50):
        time.sleep(10)
        print "producer sent ", producer.rate.printRate()

    producer.stop()
    producer.shutdown()

    sys.exit()
示例#2
0
    def __init__(self, brokerUrl, username, password, topics, sleep):
        threading.Thread.__init__(self)
        self.sleep = sleep
        global receivedTotal
        global receivedMessages
        global receivedTopics
        self.receivedTotal = 0
        self.receivedMessages = []
        self.receivedTopics = []
        self.f = ActiveMQConnectionFactory(brokerUrl)
        self.f.username = username;
        self.f.password = password;
        self.conn = self.f.createConnection()
        self.session = self.conn.createSession()

        # JMS filter
        messageSelector = ""
        # messageSelector = "destination = 'myDestination'"

        # create a consumer for each topic
        self.tops = []
        self.consumers = []
        self.listeners = []

        i = 0
        for name in topics:
            self.tops.append(self.session.createTopic(name))
            self.consumers.append(self.session.createConsumer(self.tops[i], \
                messageSelector))
            self.listeners.append(MessageListener(self.tops[i]))
            self.consumers[i].messageListener = self.listeners[i]
            i += 1
示例#3
0
def main():
	brokerUrl = 'tcp://localhost:61616?wireFormat=openwire'

	message_size = 256

	if(len(sys.argv) == 2):
	    message_size = int(sys.argv[1])

	print 'connecting to: ', brokerUrl 

	factory = ActiveMQConnectionFactory(brokerUrl)
	conn = factory.createConnection()
	session = conn.createSession()
	destination = session.createQueue("perftest")



	producer = perftest.PerfProducer(factory, destination, message_size)
	producer.start()

	for i in range(1, 50):
	    time.sleep(10)
	    print "producer sent ", producer.rate.printRate()

	producer.stop()
	producer.shutdown()


	sys.exit()
示例#4
0
 def test_error(self):
     from pyactivemq import ActiveMQConnectionFactory
     f = ActiveMQConnectionFactory()
     # set broker URL with an invalid port
     f.brokerURI = 'tcp://localhost:70000'
     try:
         conn = f.createConnection()
     except Exception:
         exctype, value = sys.exc_info()[:2]
         self.assert_(exctype is pyactivemq.CMSException)
示例#5
0
 def test_error(self):
     from pyactivemq import ActiveMQConnectionFactory
     f = ActiveMQConnectionFactory()
     # set broker URL with an invalid port
     f.brokerURL = 'tcp://localhost:70000'
     try:
         conn = f.createConnection()
     except Exception:
         exctype, value = sys.exc_info()[:2]
         self.assert_(exctype is pyactivemq.CMSException)
示例#6
0
def test_ExceptionListener():
    url = 'tcp://localhost:61613?wireFormat=stomp'
    from pyactivemq import ActiveMQConnectionFactory
    f = ActiveMQConnectionFactory(url)
    class ExceptionListener(pyactivemq.ExceptionListener):
        def onException(self, ex):
            self.ex = ex
    conn = f.createConnection()
    conn.exceptionListener = ExceptionListener()
    print 'Sleeping. Kill the broker now...'
    time.sleep(20)
    print conn.exceptionListener.ex
    del conn
示例#7
0
def test_ExceptionListener():
    url = 'tcp://localhost:61613?wireFormat=stomp'
    from pyactivemq import ActiveMQConnectionFactory
    f = ActiveMQConnectionFactory(url)

    class ExceptionListener(pyactivemq.ExceptionListener):
        def onException(self, ex):
            self.ex = ex

    conn = f.createConnection()
    conn.exceptionListener = ExceptionListener()
    print 'Sleeping. Kill the broker now...'
    time.sleep(20)
    print conn.exceptionListener.ex
    del conn
示例#8
0
    def __init__(self, url, send_topic_name, message, receive_topic_name):

        f = ActiveMQConnectionFactory(url)
        self.conn = f.createConnection()
        self.send_topic_name = send_topic_name
        self.receive_topic_name = receive_topic_name
        self.message = message

        nmessages = 1
        nconsumers = 1

        self.consumers = []

        self._create_single_producer()

        # create infinite queue that is shared by consumers
        self.queue = Queue.Queue(0)

        self._create_single_consumer()
示例#9
0
    def __init__(self, url, send_topic_name, message, receive_topic_name):

        f = ActiveMQConnectionFactory(url)
        self.conn = f.createConnection()
        self.send_topic_name = send_topic_name
        self.receive_topic_name = receive_topic_name
        self.message = message

        nmessages = 1
        nconsumers = 1

        self.consumers = []

        self._create_single_producer()

        # create infinite queue that is shared by consumers
        self.queue = Queue.Queue(0)

        self._create_single_consumer()
示例#10
0
 def test_properties(self):
     from pyactivemq import ActiveMQConnectionFactory
     f1 = ActiveMQConnectionFactory()
     # default broker URL enables failover
     self.assertEqual('failover:(tcp://localhost:61616)', f1.brokerURI)
     self.assertEqual('', f1.username)
     self.assertEqual('', f1.password)
     f2 = ActiveMQConnectionFactory('url')
     self.assertEqual('url', f2.brokerURI)
     f3 = ActiveMQConnectionFactory('url', 'user')
     self.assertEqual('url', f3.brokerURI)
     self.assertEqual('user', f3.username)
     f4 = ActiveMQConnectionFactory('url', 'user', 'password')
     self.assertEqual('url', f4.brokerURI)
     self.assertEqual('user', f4.username)
     self.assertEqual('password', f4.password)
     f4.brokerURI = 'url2'
     f4.username = '******'
     f4.password = '******'
     self.assertEqual('url2', f4.brokerURI)
     self.assertEqual('user2', f4.username)
     self.assertEqual('password2', f4.password)
示例#11
0
 def test_properties(self):
     from pyactivemq import ActiveMQConnectionFactory
     f1 = ActiveMQConnectionFactory()
     # default broker URL enables failover
     self.assertEqual('failover:(tcp://localhost:61616)', f1.brokerURL)
     self.assertEqual('', f1.username)
     self.assertEqual('', f1.password)
     f2 = ActiveMQConnectionFactory('url')
     self.assertEqual('url', f2.brokerURL)
     f3 = ActiveMQConnectionFactory('url', 'user')
     self.assertEqual('url', f3.brokerURL)
     self.assertEqual('user', f3.username)
     f4 = ActiveMQConnectionFactory('url', 'user', 'password')
     self.assertEqual('url', f4.brokerURL)
     self.assertEqual('user', f4.username)
     self.assertEqual('password', f4.password)
     f4.brokerURL = 'url2'
     f4.username = '******'
     f4.password = '******'
     self.assertEqual('url2', f4.brokerURL)
     self.assertEqual('user2', f4.username)
     self.assertEqual('password2', f4.password)
示例#12
0
 def setUp(self):
     self.url = 'tcp://localhost:61616?wireFormat=openwire'
     from pyactivemq import ActiveMQConnectionFactory
     f = ActiveMQConnectionFactory(self.url)
     self.conn = f.createConnection()
示例#13
0
class MessageListener(pyactivemq.MessageListener):

    def onMessage(self, message):
        printXml(message.text)

nmessages = 100

brokerUrl = 'tcp://localhost:61616?wireFormat=openwire'

if(len(sys.argv) == 2 and sys.argv[1] == 'stomp'):
    brokerUrl = 'tcp://localhost:61613?wireFormat=stomp'

print 'connecting to: ', brokerUrl 

f = ActiveMQConnectionFactory(brokerUrl)
conn = f.createConnection()

session = conn.createSession()
topic = session.createQueue('stocks')
producer = session.createProducer(topic)

consumer = session.createConsumer(topic)
consumer.messageListener = MessageListener()

conn.start()

textMessage = session.createTextMessage()
price = random.uniform(1, 100)

for i in xrange(nmessages):
示例#14
0
class MessageListener(pyactivemq.MessageListener):
    def onMessage(self, message):
        printXml(message.text)


nmessages = 100

brokerUrl = 'tcp://localhost:61616?wireFormat=openwire'

if (len(sys.argv) == 2 and sys.argv[1] == 'stomp'):
    brokerUrl = 'tcp://localhost:61613?wireFormat=stomp'

print 'connecting to: ', brokerUrl

f = ActiveMQConnectionFactory(brokerUrl)
conn = f.createConnection()

session = conn.createSession()
topic = session.createQueue('stocks')
producer = session.createProducer(topic)

consumer = session.createConsumer(topic)
consumer.messageListener = MessageListener()

conn.start()

textMessage = session.createTextMessage()
price = random.uniform(1, 100)

for i in xrange(nmessages):
示例#15
0
# 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 perftest, time, sys
from pyactivemq import ActiveMQConnectionFactory

brokerUrl = 'tcp://localhost:61616?wireFormat=openwire'

if(len(sys.argv) == 2 and sys.argv[1] == 'stomp'):
    brokerUrl = 'tcp://localhost:61613?wireFormat=stomp'

print 'connecting to: ', brokerUrl 

factory = ActiveMQConnectionFactory(brokerUrl)
conn = factory.createConnection()
session = conn.createSession()
destination = session.createQueue("perftest")



producer = perftest.ScaleProducer(factory)
producer.start()

for i in range(1, 100):
    time.sleep(10)
    print "producer created ", producer.rate.count, " queues"

producer.stop()
producer.shutdown()
示例#16
0
# 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 pyactivemq import AcknowledgeMode
from pyactivemq import DeliveryMode
from numpy.testing import assert_array_equal
import numpy as N

npickles = 1000

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

f = ActiveMQConnectionFactory('tcp://localhost:61616?wireFormat=openwire')
conn = f.createConnection()
session = conn.createSession(AcknowledgeMode.DUPS_OK_ACKNOWLEDGE)
queue = session.createQueue('arrays')
consumer = session.createConsumer(queue)
producer = session.createProducer(queue)
producer.deliveryMode = DeliveryMode.NON_PERSISTENT
conn.start()


def test():
    for i in range(npickles):
        m = session.createBytesMessage()
        # pickle array into BytesMessage's body
        m.bodyBytes = x.dumps()
        producer.send(m)
示例#17
0
import pyactivemq
'''
Please install activemq into your python before using this script
'''

from pyactivemq import ActiveMQConnectionFactory
from pyactivemq import AcknowledgeMode

connectionFactory = ActiveMQConnectionFactory(
    'tcp://ws097.diamond.ac.uk:61616')
connection = connectionFactory.createConnection()
session = connection.createSession(AcknowledgeMode.AUTO_ACKNOWLEDGE)
queue = session.createQueue("testQ")

consumer = session.createConsumer(queue)
connection.start()

print("Python consumer listening")
while (True):  # Yes I know, you have to kill it, it is a test
    m = consumer.receive(1000)
    if (m is None):
        continue

    if (isinstance(m, pyactivemq.TextMessage)):
        print(m.text)

    # We cannot deal with Java objects being sent over in the python - well durh!
    # The message from the tesst producer is still reveived but we have to parse it.
    # Instead maybe JSON strings.
    else:
        print(m)  # ObjectMessage
import pyactivemq

'''
Please install activemq into your python before using this script
'''

from pyactivemq import ActiveMQConnectionFactory
from pyactivemq import AcknowledgeMode

connectionFactory = ActiveMQConnectionFactory('tcp://ws097.diamond.ac.uk:61616')
connection = connectionFactory.createConnection()
session = connection.createSession(AcknowledgeMode.AUTO_ACKNOWLEDGE)
queue = session.createQueue("testQ");

consumer = session.createConsumer(queue);
connection.start();

print ("Python consumer listening")
while (True): # Yes I know, you have to kill it, it is a test
    m = consumer.receive(1000);
    if (m is None):
        continue;
    
    if (isinstance(m, pyactivemq.TextMessage)):
        print (m.text)
 
    # We cannot deal with Java objects being sent over in the python - well durh!
    # The message from the tesst producer is still reveived but we have to parse it.
    # Instead maybe JSON strings.
    else:
        print(m) # ObjectMessage
示例#19
0
    def setUp(self):
        self.url = "tcp://localhost:61616?wireFormat=openwire"
        from pyactivemq import ActiveMQConnectionFactory

        f = ActiveMQConnectionFactory(self.url)
        self.conn = f.createConnection()
示例#20
0
# 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 pyactivemq import AcknowledgeMode
from pyactivemq import DeliveryMode
from numpy.testing import assert_array_equal
import numpy as N

npickles = 1000

# 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(AcknowledgeMode.DUPS_OK_ACKNOWLEDGE)
queue = session.createQueue('arrays')
consumer = session.createConsumer(queue)
producer = session.createProducer(queue)
producer.deliveryMode = DeliveryMode.NON_PERSISTENT
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)