使用Jmeter測試JMS
前言:使用Jmeter測試ActiveMQ的JMS消息,網(wǎng)上有一篇,但是圖片看不了,具體參數(shù)填什么也不清楚,因此決定總結(jié)這篇
所使用的Jmeter版本2.8,activemq版本5.6
一、創(chuàng)建jndi.properties文件
由于 jmeter 是通過 jndi 來獲得 jms 中相關(guān)對象的,如 ConnectionFactory 和 Destination,所以在 jmeter 的 classpath 中需要添加一個(gè) jndi.properties 屬性文件,用于配置jndi
創(chuàng)建jndi.properties文件,包含如下內(nèi)容
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory #注冊queue,格式: #注冊topic,格式: |
保存并把這個(gè)文件復(fù)制到 JMETER_HOME/bin(JMETER_HOME為 jmeter 的安裝目錄)目錄中。
二、把jndi.properties放到j(luò)meter的啟動(dòng)jar包中
由于bin目錄并不在jmeter的classpath中,所以需要執(zhí)行一些額外的工作來把jndi.properties添加到j(luò)meter的classpath中,把jndi.properties打包到j(luò)meter的啟動(dòng)jar包中。jmeter的啟動(dòng)jar包為JMETER_HOME/bin/ApacheJMeter.jar,所以需要把jndi.properties 打包到這個(gè) jar 文件中。直接將文件拖入jar包中即可。
或者執(zhí)行如下操作,打開命令行窗口,并定位到 JMETER_HOME/bin 目錄,運(yùn)行如下命令 jar uf ApacheJMeter.jar jndi.properties
三、添加activemq-all-5.2.0.jar包到Jmeter的lib庫
將ACTIVE_HOME/activemq-all-5.2.0.jar文件復(fù)制到JMETER_HOME/lib目錄中,jmeter在測試jms的時(shí)候會使用到activemq提供的jms的實(shí)現(xiàn)類,這些類并沒有隨jmeter一起分發(fā),需要把這些類添加到j(luò)meter的classpath中。
四、啟動(dòng)Jmeter測試JMS
添加線程組及JMS的sampler,有三種方式的JMS消息
1、Point-to-Point
填寫參數(shù)如下:
QueueConnection Factory:connectionFactory |
2、Publisher
基本值同Point-to-Point,不同點(diǎn)在于Destination,填寫JMS的topic目的地
若在ActiveMQ中Topics的名字為example.MyTopic
則jndi.properties文件中定義的topic如下:
topic.MyTopic = example.MyTopic
則Destination填寫topic.后面的MyTopic
3、Subscriber
基本值同Publisher,不同在于可以根據(jù)需要填寫Client ID,JMS Selector進(jìn)行消息過濾
報(bào)錯(cuò):Response message: javax.naming.NameNotFoundException:***
原因Destination中填寫的錯(cuò)了,以為填寫ActiveMQ中實(shí)際的Topic名
其實(shí)在jndi.properties文件中已經(jīng)實(shí)例化了,topic.MyTopic = example.MyTopic,這里example.MyTopic就是ActiveMQ中的Topic名
因此實(shí)際填寫時(shí)是填寫topic.后的MyTopic
posted on 2013-08-27 10:30 順其自然EVO 閱讀(582) 評論(0) 編輯 收藏 所屬分類: 性能測試 、web 前端性能測試