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()
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()
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)
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)
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
class JmsTopicListener( threading.Thread ): 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 def run ( self ): self.conn.start() time.sleep(self.sleep) self.conn.close() def getReceivedTotal(self): return receivedTotal def getReceivedTopics(self): return receivedTopics def getReceivedMessages(self): return receivedMessages
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()
def setUp(self): self.url = "tcp://localhost:61616?wireFormat=openwire" from pyactivemq import ActiveMQConnectionFactory f = ActiveMQConnectionFactory(self.url) self.conn = f.createConnection()
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
def setUp(self): self.url = 'tcp://localhost:61616?wireFormat=openwire' from pyactivemq import ActiveMQConnectionFactory f = ActiveMQConnectionFactory(self.url) self.conn = f.createConnection()
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): oldPrice = price
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): oldPrice = price
# 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()
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
# 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") consumer = perftest.PerfConsumerSync(factory, destination) consumer.start() for i in range(1, 50): time.sleep(10) print "consumer received ", consumer.rate.printRate() consumer.stop() consumer.shutdown() sys.exit()